-
Notifications
You must be signed in to change notification settings - Fork 132
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
Add cosine similarity support for faiss engine #2376
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import org.opensearch.knn.index.engine.qframe.QuantizationConfig; | ||
import org.opensearch.knn.index.mapper.PerDimensionProcessor; | ||
import org.opensearch.knn.index.mapper.PerDimensionValidator; | ||
import org.opensearch.knn.index.mapper.VectorTransformer; | ||
import org.opensearch.knn.index.mapper.VectorValidator; | ||
|
||
import java.util.Map; | ||
|
@@ -47,4 +48,12 @@ public interface KNNLibraryIndexingContext { | |
* @return Get the per dimension processor | ||
*/ | ||
PerDimensionProcessor getPerDimensionProcessor(); | ||
|
||
/** | ||
* Get the vector transformer that will be used to transform the vector before indexing. | ||
* This will be applied at vector level once entire vector is parsed and validated. | ||
* | ||
* @return VectorTransformer | ||
*/ | ||
VectorTransformer getVectorTransformer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. javadoc? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -681,6 +681,8 @@ protected void validatePreparse() { | |
*/ | ||
protected abstract PerDimensionProcessor getPerDimensionProcessor(); | ||
|
||
protected abstract VectorTransformer getVectorTransformer(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you add java doc for this one? Also, can you update javadoc for getVectorValidator() to say that it is validated before any transform calls? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ack |
||
|
||
protected void parseCreateField(ParseContext context, int dimension, VectorDataType vectorDataType) throws IOException { | ||
validatePreparse(); | ||
|
||
|
@@ -691,7 +693,8 @@ protected void parseCreateField(ParseContext context, int dimension, VectorDataT | |
} | ||
final byte[] array = bytesArrayOptional.get(); | ||
getVectorValidator().validateVector(array); | ||
context.doc().addAll(getFieldsForByteVector(array)); | ||
final byte[] transformedArray = getVectorTransformer().transform(array); | ||
context.doc().addAll(getFieldsForByteVector(transformedArray)); | ||
} else if (VectorDataType.FLOAT == vectorDataType) { | ||
Optional<float[]> floatsArrayOptional = getFloatsFromContext(context, dimension); | ||
|
||
|
@@ -700,7 +703,8 @@ protected void parseCreateField(ParseContext context, int dimension, VectorDataT | |
} | ||
final float[] array = floatsArrayOptional.get(); | ||
getVectorValidator().validateVector(array); | ||
context.doc().addAll(getFieldsForFloatVector(array)); | ||
final float[] transformedArray = getVectorTransformer().transform(array); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will be called before the per-dimension processor too? What should contract around these 2 be? Im wondering if we even need the per-dimension or if we can wrap that in this new full vector transform. |
||
context.doc().addAll(getFieldsForFloatVector(transformedArray)); | ||
} else { | ||
throw new IllegalArgumentException( | ||
String.format(Locale.ROOT, "Cannot parse context for unsupported values provided for field [%s]", VECTOR_DATA_TYPE_FIELD) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confused - Why is this correct?