Skip to content

Commit

Permalink
Fix a flaky unit test:testMultiFieldsKnnIndex, which was failing due …
Browse files Browse the repository at this point in the history
…to inconsistent merge behaviors

Signed-off-by: Navneet Verma <[email protected]>
  • Loading branch information
navneet1v committed Aug 2, 2024
1 parent 523c681 commit efe3536
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
### Infrastructure
### Documentation
### Maintenance
* Fix a flaky unit test:testMultiFieldsKnnIndex, which was failing due to inconsistent merge behaviors [#1924](https://github.com/opensearch-project/k-NN/pull/1924)
### Refactoring
* Introduce KNNVectorValues interface to iterate on different types of Vector values during indexing and search [#1897](https://github.com/opensearch-project/k-NN/pull/1897)
* Clean up parsing for query [#1824](https://github.com/opensearch-project/k-NN/pull/1824)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,28 +137,27 @@ public void testMultiFieldsKnnIndex(Codec codec) throws Exception {
Document doc = new Document();
doc.add(vectorField);
writer.addDocument(doc);
writer.close();
// ensuring the refresh happens, to create the segment and hnsw file
writer.flush();

/**
* Add doc with field "my_vector"
*/
IndexWriterConfig iwc1 = newIndexWriterConfig();
iwc1.setMergeScheduler(new SerialMergeScheduler());
iwc1.setCodec(ACTUAL_CODEC);
writer = new RandomIndexWriter(random(), dir, iwc1);
float[] array1 = { 6.0f, 14.0f };
VectorField vectorField1 = new VectorField("my_vector", array1, sampleFieldType);
Document doc1 = new Document();
doc1.add(vectorField1);
writer.addDocument(doc1);
// ensuring the refresh happens, to create the segment and hnsw file
writer.flush();
IndexReader reader = writer.getReader();
writer.close();
ResourceWatcherService resourceWatcherService = createDisabledResourceWatcherService();
NativeMemoryLoadStrategy.IndexLoadStrategy.initialize(resourceWatcherService);
List<String> hnswfiles = Arrays.stream(dir.listAll()).filter(x -> x.contains("hnsw")).collect(Collectors.toList());

// there should be 2 hnsw index files created. one for test_vector and one for my_vector
assertEquals(hnswfiles.size(), 2);
assertEquals(2, hnswfiles.size());
assertEquals(hnswfiles.stream().filter(x -> x.contains("test_vector")).collect(Collectors.toList()).size(), 1);
assertEquals(hnswfiles.stream().filter(x -> x.contains("my_vector")).collect(Collectors.toList()).size(), 1);

Expand Down

0 comments on commit efe3536

Please sign in to comment.