Skip to content

Commit

Permalink
Remove forbidden API
Browse files Browse the repository at this point in the history
  • Loading branch information
dungba88 committed Nov 17, 2024
1 parent 96d2987 commit e2ab4bc
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ private TopDocs searchLeaf(
return results;
}

protected TopDocs getLeafResults(
private TopDocs getLeafResults(
LeafReaderContext ctx,
Weight filterWeight,
TimeLimitingKnnCollectorManager timeLimitingKnnCollectorManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.FloatVectorValues;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.search.knn.KnnCollectorManager;
import org.apache.lucene.util.ArrayUtil;
import org.apache.lucene.util.Bits;

public class TwoPhaseKnnVectorQuery extends KnnFloatVectorQuery {

Expand All @@ -45,12 +47,14 @@ protected TopDocs mergeLeafResults(TopDocs[] perLeafResults) {
}

@Override
protected TopDocs getLeafResults(
protected TopDocs approximateSearch(
LeafReaderContext context,
Weight filterWeight,
TimeLimitingKnnCollectorManager knnCollectorManager)
Bits acceptDocs,
int visitedLimit,
KnnCollectorManager knnCollectorManager)
throws IOException {
TopDocs results = super.getLeafResults(context, filterWeight, knnCollectorManager);
TopDocs results =
super.approximateSearch(context, acceptDocs, visitedLimit, knnCollectorManager);
if (results.scoreDocs.length <= originalK) {
// short-circuit: no re-ranking needed. we got what we need
return results;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.lucene.search;

import java.util.HashMap;
Expand All @@ -18,11 +34,12 @@
import org.apache.lucene.index.VectorSimilarityFunction;
import org.apache.lucene.store.ByteBuffersDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.tests.util.LuceneTestCase;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class TestTwoPhaseKnnVectorQuery {
public class TestTwoPhaseKnnVectorQuery extends LuceneTestCase {

private static final String FIELD = "vector";
public static final VectorSimilarityFunction VECTOR_SIMILARITY_FUNCTION =
Expand All @@ -33,7 +50,9 @@ public class TestTwoPhaseKnnVectorQuery {
private static final int VECTOR_DIMENSION = 128;

@Before
@Override
public void setUp() throws Exception {
super.setUp();
directory = new ByteBuffersDirectory();

// Set up the IndexWriterConfig to use quantized vector storage
Expand All @@ -45,9 +64,10 @@ public void setUp() throws Exception {
public void testTwoPhaseKnnVectorQuery() throws Exception {
Map<Integer, float[]> vectors = new HashMap<>();

Random random = random();

// Step 1: Index random vectors in quantized format
try (IndexWriter writer = new IndexWriter(directory, config)) {
Random random = new Random();
for (int i = 0; i < NUM_VECTORS; i++) {
float[] vector = randomFloatVector(VECTOR_DIMENSION, random);
Document doc = new Document();
Expand All @@ -61,7 +81,7 @@ public void testTwoPhaseKnnVectorQuery() throws Exception {
// Step 2: Run TwoPhaseKnnVectorQuery with a random target vector
try (IndexReader reader = DirectoryReader.open(directory)) {
IndexSearcher searcher = new IndexSearcher(reader);
float[] targetVector = randomFloatVector(VECTOR_DIMENSION, new Random());
float[] targetVector = randomFloatVector(VECTOR_DIMENSION, random);
int k = 10;
double oversample = 1.0;

Expand Down

0 comments on commit e2ab4bc

Please sign in to comment.