maedhroz commented on code in PR #4353:
URL: https://github.com/apache/cassandra/pull/4353#discussion_r2692485499


##########
src/java/org/apache/cassandra/index/sai/disk/v1/vector/DiskAnn.java:
##########
@@ -86,86 +83,56 @@ public int size()
         return graph.size();
     }
 
+    public CompressedVectors getCompressedVectors()
+    {
+        return compressedVectors;
+    }
+
     /**
      * @return Row IDs associated with the topK vectors near the query
      */
-    public VectorPostingList search(float[] queryVector, int topK, int limit, 
Bits acceptBits)
+    public CloseableIterator<RowIdWithScore> search(float[] queryVector, int 
topK, int limit, Bits acceptBits, IntConsumer nodesVisitedConsumer)
     {
         OnHeapGraph.validateIndexable(queryVector, similarityFunction);
 
         GraphIndex.View<float[]> view = graph.getView();
-        GraphSearcher<float[]> searcher = new 
GraphSearcher.Builder<>(view).build();
-        NeighborSimilarity.ScoreFunction scoreFunction;
-        NeighborSimilarity.ReRanker<float[]> reRanker;
-        if (compressedVectors == null)
+        try
         {
-            scoreFunction = (NeighborSimilarity.ExactScoreFunction)
-                            i -> similarityFunction.compare(queryVector, 
view.getVector(i));
-            reRanker = null;
+            GraphSearcher<float[]> searcher = new 
GraphSearcher.Builder<>(view).build();
+            NeighborSimilarity.ScoreFunction scoreFunction;
+            NeighborSimilarity.ReRanker<float[]> reRanker;
+            if (compressedVectors == null)
+            {
+                scoreFunction = (NeighborSimilarity.ExactScoreFunction)
+                                i -> similarityFunction.compare(queryVector, 
view.getVector(i));
+                reRanker = null;
+            }
+            else
+            {
+                scoreFunction = 
compressedVectors.approximateScoreFunctionFor(queryVector, similarityFunction);
+                reRanker = (i, map) -> similarityFunction.compare(queryVector, 
map.get(i));
+            }
+            Bits acceptedBits = ordinalsMap.ignoringDeleted(acceptBits);
+            // Search is done within the iterator to keep track of visited 
nodes. The resulting iterator
+            // searches until the graph is exhausted.
+            AutoResumingNodeScoreIterator nodeScoreIterator = new 
AutoResumingNodeScoreIterator(searcher, scoreFunction, reRanker, topK, 
acceptedBits, nodesVisitedConsumer, false, source, view);
+            return new NodeScoreToRowIdWithScoreIterator(nodeScoreIterator, 
ordinalsMap.getRowIdsView());
         }
-        else
+        catch (Exception e)
         {
-            scoreFunction = 
compressedVectors.approximateScoreFunctionFor(queryVector, similarityFunction);
-            reRanker = (i, map) -> similarityFunction.compare(queryVector, 
map.get(i));
+            FileUtils.closeQuietly(view);
+            throw new RuntimeException(e);

Review Comment:
   ```suggestion
           throw Throwables.unchecked(e);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to