-
Notifications
You must be signed in to change notification settings - Fork 126
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: Naveen Tatikonda <[email protected]>
- Loading branch information
1 parent
dcbe6ad
commit a9fd88b
Showing
7 changed files
with
195 additions
and
113 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
89 changes: 89 additions & 0 deletions
89
src/main/java/org/opensearch/knn/index/codec/KNNScalarQuantizedVectorsFormatParams.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,89 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.knn.index.codec; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.opensearch.knn.index.MethodComponentContext; | ||
|
||
import java.util.Map; | ||
|
||
import static org.opensearch.knn.common.KNNConstants.ENCODER_SQ; | ||
import static org.opensearch.knn.common.KNNConstants.LUCENE_SQ_BITS; | ||
import static org.opensearch.knn.common.KNNConstants.LUCENE_SQ_COMPRESS; | ||
import static org.opensearch.knn.common.KNNConstants.LUCENE_SQ_CONFIDENCE_INTERVAL; | ||
import static org.opensearch.knn.common.KNNConstants.LUCENE_SQ_DEFAULT_BITS; | ||
import static org.opensearch.knn.common.KNNConstants.METHOD_ENCODER_PARAMETER; | ||
|
||
/** | ||
* Class provides params for LuceneHnswScalarQuantizedVectorsFormat | ||
*/ | ||
@Getter | ||
@NoArgsConstructor | ||
public class KNNScalarQuantizedVectorsFormatParams extends KNNVectorsFormatParams { | ||
private float confidenceInterval; | ||
private int bits; | ||
private boolean compressFlag; | ||
|
||
@Override | ||
boolean validate(Map<String, Object> params) { | ||
if (params.get(METHOD_ENCODER_PARAMETER) == null) { | ||
return false; | ||
} | ||
|
||
// Validate if the object is of type MethodComponentContext before casting it later | ||
if (!(params.get(METHOD_ENCODER_PARAMETER) instanceof MethodComponentContext)) { | ||
return false; | ||
} | ||
MethodComponentContext encoderMethodComponentContext = (MethodComponentContext) params.get(METHOD_ENCODER_PARAMETER); | ||
if (!ENCODER_SQ.equals(encoderMethodComponentContext.getName())) { | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
void initialize(Map<String, Object> params, int defaultMaxConnections, int defaultBeamWidth) { | ||
super.initialize(params, defaultMaxConnections, defaultBeamWidth); | ||
MethodComponentContext encoderMethodComponentContext = (MethodComponentContext) params.get(METHOD_ENCODER_PARAMETER); | ||
Map<String, Object> sqEncoderParams = encoderMethodComponentContext.getParameters(); | ||
this.confidenceInterval = getConfidenceInterval(sqEncoderParams); | ||
this.bits = getBits(sqEncoderParams); | ||
this.compressFlag = getCompressFlag(sqEncoderParams); | ||
} | ||
|
||
private Float getConfidenceInterval(final Map<String, Object> params) { | ||
|
||
if (params != null && params.containsKey(LUCENE_SQ_CONFIDENCE_INTERVAL)) { | ||
if (params.get(LUCENE_SQ_CONFIDENCE_INTERVAL).equals(0)) return Float.valueOf(0); | ||
|
||
return ((Double) params.get(LUCENE_SQ_CONFIDENCE_INTERVAL)).floatValue(); | ||
|
||
} | ||
return null; | ||
} | ||
|
||
private int getBits(final Map<String, Object> params) { | ||
if (params != null && params.containsKey(LUCENE_SQ_BITS)) { | ||
return (int) params.get(LUCENE_SQ_BITS); | ||
} | ||
return LUCENE_SQ_DEFAULT_BITS; | ||
} | ||
|
||
private boolean getCompressFlag(final Map<String, Object> params) { | ||
if (params != null && params.containsKey(LUCENE_SQ_COMPRESS)) { | ||
return (boolean) params.get(LUCENE_SQ_COMPRESS); | ||
} | ||
return false; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/main/java/org/opensearch/knn/index/codec/KNNVectorsFormatParams.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,45 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.index.codec; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.opensearch.knn.common.KNNConstants; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Class provides params for LuceneHNSWVectorsFormat | ||
*/ | ||
@NoArgsConstructor | ||
@Getter | ||
public class KNNVectorsFormatParams { | ||
private int maxConnections; | ||
private int beamWidth; | ||
|
||
boolean validate(final Map<String, Object> params) { | ||
return false; | ||
} | ||
|
||
void initialize(final Map<String, Object> params, int defaultMaxConnections, int defaultBeamWidth) { | ||
this.maxConnections = getMaxConnections(params, defaultMaxConnections); | ||
this.beamWidth = getBeamWidth(params, defaultBeamWidth); | ||
} | ||
|
||
private int getMaxConnections(final Map<String, Object> params, int defaultMaxConnections) { | ||
if (params != null && params.containsKey(KNNConstants.METHOD_PARAMETER_M)) { | ||
return (int) params.get(KNNConstants.METHOD_PARAMETER_M); | ||
} | ||
return defaultMaxConnections; | ||
} | ||
|
||
private int getBeamWidth(final Map<String, Object> params, int defaultBeamWidth) { | ||
if (params != null && params.containsKey(KNNConstants.METHOD_PARAMETER_EF_CONSTRUCTION)) { | ||
return (int) params.get(KNNConstants.METHOD_PARAMETER_EF_CONSTRUCTION); | ||
} | ||
return defaultBeamWidth; | ||
} | ||
} |