-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Heemin Kim <[email protected]>
- Loading branch information
Showing
70 changed files
with
2,105 additions
and
316 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.common; | ||
|
||
import java.util.Map; | ||
|
||
import static org.opensearch.knn.index.util.Faiss.FAISS_BINARY_INDEX_DESCRIPTION_PREFIX; | ||
|
||
public class KNNFaissUtil { | ||
public boolean isBinaryIndex(Map<String, Object> parameters) { | ||
return parameters.get(KNNConstants.INDEX_DESCRIPTION_PARAMETER) != null | ||
&& parameters.get(KNNConstants.INDEX_DESCRIPTION_PARAMETER).toString().startsWith(FAISS_BINARY_INDEX_DESCRIPTION_PREFIX); | ||
} | ||
} |
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); | ||
} | ||
} |
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
Oops, something went wrong.