Skip to content

Commit 46157d8

Browse files
committed
fix tests due to multiple random index versioning
1 parent 479bffa commit 46157d8

File tree

3 files changed

+31
-12
lines changed

3 files changed

+31
-12
lines changed

docs/changelog/131058.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
pr: 131058
2-
summary: Add Sparse Vector Index Options Settings to Semantic Text Field
2+
summary: Adds sparse vector index options settings to semantic_text field
33
area: Search
44
type: enhancement
55
issues: []

server/src/test/java/org/elasticsearch/index/mapper/vectors/SparseVectorFieldMapperTests.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,4 +906,8 @@ private Map<String, Float> toFloats(Map<String, ?> value) {
906906
}
907907
return result;
908908
}
909+
910+
public static IndexVersion getIndexOptionsCompatibleIndexVersion() {
911+
return IndexVersionUtils.randomVersionBetween(random(), SPARSE_VECTOR_PRUNING_INDEX_OPTIONS_SUPPORT, IndexVersion.current());
912+
}
909913
}

x-pack/plugin/inference/src/test/java/org/elasticsearch/xpack/inference/mapper/SemanticTextFieldMapperTests.java

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
import org.elasticsearch.index.mapper.vectors.DenseVectorFieldMapper;
5858
import org.elasticsearch.index.mapper.vectors.DenseVectorFieldTypeTests;
5959
import org.elasticsearch.index.mapper.vectors.SparseVectorFieldMapper;
60+
import org.elasticsearch.index.mapper.vectors.SparseVectorFieldMapperTests;
6061
import org.elasticsearch.index.mapper.vectors.SparseVectorFieldTypeTests;
6162
import org.elasticsearch.index.mapper.vectors.TokenPruningConfig;
6263
import org.elasticsearch.index.query.SearchExecutionContext;
@@ -725,10 +726,11 @@ public void testSparseVectorMappingUpdate() throws IOException {
725726
for (int i = 0; i < 5; i++) {
726727
Model model = TestModel.createRandomInstance(TaskType.SPARSE_EMBEDDING);
727728
final ChunkingSettings chunkingSettings = generateRandomChunkingSettings(false);
729+
IndexVersion indexVersion = SparseVectorFieldMapperTests.getIndexOptionsCompatibleIndexVersion();
728730
final SemanticTextIndexOptions indexOptions = randomSemanticTextIndexOptions(TaskType.SPARSE_EMBEDDING);
729731
String fieldName = "field";
730732

731-
MapperService mapperService = createMapperService(
733+
MapperService mapperService = createMapperServiceWithIndexVersion(
732734
mapping(
733735
b -> addSemanticTextMapping(
734736
b,
@@ -740,17 +742,31 @@ public void testSparseVectorMappingUpdate() throws IOException {
740742
new MinimalServiceSettings(model)
741743
)
742744
),
743-
useLegacyFormat
745+
useLegacyFormat,
746+
indexVersion
744747
);
745-
assertSemanticTextField(mapperService, fieldName, true, chunkingSettings, indexOptions);
748+
var expectedIndexOptions = (indexOptions == null)
749+
? new SemanticTextIndexOptions(
750+
SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR,
751+
SparseVectorFieldMapper.SparseVectorIndexOptions.getDefaultIndexOptions(indexVersion)
752+
)
753+
: indexOptions;
754+
assertSemanticTextField(mapperService, fieldName, true, chunkingSettings, expectedIndexOptions);
746755

747756
final SemanticTextIndexOptions newIndexOptions = randomSemanticTextIndexOptions(TaskType.SPARSE_EMBEDDING);
757+
expectedIndexOptions = (newIndexOptions == null)
758+
? new SemanticTextIndexOptions(
759+
SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR,
760+
SparseVectorFieldMapper.SparseVectorIndexOptions.getDefaultIndexOptions(indexVersion)
761+
)
762+
: newIndexOptions;
763+
748764
ChunkingSettings newChunkingSettings = generateRandomChunkingSettingsOtherThan(chunkingSettings);
749765
merge(
750766
mapperService,
751767
mapping(b -> addSemanticTextMapping(b, fieldName, model.getInferenceEntityId(), null, newChunkingSettings, newIndexOptions))
752768
);
753-
assertSemanticTextField(mapperService, fieldName, true, newChunkingSettings, newIndexOptions);
769+
assertSemanticTextField(mapperService, fieldName, true, newChunkingSettings, expectedIndexOptions);
754770
}
755771
}
756772

@@ -959,13 +975,12 @@ public void testSuccessfulParse() throws IOException {
959975
);
960976
});
961977

962-
var expectedIndexOptions = indexOptions;
963-
if (expectedIndexOptions == null) {
964-
expectedIndexOptions = new SemanticTextIndexOptions(
965-
SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR,
966-
SparseVectorFieldMapper.SparseVectorIndexOptions.getDefaultIndexOptions(indexVersion)
967-
);
968-
}
978+
var expectedIndexOptions = (indexOptions == null)
979+
? new SemanticTextIndexOptions(
980+
SemanticTextIndexOptions.SupportedIndexOptions.SPARSE_VECTOR,
981+
SparseVectorFieldMapper.SparseVectorIndexOptions.getDefaultIndexOptions(indexVersion)
982+
)
983+
: indexOptions;
969984

970985
MapperService mapperService = createMapperServiceWithIndexVersion(mapping, useLegacyFormat, indexVersion);
971986
assertSemanticTextField(mapperService, fieldName1, true, null, expectedIndexOptions);

0 commit comments

Comments
 (0)