-
Notifications
You must be signed in to change notification settings - Fork 59
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
Added hnsw.ef_search variable to change expansion factor during search at runtime #199
Added hnsw.ef_search variable to change expansion factor during search at runtime #199
Conversation
When you add tests for this, make sure you add tests in for pgvector compatibility test file as well. |
…h_ef to avoid conflicting with pgvector's custom variable name, which was breaking
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! could you add tests?
src/hnsw/options.c
Outdated
"Expansion factor to use during vector search in a scan", | ||
"Valid values are in range [1, 400]", | ||
&ldb_hnsw_ef_search, | ||
// HNSW_DEFAULT_EF, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this supposed to be commented out?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will remove, doesn't impact functionality at all
src/hnsw/scan.c
Outdated
@@ -193,8 +195,14 @@ bool ldb_amgettuple(IndexScanDesc scan, ScanDirection dir) | |||
} | |||
|
|||
ldb_dlog("LANTERN querying index for %d elements", k); | |||
num_returned = usearch_search( | |||
scanstate->usearch_index, vec, usearch_scalar_f32_k, k, scanstate->labels, scanstate->distances, &error); | |||
num_returned = usearch_search_custom_ef(scanstate->usearch_index, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be better to just add ef
as optional parameter to usearch_search
and if ef != 0
, use the passed ef
, otherwise use the ef
from usearch header
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do this but C doesn't support optional parameters in functions. We can make usearch_search
a variadic function but that seems like overkill.
The "ef != 0
then use passed ef
, otherwise use ef
from usearch header" logic you mention is already added in the usearch library. So passing the ef
from here, regardless of what it is, will lead to this desired functionality
Maybe just rename usearch_search_custom_ef
to usearch_search
? Or just to make it more readable, check in this code if ef != 0
then use usearch_search_custom_ef
and if not, use the original usearch_search
?
Notes:
|
… a test hnsw_ef_search
I renamed it. Note that the other CustomIntVariable we have,
I implemented this as well. This was actually how it was working already but I refactored the usearch changes so that this logic is clearly reflected in the C api of
I added a test |
Looks great! just merged your usearch pr (Ngalstyan4/usearch#19). Will merge this as soon as you rebase the submodule onto that one |
fixes #171
Created a new custom variable
hnsw.search_ef
(used to behnsw.ef_search
, but that conflicted with pgvector's) that can be set at runtime to update the expansion factor during search. Currently, if this variable is not set, it will use theef
factor specified in the index relation option. However, as soon as this variable is set, it takes precedence over this factor and is used in all searches.Relies on this PR for usearch which creates a new function
usearch_search_custom_ef
that takes a custom expansion factor.