Skip to content

Commit 378111f

Browse files
committed
Remove FilteredHnswGraphSearcher
1 parent a6db01a commit 378111f

File tree

2 files changed

+0
-314
lines changed

2 files changed

+0
-314
lines changed

server/src/main/java/org/elasticsearch/index/codec/vectors/es910/hnsw/FilteredHnswGraphSearcher.java

Lines changed: 0 additions & 242 deletions
This file was deleted.

server/src/main/java/org/elasticsearch/index/codec/vectors/es910/hnsw/HnswGraphSearcher.java

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import org.apache.lucene.search.KnnCollector;
2323
import org.apache.lucene.search.TopKnnCollector;
24-
import org.apache.lucene.search.knn.KnnSearchStrategy;
2524
import org.apache.lucene.util.BitSet;
2625
import org.apache.lucene.util.Bits;
2726
import org.apache.lucene.util.FixedBitSet;
@@ -56,77 +55,6 @@ public HnswGraphSearcher(NeighborQueue candidates, BitSet visited) {
5655
this.visited = visited;
5756
}
5857

59-
/**
60-
* See {@link HnswGraphSearcher#search(RandomVectorScorer, KnnCollector, HnswGraph, Bits, int)}
61-
*
62-
* @param scorer the scorer to compare the query with the nodes
63-
* @param knnCollector a hnsw knn collector of top knn results to be returned
64-
* @param graph the graph values. May represent the entire graph, or a level in a hierarchical
65-
* graph.
66-
* @param acceptOrds {@link Bits} that represents the allowed document ordinals to match, or
67-
* {@code null} if they are all allowed to match.
68-
*/
69-
public static void search(RandomVectorScorer scorer, KnnCollector knnCollector, HnswGraph graph, Bits acceptOrds) throws IOException {
70-
int filteredDocCount = 0;
71-
if (acceptOrds instanceof BitSet bitSet) {
72-
// Use approximate cardinality as this is good enough, but ensure we don't exceed the graph
73-
// size as that is illogical
74-
filteredDocCount = Math.min(bitSet.approximateCardinality(), graph.size());
75-
}
76-
search(scorer, knnCollector, graph, acceptOrds, filteredDocCount);
77-
}
78-
79-
/**
80-
* Searches the HNSW graph for the nearest neighbors of a query vector. If entry points are
81-
* directly provided via the knnCollector, then the search will be initialized at those points.
82-
* Otherwise, the search will discover the best entry point per the normal HNSW search algorithm.
83-
*
84-
* @param scorer the scorer to compare the query with the nodes
85-
* @param knnCollector a hnsw knn collector of top knn results to be returned
86-
* @param graph the graph values. May represent the entire graph, or a level in a hierarchical
87-
* graph.
88-
* @param acceptOrds {@link Bits} that represents the allowed document ordinals to match, or
89-
* {@code null} if they are all allowed to match.
90-
* @param filteredDocCount the number of docs that pass the filter
91-
*/
92-
public static void search(RandomVectorScorer scorer, KnnCollector knnCollector, HnswGraph graph, Bits acceptOrds, int filteredDocCount)
93-
throws IOException {
94-
assert filteredDocCount >= 0 && filteredDocCount <= graph.size();
95-
KnnSearchStrategy.Hnsw hnswStrategy;
96-
if (knnCollector.getSearchStrategy() instanceof KnnSearchStrategy.Hnsw hnsw) {
97-
hnswStrategy = hnsw;
98-
} else if (knnCollector.getSearchStrategy() instanceof KnnSearchStrategy.Seeded seeded
99-
&& seeded.originalStrategy() instanceof KnnSearchStrategy.Hnsw hnsw) {
100-
hnswStrategy = hnsw;
101-
} else {
102-
hnswStrategy = KnnSearchStrategy.Hnsw.DEFAULT;
103-
}
104-
final AbstractHnswGraphSearcher innerSearcher;
105-
// First, check if we should use a filtered searcher
106-
if (acceptOrds != null
107-
// We can only use filtered search if we know the maxConn
108-
&& graph.maxConn() != HnswGraph.UNKNOWN_MAX_CONN
109-
&& filteredDocCount > 0
110-
&& hnswStrategy.useFilteredSearch((float) filteredDocCount / graph.size())) {
111-
innerSearcher = FilteredHnswGraphSearcher.create(knnCollector.k(), graph, filteredDocCount, acceptOrds);
112-
} else {
113-
innerSearcher = new HnswGraphSearcher(new NeighborQueue(knnCollector.k(), true), new SparseFixedBitSet(getGraphSize(graph)));
114-
}
115-
// Then, check if we the search strategy is seeded
116-
final AbstractHnswGraphSearcher graphSearcher;
117-
if (knnCollector.getSearchStrategy() instanceof KnnSearchStrategy.Seeded seeded && seeded.numberOfEntryPoints() > 0) {
118-
graphSearcher = SeededHnswGraphSearcher.fromEntryPoints(
119-
innerSearcher,
120-
seeded.numberOfEntryPoints(),
121-
seeded.entryPoints(),
122-
graph.size()
123-
);
124-
} else {
125-
graphSearcher = innerSearcher;
126-
}
127-
graphSearcher.search(knnCollector, scorer, graph, acceptOrds);
128-
}
129-
13058
/**
13159
* Search {@link OnHeapHnswGraph}, this method is thread safe.
13260
*

0 commit comments

Comments
 (0)