Skip to content

Commit 87440cf

Browse files
MB-71516: Add unit test to reproduce result inconsistency issue (#2317)
- Add a unit test that reproduces the issue fixed by blevesearch/zapx#401 --------- Co-authored-by: Abhinav Dangeti <abhinav@couchbase.com>
1 parent 8d7b969 commit 87440cf

3 files changed

Lines changed: 68 additions & 3 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ require (
2525
github.com/blevesearch/zapx/v14 v14.4.3
2626
github.com/blevesearch/zapx/v15 v15.4.3
2727
github.com/blevesearch/zapx/v16 v16.3.4
28-
github.com/blevesearch/zapx/v17 v17.0.11
28+
github.com/blevesearch/zapx/v17 v17.0.12-0.20260421144655-b9ffe761cd37
2929
github.com/couchbase/moss v0.2.0
3030
github.com/spf13/cobra v1.10.2
3131
go.etcd.io/bbolt v1.4.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ github.com/blevesearch/zapx/v15 v15.4.3 h1:iJiMJOHrz216jyO6lS0m9RTCEkprUnzvqAI2l
4545
github.com/blevesearch/zapx/v15 v15.4.3/go.mod h1:1pssev/59FsuWcgSnTa0OeEpOzmhtmr/0/11H0Z8+Nw=
4646
github.com/blevesearch/zapx/v16 v16.3.4 h1:hDAqA8qusZTNbPEL7//w5P65UZ2de6yhSeUaTbp0Po0=
4747
github.com/blevesearch/zapx/v16 v16.3.4/go.mod h1:zqkPPqs9GS9FzVWzCO3Wf1X044yWAV17+4zb+FTiEHg=
48-
github.com/blevesearch/zapx/v17 v17.0.11 h1:3OKEe8NpD4n14GW+GY/op5nh8/x8dmYNwgLdRgvv5go=
49-
github.com/blevesearch/zapx/v17 v17.0.11/go.mod h1:62wlIX0vYZoLoLLKmix4zQvyCevvUt7RLuvcV5D3/N0=
48+
github.com/blevesearch/zapx/v17 v17.0.12-0.20260421144655-b9ffe761cd37 h1:LaROcKdceOI37F6OMc9pySbdXCAQVqOgcMQk47yosqA=
49+
github.com/blevesearch/zapx/v17 v17.0.12-0.20260421144655-b9ffe761cd37/go.mod h1:62wlIX0vYZoLoLLKmix4zQvyCevvUt7RLuvcV5D3/N0=
5050
github.com/couchbase/ghistogram v0.1.0 h1:b95QcQTCzjTUocDXp/uMgSNQi8oj1tGwnJ4bODWZnps=
5151
github.com/couchbase/ghistogram v0.1.0/go.mod h1:s1Jhy76zqfEecpNWJfWUiKZookAFaiGOEoyzgHt9i7k=
5252
github.com/couchbase/moss v0.2.0 h1:VCYrMzFwEryyhRSeI+/b3tRBSeTpi/8gn5Kf6dxqn+o=

search_knn_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,3 +2986,68 @@ func TestKNNNullParams(t *testing.T) {
29862986
}
29872987
}
29882988
}
2989+
2990+
func TestVectorIndexExhaustion(t *testing.T) {
2991+
for optimization := range index.SupportedVectorIndexOptimizations {
2992+
t.Run(optimization, func(t *testing.T) {
2993+
tmpIndexPath := createTmpIndexPath(t)
2994+
defer cleanupTmpIndexPath(t, tmpIndexPath)
2995+
2996+
const dims = 8
2997+
2998+
vecFieldMapping := mapping.NewVectorFieldMapping()
2999+
vecFieldMapping.Dims = dims
3000+
vecFieldMapping.VectorIndexOptimizedFor = optimization
3001+
3002+
indexMapping := NewIndexMapping()
3003+
indexMapping.DefaultMapping.AddFieldMappingsAt("vec", vecFieldMapping)
3004+
3005+
idx, err := New(tmpIndexPath, indexMapping)
3006+
if err != nil {
3007+
t.Fatal(err)
3008+
}
3009+
defer func() {
3010+
err := idx.Close()
3011+
if err != nil {
3012+
t.Fatal(err)
3013+
}
3014+
}()
3015+
3016+
docs := []struct {
3017+
id string
3018+
vec []float32
3019+
}{
3020+
{"doc1", []float32{1, 0, 0, 0, 0, 0, 0, 0}},
3021+
{"doc2", []float32{0, 1, 0, 0, 0, 0, 0, 0}},
3022+
{"doc3", []float32{0, 0, 1, 0, 0, 0, 0, 0}},
3023+
}
3024+
3025+
batch := idx.NewBatch()
3026+
for _, doc := range docs {
3027+
err = batch.Index(doc.id, map[string]interface{}{
3028+
"vec": doc.vec,
3029+
})
3030+
if err != nil {
3031+
t.Fatal(err)
3032+
}
3033+
}
3034+
err = idx.Batch(batch)
3035+
if err != nil {
3036+
t.Fatal(err)
3037+
}
3038+
3039+
searchReq := NewSearchRequest(query.NewMatchNoneQuery())
3040+
searchReq.AddKNN("vec", []float32{1, 0, 0, 0, 0, 0, 0, 0}, 10, 1.0)
3041+
res, err := idx.Search(searchReq)
3042+
if err != nil {
3043+
t.Fatal(err)
3044+
}
3045+
if len(res.Hits) != 3 {
3046+
t.Fatalf("expected 3 hits, got %d", len(res.Hits))
3047+
}
3048+
if res.Hits[0].ID != "doc1" {
3049+
t.Fatalf("expected doc1 as top hit, got %s", res.Hits[0].ID)
3050+
}
3051+
})
3052+
}
3053+
}

0 commit comments

Comments
 (0)