fix(vector): use index metric and efc for post-build HNSW inserts - #90
Merged
Merged
Conversation
OnDiskHNSWIndex::HNSWInsertState built its search state with a default-constructed HNSWIndexConfig (metric = cosine) and default QueryHNSWConfig (efs = 200), so rows inserted after CREATE_VECTOR_INDEX (CREATE/MERGE via initInsertState, COPY FROM via finalize, embedding updates via initUpdateState) picked HNSW neighbours by cosine distance regardless of the index metric, silently lowering recall on l2/l2sq/ dotproduct indexes over non-normalized vectors. Thread the index config through and map efc onto the insert search ef. Related to LadybugDB/ladybug#1023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Rows inserted into a table after
CREATE_VECTOR_INDEX(viaCREATE/MERGEthroughinitInsertState,COPY FROMthroughfinalize, and embedding updates throughinitUpdateState) had their HNSW neighbours chosen by cosine distance regardless of the index's configured metric.Root cause
OnDiskHNSWIndex::HNSWInsertStatebuilt itsHNSWSearchStatewith a default-constructedHNSWIndexConfig{}(metric = cosine) and defaultQueryHNSWConfig{}(efs= 200).insertInternal->searchNNInUpperLayer/insertToLayer->searchKNNInLayerall score candidates withsearchState.metricFunc, so post-build inserts silently used cosine (and default ef) onl2/l2sq/dotproductindexes over non-normalized vectors, lowering recall for those rows. The initial build (InMemHNSWIndex), shrink (shrinkForNodeusesconfig.metric), and query path (real index config) were already correct.Fix
HNSWInsertStatenow takesconst HNSWIndexConfig&and forwards it toHNSWSearchStateinstead ofHNSWIndexConfig{}.getInsertQueryConfig()helper maps the index'sefconto the insert search'sefs, so customefcis honored for incremental inserts too.initInsertState,finalize) pass throughconfig.Testing
E2E_TEST_FILES_DIRECTORY=extension ... e2e_test --gtest_filter='vector~*').Related to LadybugDB/ladybug#1023