From 2501ad27905c8b52fbb9f1d3038be4d4c83b6e29 Mon Sep 17 00:00:00 2001 From: Vijayan Balasubramanian Date: Tue, 8 Oct 2024 16:42:10 -0700 Subject: [PATCH] Rename variables Signed-off-by: Vijayan Balasubramanian --- .../codec/BasePerFieldKnnVectorsFormat.java | 20 ++++++++++--------- .../NativeEngines990KnnVectorsFormat.java | 12 +++++------ .../NativeEngines990KnnVectorsWriter.java | 14 ++++++------- .../org/opensearch/knn/KNNRestTestCase.java | 4 ++-- 4 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/main/java/org/opensearch/knn/index/codec/BasePerFieldKnnVectorsFormat.java b/src/main/java/org/opensearch/knn/index/codec/BasePerFieldKnnVectorsFormat.java index 9edf9a588..72187516f 100644 --- a/src/main/java/org/opensearch/knn/index/codec/BasePerFieldKnnVectorsFormat.java +++ b/src/main/java/org/opensearch/knn/index/codec/BasePerFieldKnnVectorsFormat.java @@ -131,20 +131,22 @@ public KnnVectorsFormat getKnnVectorsFormatForField(final String field) { } private NativeEngines990KnnVectorsFormat nativeEngineVectorsFormat() { - int buildVectorDatastructureThreshold = getBuildVectorDataStructureThresholdSetting(mapperService.get()); + // mapperService is already checked for null or valid instance type at caller, hence we don't need + // addition isPresent check here. + int approximateThreshold = getApproximateThresholdValue(); return new NativeEngines990KnnVectorsFormat( new Lucene99FlatVectorsFormat(FlatVectorScorerUtil.getLucene99FlatVectorsScorer()), - buildVectorDatastructureThreshold + approximateThreshold ); } - private int getBuildVectorDataStructureThresholdSetting(final MapperService knnMapperService) { - final IndexSettings indexSettings = knnMapperService.getIndexSettings(); - final Integer buildVectorDataStructureThreshold = indexSettings.getValue( - KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD_SETTING - ); - return buildVectorDataStructureThreshold != null - ? buildVectorDataStructureThreshold + private int getApproximateThresholdValue() { + // This is private method and mapperService is already checked for null or valid instance type before this call + // at caller, hence we don't need additional isPresent check here. + final IndexSettings indexSettings = mapperService.get().getIndexSettings(); + final Integer approximateThresholdValue = indexSettings.getValue(KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD_SETTING); + return approximateThresholdValue != null + ? approximateThresholdValue : KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD_DEFAULT_VALUE; } diff --git a/src/main/java/org/opensearch/knn/index/codec/KNN990Codec/NativeEngines990KnnVectorsFormat.java b/src/main/java/org/opensearch/knn/index/codec/KNN990Codec/NativeEngines990KnnVectorsFormat.java index cf04aa05a..520a9838d 100644 --- a/src/main/java/org/opensearch/knn/index/codec/KNN990Codec/NativeEngines990KnnVectorsFormat.java +++ b/src/main/java/org/opensearch/knn/index/codec/KNN990Codec/NativeEngines990KnnVectorsFormat.java @@ -31,7 +31,7 @@ public class NativeEngines990KnnVectorsFormat extends KnnVectorsFormat { /** The format for storing, reading, merging vectors on disk */ private static FlatVectorsFormat flatVectorsFormat; private static final String FORMAT_NAME = "NativeEngines990KnnVectorsFormat"; - private static int buildVectorDatastructureThreshold; + private static int approximateThreshold; public NativeEngines990KnnVectorsFormat() { this(new Lucene99FlatVectorsFormat(new DefaultFlatVectorScorer())); @@ -41,10 +41,10 @@ public NativeEngines990KnnVectorsFormat(final FlatVectorsFormat flatVectorsForma this(flatVectorsFormat, KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD_DEFAULT_VALUE); } - public NativeEngines990KnnVectorsFormat(final FlatVectorsFormat flatVectorsFormat, int buildVectorDatastructureThreshold) { + public NativeEngines990KnnVectorsFormat(final FlatVectorsFormat flatVectorsFormat, int approximateThreshold) { super(FORMAT_NAME); NativeEngines990KnnVectorsFormat.flatVectorsFormat = flatVectorsFormat; - NativeEngines990KnnVectorsFormat.buildVectorDatastructureThreshold = buildVectorDatastructureThreshold; + NativeEngines990KnnVectorsFormat.approximateThreshold = approximateThreshold; } /** @@ -54,7 +54,7 @@ public NativeEngines990KnnVectorsFormat(final FlatVectorsFormat flatVectorsForma */ @Override public KnnVectorsWriter fieldsWriter(final SegmentWriteState state) throws IOException { - return new NativeEngines990KnnVectorsWriter(state, flatVectorsFormat.fieldsWriter(state), buildVectorDatastructureThreshold); + return new NativeEngines990KnnVectorsWriter(state, flatVectorsFormat.fieldsWriter(state), approximateThreshold); } /** @@ -73,8 +73,8 @@ public String toString() { + this.getClass().getSimpleName() + ", flatVectorsFormat=" + flatVectorsFormat - + ", buildVectorDatastructureThreshold" - + buildVectorDatastructureThreshold + + ", approximateThreshold=" + + approximateThreshold + ")"; } } diff --git a/src/main/java/org/opensearch/knn/index/codec/KNN990Codec/NativeEngines990KnnVectorsWriter.java b/src/main/java/org/opensearch/knn/index/codec/KNN990Codec/NativeEngines990KnnVectorsWriter.java index e6720e7cf..7c8636577 100644 --- a/src/main/java/org/opensearch/knn/index/codec/KNN990Codec/NativeEngines990KnnVectorsWriter.java +++ b/src/main/java/org/opensearch/knn/index/codec/KNN990Codec/NativeEngines990KnnVectorsWriter.java @@ -53,16 +53,16 @@ public class NativeEngines990KnnVectorsWriter extends KnnVectorsWriter { private KNN990QuantizationStateWriter quantizationStateWriter; private final List> fields = new ArrayList<>(); private boolean finished; - private final Integer buildVectorDataStructureThreshold; + private final Integer approximateThreshold; public NativeEngines990KnnVectorsWriter( SegmentWriteState segmentWriteState, FlatVectorsWriter flatVectorsWriter, - Integer buildVectorDataStructureThreshold + Integer approximateThreshold ) { this.segmentWriteState = segmentWriteState; this.flatVectorsWriter = flatVectorsWriter; - this.buildVectorDataStructureThreshold = buildVectorDataStructureThreshold; + this.approximateThreshold = approximateThreshold; } /** @@ -111,7 +111,7 @@ public void flush(int maxDoc, final Sorter.DocMap sortMap) throws IOException { "Skip building vector data structure for field: {}, as liveDoc: {} is less than the threshold {} during flush", fieldInfo.name, totalLiveDocs, - buildVectorDataStructureThreshold + approximateThreshold ); continue; } @@ -151,7 +151,7 @@ public void mergeOneField(final FieldInfo fieldInfo, final MergeState mergeState "Skip building vector data structure for field: {}, as liveDoc: {} is less than the threshold {} during merge", fieldInfo.name, totalLiveDocs, - buildVectorDataStructureThreshold + approximateThreshold ); return; } @@ -287,9 +287,9 @@ private void initQuantizationStateWriterIfNecessary() throws IOException { } private boolean shouldSkipBuildingVectorDataStructure(final long docCount) { - if (buildVectorDataStructureThreshold < 0) { + if (approximateThreshold < 0) { return true; } - return docCount < buildVectorDataStructureThreshold; + return docCount < approximateThreshold; } } diff --git a/src/testFixtures/java/org/opensearch/knn/KNNRestTestCase.java b/src/testFixtures/java/org/opensearch/knn/KNNRestTestCase.java index a05ecb4b8..2c2efed3d 100644 --- a/src/testFixtures/java/org/opensearch/knn/KNNRestTestCase.java +++ b/src/testFixtures/java/org/opensearch/knn/KNNRestTestCase.java @@ -775,12 +775,12 @@ protected Settings getKNNSegmentReplicatedIndexSettings() { .build(); } - protected Settings buildKNNIndexSettings(int buildVectorDatastructureThreshold) { + protected Settings buildKNNIndexSettings(int approximateThreshold) { return Settings.builder() .put("number_of_shards", 1) .put("number_of_replicas", 0) .put(KNN_INDEX, true) - .put(INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, buildVectorDatastructureThreshold) + .put(INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, approximateThreshold) .build(); }