Skip to content

Commit c6dbf7e

Browse files
committed
make hnsw collector a decorator
1 parent 1dbaa1a commit c6dbf7e

File tree

2 files changed

+10
-24
lines changed

2 files changed

+10
-24
lines changed

lucene/core/src/java/org/apache/lucene/search/HnswKnnCollector.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@
1717
package org.apache.lucene.search;
1818

1919
/** {@link KnnCollector} that exposes methods to hook into specific parts of the HNSW algorithm. */
20-
public interface HnswKnnCollector extends KnnCollector {
20+
public abstract class HnswKnnCollector extends KnnCollector.Decorator {
21+
22+
public HnswKnnCollector(KnnCollector collector) {
23+
super(collector);
24+
}
2125

2226
/** Indicates exploration of the next HNSW candidate graph node. */
23-
void nextCandidate();
27+
public abstract void nextCandidate();
2428
}

lucene/core/src/java/org/apache/lucene/search/HnswQueueSaturationCollector.java

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
* delegate} KnnCollector queue, at each HNSW node candidate visit. Once it saturates for a number
2424
* of consecutive node visits (e.g., the patience parameter), this early terminates.
2525
*/
26-
public class HnswQueueSaturationCollector implements HnswKnnCollector {
26+
public class HnswQueueSaturationCollector extends HnswKnnCollector {
2727

28-
private static final double DEFAULT_SATURATION_THRESHOLD = 0.995d;
28+
private static final double DEFAULT_SATURATION_THRESHOLD = 0.95d;
2929

3030
private final KnnCollector delegate;
3131
private final double saturationThreshold;
@@ -36,6 +36,7 @@ public class HnswQueueSaturationCollector implements HnswKnnCollector {
3636
private int currentQueueSize;
3737

3838
HnswQueueSaturationCollector(KnnCollector delegate, double saturationThreshold, int patience) {
39+
super(delegate);
3940
this.delegate = delegate;
4041
this.previousQueueSize = 0;
4142
this.currentQueueSize = 0;
@@ -46,6 +47,7 @@ public class HnswQueueSaturationCollector implements HnswKnnCollector {
4647
}
4748

4849
public HnswQueueSaturationCollector(KnnCollector delegate) {
50+
super(delegate);
4951
this.delegate = delegate;
5052
this.previousQueueSize = 0;
5153
this.currentQueueSize = 0;
@@ -64,26 +66,6 @@ public boolean earlyTerminated() {
6466
return delegate.earlyTerminated() || patienceFinished;
6567
}
6668

67-
@Override
68-
public void incVisitedCount(int count) {
69-
delegate.incVisitedCount(count);
70-
}
71-
72-
@Override
73-
public long visitedCount() {
74-
return delegate.visitedCount();
75-
}
76-
77-
@Override
78-
public long visitLimit() {
79-
return delegate.visitLimit();
80-
}
81-
82-
@Override
83-
public int k() {
84-
return delegate.k();
85-
}
86-
8769
@Override
8870
public boolean collect(int docId, float similarity) {
8971
boolean collect = delegate.collect(docId, similarity);

0 commit comments

Comments
 (0)