Skip to content

Commit

Permalink
remove inverted file index for neighbors (#929)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhenghaoz authored Jan 20, 2025
1 parent 6eb9bc7 commit 010865b
Show file tree
Hide file tree
Showing 10 changed files with 293 additions and 1,015 deletions.
13 changes: 4 additions & 9 deletions base/search/hnsw.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ import (
"modernc.org/mathutil"
)

const (
DefaultTestSize = 1000
)

var _ VectorIndex = &HNSW{}

// HNSW is a vector index based on Hierarchical Navigable Small Worlds.
Expand Down Expand Up @@ -468,12 +472,3 @@ func (h *HNSW) efSearchValue(n int) int {
}
return mathutil.Max(h.efConstruction, n)
}

func EstimateHNSWBuilderComplexity(dataSize, trials int) int {
// build index
complexity := dataSize * dataSize
// evaluate
complexity += DefaultTestSize * dataSize
// with trials
return complexity * trials
}
25 changes: 0 additions & 25 deletions base/search/index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,3 @@ func TestHNSW_InnerProduct(t *testing.T) {
recall = builder.evaluateTermSearch(idx, true, "prime")
assert.Greater(t, recall, float32(0.8))
}

func TestIVF_Cosine(t *testing.T) {
// load dataset
trainSet, _, err := ranking.LoadDataFromBuiltIn("ml-100k")
assert.NoError(t, err)
values := make([]float32, trainSet.UserCount())
for i := range values {
values[i] = 1
}
var vectors []Vector
for i, feedback := range trainSet.ItemFeedback {
var terms []string
if big.NewInt(int64(i)).ProbablyPrime(0) {
terms = append(terms, "prime")
}
vectors = append(vectors, NewDictionaryVector(feedback, values, terms, false))
}

// build vector index
builder := NewIVFBuilder(vectors, 10)
idx, recall := builder.Build(0.9, 5, true)
assert.Greater(t, recall, float32(0.9))
recall = builder.evaluateTermSearch(idx, true, "prime")
assert.Greater(t, recall, float32(0.8))
}
339 changes: 0 additions & 339 deletions base/search/ivf.go

This file was deleted.

Loading

0 comments on commit 010865b

Please sign in to comment.