msokolov commented on a change in pull request #2214: URL: https://github.com/apache/lucene-solr/pull/2214#discussion_r560546645
########## File path: lucene/core/src/test/org/apache/lucene/index/TestVectorValues.java ########## @@ -815,4 +816,47 @@ public void testSearchStrategyIdentifiers() { assertEquals(2, VectorValues.SearchStrategy.DOT_PRODUCT_HNSW.ordinal()); assertEquals(3, VectorValues.SearchStrategy.values().length); } + + public void testAdvance() throws Exception { + try (Directory dir = newDirectory()) { + try (IndexWriter w = new IndexWriter(dir, createIndexWriterConfig())) { + int numdocs = 2000; + String fieldName = "field"; + for (int i = 0; i < numdocs; i++) { + Document doc = new Document(); + // randomly add a vector field + if (random().nextInt(4) == 3) { + doc.add( + new VectorField( + fieldName, new float[4], VectorValues.SearchStrategy.DOT_PRODUCT_HNSW)); Review comment: Maybe use SearchStrategy.NONE here so we don't bother building a graph for this test case, which works the same with or without ########## File path: lucene/core/src/test/org/apache/lucene/index/TestVectorValues.java ########## @@ -815,4 +816,47 @@ public void testSearchStrategyIdentifiers() { assertEquals(2, VectorValues.SearchStrategy.DOT_PRODUCT_HNSW.ordinal()); assertEquals(3, VectorValues.SearchStrategy.values().length); } + + public void testAdvance() throws Exception { + try (Directory dir = newDirectory()) { + try (IndexWriter w = new IndexWriter(dir, createIndexWriterConfig())) { + int numdocs = 2000; Review comment: `atLeast(1000)` will randomize the number of docs ########## File path: lucene/core/src/test/org/apache/lucene/index/TestVectorValues.java ########## @@ -815,4 +816,47 @@ public void testSearchStrategyIdentifiers() { assertEquals(2, VectorValues.SearchStrategy.DOT_PRODUCT_HNSW.ordinal()); assertEquals(3, VectorValues.SearchStrategy.values().length); } + + public void testAdvance() throws Exception { + try (Directory dir = newDirectory()) { + try (IndexWriter w = new IndexWriter(dir, createIndexWriterConfig())) { + int numdocs = 2000; + String fieldName = "field"; + for (int i = 0; i < numdocs; i++) { + Document doc = new Document(); + // randomly add a vector field + if (random().nextInt(4) == 3) { + doc.add( + new VectorField( + fieldName, new float[4], VectorValues.SearchStrategy.DOT_PRODUCT_HNSW)); + } + w.addDocument(doc); + } + w.forceMerge(1); + try (IndexReader reader = w.getReader()) { + LeafReader r = getOnlyLeafReader(reader); + VectorValues vectorValues = r.getVectorValues(fieldName); + TreeSet<Integer> vectorDocs = new TreeSet<>(); Review comment: could we store the values in an `int[]` here? They are guaranteed to be returned in increasing order by `nextDoc` (although asserting that is so would be good). Then below we can maintain an index into the array and advance by one to get the next expected docid. ########## File path: lucene/core/src/test/org/apache/lucene/index/TestVectorValues.java ########## @@ -815,4 +816,47 @@ public void testSearchStrategyIdentifiers() { assertEquals(2, VectorValues.SearchStrategy.DOT_PRODUCT_HNSW.ordinal()); assertEquals(3, VectorValues.SearchStrategy.values().length); } + + public void testAdvance() throws Exception { + try (Directory dir = newDirectory()) { + try (IndexWriter w = new IndexWriter(dir, createIndexWriterConfig())) { + int numdocs = 2000; + String fieldName = "field"; + for (int i = 0; i < numdocs; i++) { + Document doc = new Document(); + // randomly add a vector field + if (random().nextInt(4) == 3) { + doc.add( + new VectorField( + fieldName, new float[4], VectorValues.SearchStrategy.DOT_PRODUCT_HNSW)); + } + w.addDocument(doc); + } + w.forceMerge(1); + try (IndexReader reader = w.getReader()) { + LeafReader r = getOnlyLeafReader(reader); + VectorValues vectorValues = r.getVectorValues(fieldName); + TreeSet<Integer> vectorDocs = new TreeSet<>(); + int cur = -1; + while (cur != NO_MORE_DOCS) { + cur = vectorValues.nextDoc(); + vectorDocs.add(cur); + } + vectorValues = r.getVectorValues(fieldName); + for (int i = 0; i != NO_MORE_DOCS && i < numdocs; i++) { + // randomly advance to i + if (random().nextInt(4) == 3) { + vectorValues.advance(i); + assertEquals((int) vectorDocs.higher(i - 1), vectorValues.docID()); + if (vectorValues.docID() == NO_MORE_DOCS) { + break; + } + // ensure i is always greater than vectorValues.docID() + i = vectorValues.docID(); Review comment: The comment above is confusing since i is manifestly *not* greater than vectorValues.docID() , it's equal! ########## File path: lucene/core/src/test/org/apache/lucene/index/TestVectorValues.java ########## @@ -815,4 +816,47 @@ public void testSearchStrategyIdentifiers() { assertEquals(2, VectorValues.SearchStrategy.DOT_PRODUCT_HNSW.ordinal()); assertEquals(3, VectorValues.SearchStrategy.values().length); } + + public void testAdvance() throws Exception { + try (Directory dir = newDirectory()) { + try (IndexWriter w = new IndexWriter(dir, createIndexWriterConfig())) { + int numdocs = 2000; + String fieldName = "field"; + for (int i = 0; i < numdocs; i++) { + Document doc = new Document(); + // randomly add a vector field + if (random().nextInt(4) == 3) { + doc.add( + new VectorField( + fieldName, new float[4], VectorValues.SearchStrategy.DOT_PRODUCT_HNSW)); + } + w.addDocument(doc); + } + w.forceMerge(1); + try (IndexReader reader = w.getReader()) { + LeafReader r = getOnlyLeafReader(reader); + VectorValues vectorValues = r.getVectorValues(fieldName); + TreeSet<Integer> vectorDocs = new TreeSet<>(); + int cur = -1; + while (cur != NO_MORE_DOCS) { + cur = vectorValues.nextDoc(); + vectorDocs.add(cur); + } + vectorValues = r.getVectorValues(fieldName); + for (int i = 0; i != NO_MORE_DOCS && i < numdocs; i++) { + // randomly advance to i + if (random().nextInt(4) == 3) { + vectorValues.advance(i); Review comment: let's assert that the return value of `advance` is what we expect it to be ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org