-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add ParquetDenseVectorCollection tests using parquet-floor
We created a test class for ParquetDenseVectorCollection that extends DocumentCollectionTest. Instead of creating new test files, we utilized an existing Parquet test file containing BGE embeddings. Replaces Hadoop dependencies with parquet-floor for: reduced dependency footprint, simplified Parquet file handling, removal of complex Hadoop configuration. Tests verify: basic Parquet file reading functionality, document iteration and content validation, integration with existing BGE embedding test data.
- Loading branch information
Vincent Zhong
committed
Dec 23, 2024
1 parent
6a9cacf
commit ae57dcb
Showing
2 changed files
with
77 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/test/java/io/anserini/collection/ParquetDenseVectorCollectionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Tests for the ParquetDenseVectorCollection class which handles dense vector embeddings stored in Parquet format. | ||
* This test suite verifies the collection's ability to read and process Parquet files containing vector embeddings | ||
* using the parquet-floor library instead of Hadoop dependencies. | ||
*/ | ||
package io.anserini.collection; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class ParquetDenseVectorCollectionTest extends DocumentCollectionTest<ParquetDenseVectorCollection.Document> { | ||
@Before | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
} | ||
|
||
/* | ||
* Verifies that a document's properties match expected values. | ||
* This implementation focuses on three key aspects: | ||
* 1. Document can be indexed | ||
* 2. Document ID matches expected value | ||
* 3. Document's vector content is present | ||
*/ | ||
@Override | ||
void checkDocument(SourceDocument doc, Map<String, String> expected) { | ||
assertTrue(doc.indexable()); | ||
assertEquals(expected.get("id"), doc.id()); | ||
assertTrue(doc.contents().contains(expected.get("vector"))); | ||
} | ||
|
||
/* | ||
* Tests the collection's ability to read and iterate over documents in a Parquet file. | ||
* Uses a pre-existing test file containing BGE embeddings from MS MARCO passages. | ||
* Verifies that: | ||
* 1. Documents can be read from the Parquet file | ||
* 2. Each document has a valid ID | ||
* 3. The collection contains the expected number of documents | ||
*/ | ||
@Test | ||
public void testSegment() throws IOException { | ||
Path path = Paths.get("src/test/resources/sample_docs/parquet/msmarco-passage-bge-base-en-v1.5.parquet"); | ||
ParquetDenseVectorCollection collection = new ParquetDenseVectorCollection(path); | ||
|
||
AtomicInteger cnt = new AtomicInteger(); | ||
Map<String, Integer> docIds = new HashMap<>(); | ||
|
||
for (FileSegment<ParquetDenseVectorCollection.Document> segment : collection) { | ||
for (ParquetDenseVectorCollection.Document doc : segment) { | ||
docIds.put(doc.id(), cnt.incrementAndGet()); | ||
} | ||
} | ||
|
||
assertTrue("Collection should contain documents", docIds.size() > 0); | ||
for (String docId : docIds.keySet()) { | ||
assertTrue("Document ID should not be empty", docId != null && !docId.isEmpty()); | ||
} | ||
} | ||
} |