fix: replenish() hardcodes CosineDistance instead of graph distance#21
Open
suykerbuyk wants to merge 2 commits into
Open
fix: replenish() hardcodes CosineDistance instead of graph distance#21suykerbuyk wants to merge 2 commits into
suykerbuyk wants to merge 2 commits into
Conversation
added 2 commits
April 11, 2026 12:26
In a binary min-heap, the last array element is not necessarily the maximum. Max() must scan the leaf nodes (indices n/2..n-1) to find the true maximum. PopLast() used Remove(Len()-1) which removed an arbitrary element instead of the worst. This caused incorrect evictions during neighbor selection and search result trimming, degrading graph quality.
…ance replenish() is called after neighbor eviction and node deletion to restore connectivity. It unconditionally used CosineDistance, ignoring the graph's configured distance function. This corrupted the graph topology for any non-Cosine metric. Thread DistanceFunc through replenish() and isolate() so the correct distance function is always used.
2 tasks
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
replenish()unconditionally calledaddNeighbor(..., CosineDistance)regardless of the graph's configured distance functionDistanceFuncthroughreplenish()andisolate()so the correct function is always usedDepends on #20.
Test plan
TestGraph_DeleteReplenishUsesGraphDistance— builds a Euclidean graph, deletes a node to trigger replenish, verifies search still returns the correct nearest neighborgo test ./...andgo vet ./...pass