Skip to content

perf(hnsw): deduplicate neighbor updates and fix error handling#9664

Open
shaunpatterson wants to merge 2 commits intodgraph-io:mainfrom
shaunpatterson:sp/dedup-neighbor-updates
Open

perf(hnsw): deduplicate neighbor updates and fix error handling#9664
shaunpatterson wants to merge 2 commits intodgraph-io:mainfrom
shaunpatterson:sp/dedup-neighbor-updates

Conversation

@shaunpatterson
Copy link

Summary

  • Deduplicate addNeighbors calls: Replace nnUidArray (which accumulated duplicate UIDs when the same neighbor appeared across multiple HNSW layers) with direct iteration over inboundEdgesAllLayersMap keys, ensuring each neighbor is processed exactly once
  • Fix error handling for addNeighbors(inUuid, ...): The error was previously checked after the neighbor loop instead of immediately, allowing unnecessary work on failure
  • Fix silent error swallowing: searchPersistentLayer errors were returned as layerErr (always nil) instead of err, masking real failures

Test plan

  • Verify existing HNSW vector index tests pass (go test ./tok/hnsw/...)
  • Confirm addNeighbors is called once per unique neighbor UID (no redundant writes)
  • Validate error propagation from searchPersistentLayer is no longer swallowed

🤖 Generated with Claude Code

…sertHelper

Deduplicate addNeighbors calls by iterating over inboundEdgesAllLayersMap keys
instead of nnUidArray, which could contain duplicate UIDs when the same neighbor
appears across multiple layers. Also fix two bugs: (1) err from addNeighbors for
the inserted node was checked after the neighbor loop instead of immediately,
and (2) searchPersistentLayer errors were silently swallowed by returning the
uninitialized layerErr variable instead of err.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@shaunpatterson shaunpatterson requested a review from a team as a code owner March 20, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant