Summary
Apply \ordered(false)\ + \MongoBulkWriteException\ handling to the Java vector search samples (\HNSW.java, \IVF.java, \DiskAnn.java), matching the bulk insert patterns already used by Python, TypeScript, .NET, and Go samples.
What to change
In each Java sample's \insertDataInBatches\ method:
- Add \InsertManyOptions\ with \ordered(false)\ for parallel execution
- Wrap \insertMany()\ in try/catch for \MongoBulkWriteException\
- Track and log partial successes (inserted vs failed counts)
Pattern to follow (from existing TypeScript sample):
\\ ypescript
const result = await collection.insertMany(batch, { ordered: false });
\\
Java equivalent:
\\java
var insertOptions = new InsertManyOptions().ordered(false);
try {
collection.insertMany(documents, insertOptions);
totalInserted += documents.size();
} catch (MongoBulkWriteException e) {
var inserted = documents.size() - e.getWriteErrors().size();
totalInserted += inserted;
totalFailed += e.getWriteErrors().size();
}
\\
Files to modify
- \�i/vector-search-java/src/main/java/com/azure/documentdb/samples/HNSW.java\
- \�i/vector-search-java/src/main/java/com/azure/documentdb/samples/IVF.java\
- \�i/vector-search-java/src/main/java/com/azure/documentdb/samples/DiskAnn.java\
Background
Summary
Apply \ordered(false)\ + \MongoBulkWriteException\ handling to the Java vector search samples (\HNSW.java, \IVF.java, \DiskAnn.java), matching the bulk insert patterns already used by Python, TypeScript, .NET, and Go samples.
What to change
In each Java sample's \insertDataInBatches\ method:
Pattern to follow (from existing TypeScript sample):
\\ ypescript
const result = await collection.insertMany(batch, { ordered: false });
\\
Java equivalent:
\\java
var insertOptions = new InsertManyOptions().ordered(false);
try {
collection.insertMany(documents, insertOptions);
totalInserted += documents.size();
} catch (MongoBulkWriteException e) {
var inserted = documents.size() - e.getWriteErrors().size();
totalInserted += inserted;
totalFailed += e.getWriteErrors().size();
}
\\
Files to modify
Background