Bulk score hnsw neighbor array#15958
Conversation
|
Hi @benwtrent , would appreciate a look when you have time. Happy to make any changes if needed. Thanks! |
|
This PR has not had activity in the past 2 weeks, labeling it as stale. If the PR is waiting for review, notify the dev@lucene.apache.org list. Thank you for your contribution! |
| return true; | ||
| } | ||
| } | ||
| return scorer.bulkScore(nodes, bulkScores, candidateIndex) >= minAcceptedSimilarity; |
There was a problem hiding this comment.
It seems like we only want to score uncheckedIndexes right?
There was a problem hiding this comment.
Hi @benwtrent , thanks for the review!
Not exactly, it depends on whether the candidate itself is checked or unchecked.
Case 1 (candidate is unchecked): brand new node, never been diversity-checked against anyone, so we score against all better neighbors (0..candidateIndex-1) not just unchecked ones.
Case 2 (candidate is checked): already survived diversity checks against all checked nodes, so we only score against the newly added unchecked nodes.
This is the same logic as before my change, I only replaced the per-node scorer.score() loop with bulkScore.
That being said, looking at it again I made two small improvements: renamed bulkScoreNodes to uncheckedNodes to make it clearer what it actually contains, and moved the population of uncheckedNodes up into findWorstNonDiverse so it's built once and reused across calls to isWorstNonDiverse rather than being recreated every time.
issue #15606
Refactor
NeighborArray#isWorstNonDiverseto usebulkScoreinstead ofscore, enabling multiple nodes to be evaluated at a time when searching for the worst neighbor to remove.This change follows the approach taken in #15607, though unlike that case, this function is called less frequently so the direct performance gains are modest and within margin of error.
The primary motivation is consistency, aligning both call sites to use
bulkScoreensures this code automatically benefits from any future optimizations made to implementations of that function.Benchmarks run using luceneutil knnPerfTest
on a ThinkPad T14 Gen 1 (Intel i5-10210U, 8 logical cores, 16GB RAM, Linux).
Dataset: Cohere v3 Wikipedia 1024d, 50K docs, dot_product metric,
maxConn=64, beamWidthIndex=250, quantizeBits=8.