-
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.
Browse files
Browse the repository at this point in the history
Signed-off-by: Navneet Verma <[email protected]>
- Loading branch information
Showing
17 changed files
with
339 additions
and
76 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
37 changes: 37 additions & 0 deletions
37
src/main/java/org/opensearch/knn/common/FieldInfoExtractor.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,37 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.knn.common; | ||
|
||
import lombok.experimental.UtilityClass; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.apache.lucene.index.FieldInfo; | ||
import org.opensearch.knn.index.VectorDataType; | ||
import org.opensearch.knn.indices.ModelMetadata; | ||
import org.opensearch.knn.indices.ModelUtil; | ||
|
||
/** | ||
* A utility class to extract information from FieldInfo. | ||
*/ | ||
@UtilityClass | ||
public class FieldInfoExtractor { | ||
|
||
/** | ||
* Extract vector data type from fieldInfo | ||
* @param fieldInfo {@link FieldInfo} | ||
* @return {@link VectorDataType} | ||
*/ | ||
public static VectorDataType extractVectorDataType(final FieldInfo fieldInfo) { | ||
String vectorDataTypeString = fieldInfo.getAttribute(KNNConstants.VECTOR_DATA_TYPE_FIELD); | ||
if (StringUtils.isEmpty(vectorDataTypeString)) { | ||
final ModelMetadata modelMetadata = ModelUtil.getModelMetadata(fieldInfo.getAttribute(KNNConstants.MODEL_ID)); | ||
if (modelMetadata != null) { | ||
VectorDataType vectorDataType = modelMetadata.getVectorDataType(); | ||
vectorDataTypeString = vectorDataType == null ? null : vectorDataType.getValue(); | ||
} | ||
} | ||
return StringUtils.isNotEmpty(vectorDataTypeString) ? VectorDataType.get(vectorDataTypeString) : VectorDataType.DEFAULT; | ||
} | ||
} |
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
Oops, something went wrong.