Repository navigation
fix(search): harden HNSW load/rebuild against malformed-length persisted state (#313) - #328
Merged
Merged
Conversation
Owner
Author
|
Runtime evidence snapshot (current DB shape, post-fix validation) Baseline build (
Fixed build (
This confirms #313 reliability hardening stabilizes ANN load/rebuild behavior under the current DB's mixed embedding dimensions. |
This was referenced Mar 11, 2026
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.
What this does
Implements a bounded reliability fix for #313 so malformed ANN/HNSW persisted state no longer causes repeated unstable load/rebuild loops and potential panic-adjacent behavior.
This keeps the lane strictly reliability-focused (no ranking/search-quality widening).
Problem / Context
Issue: #313
Observed on current
main+ current DB shape:warning: could not load HNSW index ... friend count: invalid value -1152003907; rebuildingRoot cause:
BuildHNSWassumed all stored embeddings share dimensions of the first vector.ann.Loadparse expectations (malformed-length style failure surface).How it works
1) Harden HNSW build path against mixed/malformed dimensions
File:
internal/search/search.goBuildHNSWnow:This prevents persisting malformed HNSW structure from mixed-dimension rows.
2) Add deterministic regression for malformed-length load case
Files:
internal/ann/hnsw_test.gointernal/search/search_test.goAdded tests:
TestLoadRejectsMalformedFriendCountWithoutPanickingTestBuildHNSW_SkipsMismatchedEmbeddingDimensionsAndPersistsValidIndexRepro/disprove evidence on current main/current DB shape
Baseline (
/tmp/cortex-313-main, 10 semantic/hybrid runs):main_warnings=10(load failure + rebuild every run)friend count: invalid value -1152003907; rebuildingFixed branch build (
/tmp/cortex-313-fix-bin, same 10 runs):load_warnings=1skip_warnings=1This demonstrates graceful recovery to stable persisted state.
Testing done
Exact commands run:
go test ./internal/ann -run 'RejectsCorruptNodeLevel|RejectsMalformedFriendCount' -count=1go test ./internal/search -run 'LoadOrBuildHNSW_RebuildsCorruptPersistedIndex|BuildHNSW_SkipsMismatchedEmbeddingDimensionsAndPersistsValidIndex' -count=1go test ./...Screenshots / before-after
Terminal before/after evidence:
Breaking changes / risks
Breaking changes: None.
Risk note:
Explicit out-of-scope
Merge notes