Skip to content

Commit 1a448f1

Browse files
Use TernaryLongHeap in NeighborQueue for better HNSW performance (#15163)
1 parent 00f2b01 commit 1a448f1

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lucene/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ Optimizations
129129
---------------------
130130
* GITHUB#15140: Optimize TopScoreDocCollector with TernaryLongHeap for improved performance over Binary-LongHeap. (Ramakrishna Chilaka)
131131

132+
* GITHUB#15163: Use TernaryLongHeap in NeighborQueue for faster vector search performance. (Ramakrishna Chilaka)
133+
132134
* GITHUB#14998: Speed up flushing of live docs. (Adrien Grand)
133135

134136
* GITHUB#15165: Optimize PForUtil.encode() with histogram-based bit selection. (Ramakrishna Chilaka)

lucene/core/src/java/org/apache/lucene/util/hnsw/NeighborQueue.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717

1818
package org.apache.lucene.util.hnsw;
1919

20-
import org.apache.lucene.util.LongHeap;
2120
import org.apache.lucene.util.NumericUtils;
21+
import org.apache.lucene.util.TernaryLongHeap;
2222

2323
/**
24-
* NeighborQueue uses a {@link LongHeap} to store lists of arcs in an HNSW graph, represented as a
25-
* neighbor node id with an associated score packed together as a sortable long, which is sorted
26-
* primarily by score. The queue provides both fixed-size and unbounded operations via {@link
24+
* NeighborQueue uses a {@link TernaryLongHeap} to store lists of arcs in an HNSW graph, represented
25+
* as a neighbor node id with an associated score packed together as a sortable long, which is
26+
* sorted primarily by score. The queue provides both fixed-size and unbounded operations via {@link
2727
* #insertWithOverflow(int, float)} and {@link #add(int, float)}, and provides MIN and MAX heap
2828
* subclasses.
2929
*/
@@ -48,7 +48,7 @@ long apply(long v) {
4848
abstract long apply(long v);
4949
}
5050

51-
private final LongHeap heap;
51+
private final TernaryLongHeap heap;
5252
private final Order order;
5353

5454
// Used to track the number of neighbors visited during a single graph traversal
@@ -57,7 +57,7 @@ long apply(long v) {
5757
private boolean incomplete;
5858

5959
public NeighborQueue(int initialSize, boolean maxHeap) {
60-
this.heap = new LongHeap(initialSize);
60+
this.heap = new TernaryLongHeap(initialSize);
6161
this.order = maxHeap ? Order.MAX_HEAP : Order.MIN_HEAP;
6262
}
6363

0 commit comments

Comments
 (0)