Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MB-61889: Address corner case with ivf_nprobe_pct #34

Merged
merged 2 commits into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module github.com/blevesearch/go-faiss

go 1.19
go 1.21
8 changes: 5 additions & 3 deletions search_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewSearchParams(idx Index, params json.RawMessage, sel *C.FaissIDSelector,
return rv, fmt.Errorf("failed to create faiss search params")
}

// # check if the index is IVF and set the search params
// check if the index is IVF and set the search params
if ivfIdx := C.faiss_IndexIVF_cast(idx.cPtr()); ivfIdx != nil {
rv.sp = C.faiss_SearchParametersIVF_cast(rv.sp)
if len(params) == 0 {
Expand All @@ -72,9 +72,11 @@ func NewSearchParams(idx Index, params json.RawMessage, sel *C.FaissIDSelector,

if ivfParams.NprobePct > 0 {
nlist := float32(C.faiss_IndexIVF_nlist(ivfIdx))
nprobe = int(nlist * (ivfParams.NprobePct / 100))
// in the situation when the calculated nprobe happens to be
// between 0 and 1, we'll round it up.
nprobe = max(int(nlist * (ivfParams.NprobePct / 100)), 1)
} else {
// It's important to set nprobe to the value decided at the time of
// it's important to set nprobe to the value decided at the time of
// index creation. Otherwise, nprobe will be set to the default
// value of 1.
nprobe = int(C.faiss_IndexIVF_nprobe(ivfIdx))
Expand Down