Skip to content

[Optimization] Add ordered(false) bulk insert to Java agent sample #61

@diberry

Description

@diberry

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:

  1. Add \InsertManyOptions\ with \ordered(false)\ for parallel execution
  2. Wrap \insertMany()\ in try/catch for \MongoBulkWriteException\
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestsquadSquad managed issuesquad:bobbieAssigned to Bobbie (Java engineer)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions