Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Multi-Vector support for HNSW search #13525

Open
wants to merge 135 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
135 commits
Select commit Hold shift + click to select a range
96e09b3
tensor partial
vigyasharma May 15, 2024
50f3789
docstring edit
vigyasharma May 18, 2024
0050b30
define a KnnFloatTensorField
vigyasharma May 20, 2024
b543668
clean up tensor similarity function
vigyasharma May 20, 2024
c58a3fb
add to fieldIndo and indexing chain schema setup
vigyasharma Jun 13, 2024
b237cdb
started creating new tensor format
vigyasharma Jun 14, 2024
4324151
modified Lucene99FlatVectorsWriter to write tensors
vigyasharma Jun 16, 2024
774e91d
Tensor writer with changes to write tensorDataOffsets
vigyasharma Jun 20, 2024
d15cffc
write byte tensor values
vigyasharma Jun 20, 2024
ada3db1
read tensor metadata and create FieldEntry
vigyasharma Jun 20, 2024
e42a389
Added OffHeapFloatTensorValues
vigyasharma Jun 20, 2024
9bc98bc
support for OffHeapByteTensorValues with code to reuse the bytebuffer
vigyasharma Jun 21, 2024
5e11640
default flat tensor scorer impl
vigyasharma Jun 21, 2024
851a14b
Tensor reader impl. done
vigyasharma Jun 21, 2024
7c39b76
Flat tensor writer impl.
vigyasharma Jun 22, 2024
318455a
revert all tensor changes in FlatVectorsWriter
vigyasharma Jun 22, 2024
b24ae9a
remove unused imports
vigyasharma Jun 23, 2024
a35062f
modify hnswVectorsWriter to build graph with tensors
vigyasharma Jun 25, 2024
c94127d
reuse hnswvectorsreader for tensors
vigyasharma Jun 25, 2024
ced69a3
add knnTensorsformat with an hnsw impl
vigyasharma Jun 25, 2024
b20859f
plumb tensors into the indexing chain
vigyasharma Jun 25, 2024
a30e06e
update lucene94FieldInfosFormat constructor
vigyasharma Jun 25, 2024
13bd4c5
update FieldInfos ctor calls and bw codecs with new params
vigyasharma Jun 25, 2024
834db2b
get tensorReader from codec readers and segment readers
vigyasharma Jun 26, 2024
d214b1b
minor bug fix with readers
vigyasharma Jun 26, 2024
4adefed
add KnnFloatTensorQuery wrapper
vigyasharma Jun 26, 2024
b31e0be
add ByteTensorQuery
vigyasharma Jun 26, 2024
208b041
gradle tidy
vigyasharma Jun 26, 2024
4d173e7
remove commented code
vigyasharma Jun 26, 2024
b5551fc
tidy again
vigyasharma Jun 26, 2024
421b6d6
fix ctor bug
vigyasharma Jun 26, 2024
ee2e0d7
gradle check minus test files
vigyasharma Jun 26, 2024
f50e91a
add no commit tags
vigyasharma Jun 26, 2024
edde79a
make Tensor Similarity Fn a class with Agg enum
vigyasharma Jun 27, 2024
a2a91c4
changed tensor fields, fieldTypes and fieldInfos
vigyasharma Jun 27, 2024
0f7b1dd
modify FlatTensor reader and writers with new FI format
vigyasharma Jun 27, 2024
825e267
modify HnswVectors reader and writer for new FieldInfo
vigyasharma Jun 27, 2024
42475cc
update codecreader and tensor query classes
vigyasharma Jun 27, 2024
0316e02
fix FieldInfo in some files
vigyasharma Jun 27, 2024
0ccb40b
update FieldInfo ctor
vigyasharma Jun 27, 2024
ebc2518
add hashcode to TSF
vigyasharma Jun 27, 2024
21261af
gradle tidy
vigyasharma Jun 27, 2024
872874c
remove nocommits for builds
vigyasharma Jun 27, 2024
d52868f
linting, licenses, and compilation bugs
vigyasharma Jun 27, 2024
749a670
tidy
vigyasharma Jun 27, 2024
ece1728
add missing java docs
vigyasharma Jun 27, 2024
30bdb49
add no commits
vigyasharma Jun 28, 2024
b92d6eb
start single format multivectors change
vigyasharma Jun 30, 2024
1579aea
rename TensorSimilarity to MultiVectorSimilarity
vigyasharma Jul 1, 2024
4f5e494
Add interface to FlatVectorsScorer; del FlatTensorsScorer
vigyasharma Jul 1, 2024
f667e4d
Use DefaultFlatMultiVectorScorer that extends DefFlatVecScorer
vigyasharma Jul 1, 2024
6f13b2e
change OffHeapMVValues; change MVDataOffsetReader
vigyasharma Jul 1, 2024
429a106
change field values to Byte/FloatMultiVectorValue
vigyasharma Jul 1, 2024
104d802
changes to FlatVectorsWriter; del FlatTensorsWriter
vigyasharma Jul 1, 2024
5afa0d9
update FlatVectorsReader to handle multi-vectors
vigyasharma Jul 1, 2024
da32aae
minor import bug
vigyasharma Jul 2, 2024
3fb3808
del FlatTensorReader and FlatTensorFormat
vigyasharma Jul 2, 2024
d0a0b65
Hnsw reader, writer and format changes
vigyasharma Jul 2, 2024
001afd7
remove multivector metadata from hnsw format; not needed
vigyasharma Jul 2, 2024
ca41e85
remove codec change; use static default var for agg fn
vigyasharma Jul 2, 2024
db97c0d
change FieldInfo values; remove TensorQuery classes
vigyasharma Jul 2, 2024
7769e48
restore readers to main branch versions
vigyasharma Jul 2, 2024
1274a27
reword some occurrences of tensor in comments
vigyasharma Jul 2, 2024
05174ff
indexing change and vectorValConsumer changes
vigyasharma Jul 2, 2024
cd08506
some comment changes; use DEF_AGG for MultiVecSimFnAgg
vigyasharma Jul 2, 2024
79450dd
tidy
vigyasharma Jul 2, 2024
cd7e890
compile errors from FI ctor
vigyasharma Jul 2, 2024
0edb868
use ByteBuffer.clear instead of reset
vigyasharma Jul 2, 2024
19fe230
add logs for assert failures
vigyasharma Jul 2, 2024
bca27ff
missed a ;
vigyasharma Jul 2, 2024
93c5077
fix bug around multi-vector condition
vigyasharma Jul 3, 2024
bc0ebc1
bug fix for non-multi-vector case
vigyasharma Jul 3, 2024
1d80b28
tidy
vigyasharma Jul 3, 2024
a33d533
move changes to new format files
vigyasharma Jul 3, 2024
8a098f2
tidy; remove unused imports
vigyasharma Jul 3, 2024
c591b67
remove multi-vector specific check
vigyasharma Jul 3, 2024
51ca4dc
missing docstring
vigyasharma Jul 3, 2024
b5ada6f
tensor partial
vigyasharma May 15, 2024
bc68c8f
docstring edit
vigyasharma May 18, 2024
785c958
define a KnnFloatTensorField
vigyasharma May 20, 2024
d7197be
clean up tensor similarity function
vigyasharma May 20, 2024
9c6d4f5
add to fieldIndo and indexing chain schema setup
vigyasharma Jun 13, 2024
9ce6977
started creating new tensor format
vigyasharma Jun 14, 2024
462e150
modified Lucene99FlatVectorsWriter to write tensors
vigyasharma Jun 16, 2024
b2f3fad
Tensor writer with changes to write tensorDataOffsets
vigyasharma Jun 20, 2024
a88c4ba
write byte tensor values
vigyasharma Jun 20, 2024
8a3ec4f
read tensor metadata and create FieldEntry
vigyasharma Jun 20, 2024
9d6ffd5
Added OffHeapFloatTensorValues
vigyasharma Jun 20, 2024
cf4ca9c
support for OffHeapByteTensorValues with code to reuse the bytebuffer
vigyasharma Jun 21, 2024
a9a345b
default flat tensor scorer impl
vigyasharma Jun 21, 2024
555b055
Tensor reader impl. done
vigyasharma Jun 21, 2024
0abc881
Flat tensor writer impl.
vigyasharma Jun 22, 2024
eebf38e
revert all tensor changes in FlatVectorsWriter
vigyasharma Jun 22, 2024
5334fdb
remove unused imports
vigyasharma Jun 23, 2024
bc02b0b
modify hnswVectorsWriter to build graph with tensors
vigyasharma Jun 25, 2024
1a9ed21
reuse hnswvectorsreader for tensors
vigyasharma Jun 25, 2024
f567095
add knnTensorsformat with an hnsw impl
vigyasharma Jun 25, 2024
059a8ff
plumb tensors into the indexing chain
vigyasharma Jun 25, 2024
7b86353
update lucene94FieldInfosFormat constructor
vigyasharma Jun 25, 2024
1626195
update FieldInfos ctor calls and bw codecs with new params
vigyasharma Jun 25, 2024
27449f5
get tensorReader from codec readers and segment readers
vigyasharma Jun 26, 2024
34d4063
minor bug fix with readers
vigyasharma Jun 26, 2024
543565f
add KnnFloatTensorQuery wrapper
vigyasharma Jun 26, 2024
9a0633b
add ByteTensorQuery
vigyasharma Jun 26, 2024
90c42b2
gradle tidy
vigyasharma Jun 26, 2024
8c3b1c0
remove commented code
vigyasharma Jun 26, 2024
533c2bf
tidy again
vigyasharma Jun 26, 2024
9b7cb0b
fix ctor bug
vigyasharma Jun 26, 2024
c2ae83b
gradle check minus test files
vigyasharma Jun 26, 2024
0ecda0f
add no commit tags
vigyasharma Jun 26, 2024
24d231e
make Tensor Similarity Fn a class with Agg enum
vigyasharma Jun 27, 2024
d08bc68
changed tensor fields, fieldTypes and fieldInfos
vigyasharma Jun 27, 2024
419cc9e
modify FlatTensor reader and writers with new FI format
vigyasharma Jun 27, 2024
75ecb2c
modify HnswVectors reader and writer for new FieldInfo
vigyasharma Jun 27, 2024
e6e6bdf
update codecreader and tensor query classes
vigyasharma Jun 27, 2024
c0912d1
fix FieldInfo in some files
vigyasharma Jun 27, 2024
c24a99f
update FieldInfo ctor
vigyasharma Jun 27, 2024
04636b9
add hashcode to TSF
vigyasharma Jun 27, 2024
4b2bad4
gradle tidy
vigyasharma Jun 27, 2024
a98035c
remove nocommits for builds
vigyasharma Jun 27, 2024
56db6d0
linting, licenses, and compilation bugs
vigyasharma Jun 27, 2024
97d327d
tidy
vigyasharma Jun 27, 2024
acdd158
add missing java docs
vigyasharma Jun 27, 2024
c80cbcf
add no commits
vigyasharma Jun 28, 2024
6ca9e14
merge new changes
vigyasharma Jul 3, 2024
3365889
fix all merge conflicts
vigyasharma Jul 4, 2024
12f5b54
no commits
vigyasharma Jul 4, 2024
ffda63f
remove isMultiVector member in Lucene99FlatMultiVectorsWriter.FieldWr…
cpoerschke Jul 12, 2024
b2b95cd
remove FieldInfo.isMultiVector in favour of MultiVectorSimilarityFunc…
cpoerschke Jul 12, 2024
eacc63c
in IndexingChain.FieldSchema fold setMultiVectors into setVectors
cpoerschke Jul 12, 2024
1570690
remove metadata check for fixed vector lengths. add debug logs
vigyasharma Oct 21, 2024
b1e5568
fix hnsw vector to read MV scorer supplier; fix loop and array copy i…
vigyasharma Oct 22, 2024
ce2face
add Aggregate to FieldInfos format
vigyasharma Oct 22, 2024
2e52495
assert and logs on vector-data rw offsets
vigyasharma Oct 24, 2024
7aa9555
go to base vectorscorer for single valued use-case
vigyasharma Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.MultiVectorSimilarityFunction;
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.index.VectorEncoding;
import org.apache.lucene.index.VectorSimilarityFunction;
Expand Down Expand Up @@ -218,6 +219,7 @@ private FieldInfo[] readFieldInfos(IndexInput input, int version) throws IOExcep
0,
VectorEncoding.FLOAT32,
VectorSimilarityFunction.EUCLIDEAN,
MultiVectorSimilarityFunction.Aggregation.NONE,
isSoftDeletesField,
false);
} catch (IllegalStateException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.MultiVectorSimilarityFunction;
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.index.VectorEncoding;
import org.apache.lucene.index.VectorSimilarityFunction;
Expand Down Expand Up @@ -195,6 +196,7 @@ public FieldInfos read(
vectorDimension,
VectorEncoding.FLOAT32,
vectorDistFunc,
MultiVectorSimilarityFunction.Aggregation.NONE,
isSoftDeletesField,
false);
infos[i].checkConsistency();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.MultiVectorSimilarityFunction;
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.index.VectorEncoding;
import org.apache.lucene.index.VectorSimilarityFunction;
Expand Down Expand Up @@ -199,6 +200,7 @@ public FieldInfos read(
vectorNumDimensions,
vectorEncoding,
vectorDistFunc,
MultiVectorSimilarityFunction.Aggregation.NONE,
isSoftDeletesField,
isParentField);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.apache.lucene.index.DocValuesType;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.MultiVectorSimilarityFunction;
import org.apache.lucene.index.VectorEncoding;
import org.apache.lucene.index.VectorSimilarityFunction;
import org.apache.lucene.store.ByteBuffersDataOutput;
Expand Down Expand Up @@ -120,6 +121,7 @@ private static FieldInfo getMockFieldInfo(String fieldName, int number) {
0,
VectorEncoding.FLOAT32,
VectorSimilarityFunction.EUCLIDEAN,
MultiVectorSimilarityFunction.Aggregation.NONE,
true,
false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.apache.lucene.index.FieldInfos;
import org.apache.lucene.index.ImpactsEnum;
import org.apache.lucene.index.IndexOptions;
import org.apache.lucene.index.MultiVectorSimilarityFunction;
import org.apache.lucene.index.PostingsEnum;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.VectorEncoding;
Expand Down Expand Up @@ -207,6 +208,7 @@ private static FieldInfo mockFieldInfo(String fieldName, int number) {
0,
VectorEncoding.FLOAT32,
VectorSimilarityFunction.EUCLIDEAN,
MultiVectorSimilarityFunction.Aggregation.NONE,
false,
false);
}
Expand Down
3 changes: 2 additions & 1 deletion lucene/core/src/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@
provides org.apache.lucene.codecs.KnnVectorsFormat with
org.apache.lucene.codecs.lucene99.Lucene99HnswVectorsFormat,
org.apache.lucene.codecs.lucene99.Lucene99HnswScalarQuantizedVectorsFormat,
org.apache.lucene.codecs.lucene99.Lucene99ScalarQuantizedVectorsFormat;
org.apache.lucene.codecs.lucene99.Lucene99ScalarQuantizedVectorsFormat,
org.apache.lucene.codecs.lucene99.Lucene99HnswMultiVectorsFormat;
provides org.apache.lucene.codecs.PostingsFormat with
org.apache.lucene.codecs.lucene99.Lucene99PostingsFormat;
provides org.apache.lucene.index.SortFieldProvider with
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
/*
* 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.codecs.hnsw;

import java.io.IOException;
import org.apache.lucene.index.MultiVectorSimilarityFunction;
import org.apache.lucene.index.VectorSimilarityFunction;
import org.apache.lucene.util.hnsw.RandomAccessVectorValues;
import org.apache.lucene.util.hnsw.RandomVectorScorer;
import org.apache.lucene.util.hnsw.RandomVectorScorerSupplier;

/**
* Default multi-vector implementation of {@link FlatVectorsScorer}.
*
* @lucene.experimental
*/
// noCommit - pending tests
public class DefaultFlatMultiVectorScorer extends DefaultFlatVectorScorer {

public static final DefaultFlatMultiVectorScorer INSTANCE = new DefaultFlatMultiVectorScorer();

// @Override
// public RandomVectorScorerSupplier getRandomVectorScorerSupplier(VectorSimilarityFunction similarityFunction, RandomAccessVectorValues vectorValues) throws IOException {
// throw new IllegalStateException("getRandomVectorScorerSupplier called on a Multi-Vector scorer. Expected call to getRandomMultiVectorScorerSupplier instead");
// }

@Override
public RandomVectorScorerSupplier getRandomMultiVectorScorerSupplier(
MultiVectorSimilarityFunction similarityFunction, RandomAccessVectorValues values)
throws IOException {
if (values instanceof RandomAccessVectorValues.Floats floatMultiVectorValues) {
return new FloatScoringSupplier(floatMultiVectorValues, similarityFunction);
} else if (values instanceof RandomAccessVectorValues.Bytes byteMultiVectorValues) {
return new ByteScoringSupplier(byteMultiVectorValues, similarityFunction);
}
throw new IllegalArgumentException(
"MultiVector values must be an instance of RandomAccessVectorValues.Floats or RandomAccessVectorValues.Bytes");
}

@Override
public RandomVectorScorer getRandomMultiVectorScorer(
MultiVectorSimilarityFunction similarityFunction,
RandomAccessVectorValues values,
float[] target)
throws IOException {
assert values instanceof RandomAccessVectorValues.Floats;
if (target.length % values.dimension() != 0) {
throw new IllegalArgumentException(
"query multiVector dimension differs from multiVector field dimension: "
+ values.dimension());
}
return new FloatMultiVectorScorer(
(RandomAccessVectorValues.Floats) values, target, similarityFunction);
}

@Override
public RandomVectorScorer getRandomMultiVectorScorer(
MultiVectorSimilarityFunction similarityFunction,
RandomAccessVectorValues values,
byte[] target)
throws IOException {
assert values instanceof RandomAccessVectorValues.Bytes;
if (target.length % values.dimension() != 0) {
throw new IllegalArgumentException(
"query multiVector dimension differs from multiVector field dimension: "
+ values.dimension());
}
return new ByteMultiVectorScorer(
(RandomAccessVectorValues.Bytes) values, target, similarityFunction);
}

@Override
public String toString() {
return "DefaultFlatMultiVectorScorer()";
}

/** RandomVectorScorerSupplier for bytes multiVectors */
private static final class ByteScoringSupplier implements RandomVectorScorerSupplier {
private final RandomAccessVectorValues.Bytes multiVectors;
private final RandomAccessVectorValues.Bytes multiVectors1;
private final RandomAccessVectorValues.Bytes multiVectors2;
private final MultiVectorSimilarityFunction similarityFunction;
private final int dimension;

private ByteScoringSupplier(
RandomAccessVectorValues.Bytes multiVectors,
MultiVectorSimilarityFunction similarityFunction)
throws IOException {
this.multiVectors = multiVectors;
multiVectors1 = multiVectors.copy();
multiVectors2 = multiVectors.copy();
this.similarityFunction = similarityFunction;
this.dimension = multiVectors.dimension();
}

@Override
public RandomVectorScorer scorer(int ord) {
return new RandomVectorScorer.AbstractRandomVectorScorer(multiVectors) {
@Override
public float score(int node) throws IOException {
return similarityFunction.compare(
multiVectors1.vectorValue(ord), multiVectors2.vectorValue(node), dimension);
}
};
}

@Override
public RandomVectorScorerSupplier copy() throws IOException {
return new ByteScoringSupplier(multiVectors, similarityFunction);
}
}

/** RandomVectorScorerSupplier for Float vector */
private static final class FloatScoringSupplier implements RandomVectorScorerSupplier {
private final RandomAccessVectorValues.Floats multiVectors;
private final RandomAccessVectorValues.Floats multiVectors1;
private final RandomAccessVectorValues.Floats multiVectors2;
private final MultiVectorSimilarityFunction similarityFunction;
private final int dimension;

private FloatScoringSupplier(
RandomAccessVectorValues.Floats multiVectors,
MultiVectorSimilarityFunction similarityFunction)
throws IOException {
this.multiVectors = multiVectors;
multiVectors1 = multiVectors.copy();
multiVectors2 = multiVectors.copy();
this.similarityFunction = similarityFunction;
this.dimension = multiVectors.dimension();
}

@Override
public RandomVectorScorer scorer(int ord) {
return new RandomVectorScorer.AbstractRandomVectorScorer(multiVectors) {
@Override
public float score(int node) throws IOException {
return similarityFunction.compare(
multiVectors1.vectorValue(ord), multiVectors2.vectorValue(node), dimension);
}
};
}

@Override
public RandomVectorScorerSupplier copy() throws IOException {
return new FloatScoringSupplier(multiVectors, similarityFunction);
}
}

/** A {@link RandomVectorScorer} for float multiVectors. */
private static class FloatMultiVectorScorer
extends RandomVectorScorer.AbstractRandomVectorScorer {
private final RandomAccessVectorValues.Floats values;
private final float[] query;
private final MultiVectorSimilarityFunction similarityFunction;
private final int dimension;

public FloatMultiVectorScorer(
RandomAccessVectorValues.Floats values,
float[] query,
MultiVectorSimilarityFunction similarityFunction) {
super(values);
this.values = values;
this.query = query;
this.similarityFunction = similarityFunction;
this.dimension = values.dimension();
}

@Override
public float score(int node) throws IOException {
return similarityFunction.compare(query, values.vectorValue(node), dimension);
}
}

/** A {@link RandomVectorScorer} for byte multiVectors. */
private static class ByteMultiVectorScorer extends RandomVectorScorer.AbstractRandomVectorScorer {
private final RandomAccessVectorValues.Bytes values;
private final byte[] query;
private final MultiVectorSimilarityFunction similarityFunction;
private final int dimension;

public ByteMultiVectorScorer(
RandomAccessVectorValues.Bytes values,
byte[] query,
MultiVectorSimilarityFunction similarityFunction) {
super(values);
this.values = values;
this.query = query;
this.similarityFunction = similarityFunction;
this.dimension = values.dimension();
}

@Override
public float score(int node) throws IOException {
return similarityFunction.compare(query, values.vectorValue(node), dimension);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package org.apache.lucene.codecs.hnsw;

import java.io.IOException;
import org.apache.lucene.index.MultiVectorSimilarityFunction;
import org.apache.lucene.index.VectorSimilarityFunction;
import org.apache.lucene.util.hnsw.RandomAccessVectorValues;
import org.apache.lucene.util.hnsw.RandomVectorScorer;
Expand Down Expand Up @@ -72,4 +73,54 @@ RandomVectorScorer getRandomVectorScorer(
RandomAccessVectorValues vectorValues,
byte[] target)
throws IOException;

/**
* Returns a {@link RandomVectorScorerSupplier} that can be used to score multi-vector values
*
* @param similarityFunction the similarity function to use
* @param values the multi-vector values to score
* @return a {@link RandomVectorScorerSupplier} that can be used to score multi-vectors
* @throws IOException if an I/O error occurs
*/
default RandomVectorScorerSupplier getRandomMultiVectorScorerSupplier(
MultiVectorSimilarityFunction similarityFunction, RandomAccessVectorValues values)
throws IOException {
throw new UnsupportedOperationException("Multi-Vector scoring not supported");
}

/**
* Returns a {@link RandomVectorScorer} for the given set of multi-vectors and target
* multi-vector.
*
* @param similarityFunction the similarity function to use
* @param values the multi-vector values to score
* @param target the target multi-vector with vector values packed in a single array
* @return a {@link RandomVectorScorer} for the given field and target multi-vector.
* @throws IOException if an I/O error occurs when reading from the index.
*/
default RandomVectorScorer getRandomMultiVectorScorer(
MultiVectorSimilarityFunction similarityFunction,
RandomAccessVectorValues values,
float[] target)
throws IOException {
throw new UnsupportedOperationException("Multi-Vector scoring not supported");
}

/**
* Returns a {@link RandomVectorScorer} for the given set of multi-vectors and target
* multi-vector.
*
* @param similarityFunction the similarity function to use
* @param values the multi-vector values to score
* @param target the target multi-vector with vector values packed in a single array
* @return a {@link RandomVectorScorer} for the given field and target multi-vector.
* @throws IOException if an I/O error occurs when reading from the index.
*/
default RandomVectorScorer getRandomMultiVectorScorer(
MultiVectorSimilarityFunction similarityFunction,
RandomAccessVectorValues values,
byte[] target)
throws IOException {
throw new UnsupportedOperationException("Multi-Vector scoring not supported");
}
}
Loading