Skip to content

Commit

Permalink
change version
Browse files Browse the repository at this point in the history
Signed-off-by: Balasubramanian <[email protected]>
  • Loading branch information
VijayanB committed Feb 11, 2025
1 parent 69f4e6f commit 8c64b30
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ protected BiFunction<float[], float[], Float> getScoringMethod(float[] processed
protected BiFunction<float[], float[], Float> getScoringMethod(final float[] processedQuery, Version indexCreatedVersion) {
SpaceType.COSINESIMIL.validateVector(processedQuery);
float qVectorSquaredMagnitude = getVectorMagnitudeSquared(processedQuery);
if (indexCreatedVersion.onOrAfter(Version.V_2_19_0)) {
if (indexCreatedVersion.onOrAfter(Version.V_2_17_0)) {
// To be consistent, we will be using same formula used by lucene as mentioned below
// https://github.com/apache/lucene/blob/0494c824e0ac8049b757582f60d085932a890800/lucene/core/src/java/org/apache/lucene/index/VectorSimilarityFunction.java#L73
// for indices that are created on or after 2.19.0
Expand Down
55 changes: 0 additions & 55 deletions src/test/java/org/opensearch/knn/index/NmslibIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,61 +194,6 @@ public void testEndToEnd() throws Exception {
fail("Graphs are not getting evicted");
}

public void testEndToEnd_withApproxAndExactSearch_inSameIndex_ForCosineSpaceType() throws Exception {
String indexName = "test-index-1";
String fieldName = "test-field-1";
SpaceType spaceType = SpaceType.COSINESIMIL;
Integer dimension = testData.indexData.vectors[0].length;

// Create an index
XContentBuilder builder = XContentFactory.jsonBuilder()
.startObject()
.startObject("properties")
.startObject(fieldName)
.field("type", "knn_vector")
.field("dimension", dimension)
.field(KNNConstants.METHOD_PARAMETER_SPACE_TYPE, spaceType.getValue())
.startObject(KNNConstants.KNN_METHOD)
.field(KNNConstants.NAME, KNNConstants.METHOD_HNSW)
.field(KNNConstants.KNN_ENGINE, KNNEngine.NMSLIB.getName())
.endObject()
.endObject()
.endObject()
.endObject();

Map<String, Object> mappingMap = xContentBuilderToMap(builder);
String mapping = builder.toString();

createKnnIndex(indexName, buildKNNIndexSettings(0), mapping);

// Index one document
addKnnDoc(indexName, randomAlphaOfLength(5), fieldName, Floats.asList(testData.indexData.vectors[0]).toArray());

// Assert we have the right number of documents in the index
refreshAllIndices();
assertEquals(1, getDocCount(indexName));
// update threshold setting to skip building graph
updateIndexSettings(indexName, Settings.builder().put(KNNSettings.INDEX_KNN_ADVANCED_APPROXIMATE_THRESHOLD, -1));
// add duplicate document with different id
addKnnDoc(indexName, randomAlphaOfLength(5), fieldName, Floats.asList(testData.indexData.vectors[0]).toArray());
assertEquals(2, getDocCount(indexName));
final int k = 2;
// search index
Response response = searchKNNIndex(
indexName,
KNNQueryBuilder.builder().fieldName(fieldName).vector(testData.queries[0]).k(k).build(),
k
);
String responseBody = EntityUtils.toString(response.getEntity());
List<KNNResult> knnResults = parseSearchResponse(responseBody, fieldName);
assertEquals(k, knnResults.size());

List<Float> actualScores = parseSearchResponseScore(responseBody, fieldName);

// both document should have identical score
assertEquals(actualScores.get(0), actualScores.get(1), 0.001);
}

@SneakyThrows
private void validateSearch(
final String indexName,
Expand Down

0 comments on commit 8c64b30

Please sign in to comment.