Skip to content

fix: replenish() hardcodes CosineDistance instead of graph distance#21

Open
suykerbuyk wants to merge 2 commits into
coder:mainfrom
suykerbuyk:fix/replenish-distance
Open

fix: replenish() hardcodes CosineDistance instead of graph distance#21
suykerbuyk wants to merge 2 commits into
coder:mainfrom
suykerbuyk:fix/replenish-distance

Conversation

@suykerbuyk
Copy link
Copy Markdown
Contributor

Summary

  • replenish() unconditionally called addNeighbor(..., CosineDistance) regardless of the graph's configured distance function
  • This corrupted graph topology for Euclidean or custom metrics
  • Fix: thread DistanceFunc through replenish() and isolate() so the correct function is always used

Depends on #20.

Test plan

  • Added TestGraph_DeleteReplenishUsesGraphDistance — builds a Euclidean graph, deletes a node to trigger replenish, verifies search still returns the correct nearest neighbor
  • go test ./... and go vet ./... pass

John Suykerbuyk 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant