forked from opensearch-project/k-NN
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add binary format support with HNSW method in Faiss Engine
Signed-off-by: Heemin Kim <[email protected]>
- Loading branch information
Showing
73 changed files
with
2,272 additions
and
427 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
src/main/java/org/opensearch/knn/index/KNNVectorSimilarityFunction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.index; | ||
|
||
import org.apache.lucene.index.VectorSimilarityFunction; | ||
import org.opensearch.knn.plugin.script.KNNScoringUtil; | ||
|
||
/** | ||
* Wrapper class of VectorSimilarityFunction to support more function than what Lucene provides | ||
*/ | ||
public enum KNNVectorSimilarityFunction { | ||
EUCLIDEAN(VectorSimilarityFunction.EUCLIDEAN), | ||
DOT_PRODUCT(VectorSimilarityFunction.DOT_PRODUCT), | ||
COSINE(VectorSimilarityFunction.COSINE), | ||
MAXIMUM_INNER_PRODUCT(VectorSimilarityFunction.MAXIMUM_INNER_PRODUCT), | ||
HAMMING(null) { | ||
@Override | ||
public float compare(float[] v1, float[] v2) { | ||
throw new IllegalStateException("Hamming space is not supported with float vectors"); | ||
} | ||
|
||
@Override | ||
public float compare(byte[] v1, byte[] v2) { | ||
return 1.0f / (1 + KNNScoringUtil.calculateHammingBit(v1, v2)); | ||
} | ||
|
||
@Override | ||
public VectorSimilarityFunction getVectorSimilarityFunction() { | ||
throw new IllegalStateException("VectorSimilarityFunction is not available for Hamming space"); | ||
} | ||
}; | ||
|
||
private final VectorSimilarityFunction vectorSimilarityFunction; | ||
|
||
KNNVectorSimilarityFunction(final VectorSimilarityFunction vectorSimilarityFunction) { | ||
this.vectorSimilarityFunction = vectorSimilarityFunction; | ||
} | ||
|
||
public VectorSimilarityFunction getVectorSimilarityFunction() { | ||
return vectorSimilarityFunction; | ||
} | ||
|
||
public float compare(float[] var1, float[] var2) { | ||
return vectorSimilarityFunction.compare(var1, var2); | ||
} | ||
|
||
public float compare(byte[] var1, byte[] var2) { | ||
return vectorSimilarityFunction.compare(var1, var2); | ||
} | ||
} |
Oops, something went wrong.