diff --git a/go.mod b/go.mod index 1d8fc78..afe720a 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,3 @@ module github.com/blevesearch/go-faiss -go 1.19 +go 1.21 diff --git a/search_params.go b/search_params.go index 17575d5..bddc92f 100644 --- a/search_params.go +++ b/search_params.go @@ -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 { @@ -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))