Skip to content

Add typed builder API for vector search index definitions#1960

Draft
rozza wants to merge 1 commit intomongodb:mainfrom
rozza:JAVA-6112
Draft

Add typed builder API for vector search index definitions#1960
rozza wants to merge 1 commit intomongodb:mainfrom
rozza:JAVA-6112

Conversation

@rozza
Copy link
Copy Markdown
Member

@rozza rozza commented May 5, 2026

  • Introduced SearchIndexDefinition sealed interface with factory methods,
  • VectorSearchIndexFields (vectorField, filterField, autoEmbedField builders),
  • HnswSearchIndexOptions for HNSW-specific parameters, and
  • VectorSearchIndexDefinition as the concrete implementation. Updates
  • Updated SearchIndexModel javadoc to reference the new builders.

JAVA-6112

* Introduced SearchIndexDefinition sealed interface with factory methods,
* VectorSearchIndexFields (vectorField, filterField, autoEmbedField builders),
* HnswSearchIndexOptions for HNSW-specific parameters, and
* VectorSearchIndexDefinition as the concrete implementation. Updates
* Updated SearchIndexModel javadoc to reference the new builders.

JAVA-6112
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a typed Java builder API for creating Atlas Vector Search index definitions (and supporting options), and wires the new public types into the Scala driver surface area. It also adds unit tests validating the BSON produced by the new builders.

Changes:

  • Added SearchIndexDefinition with vectorSearch(...) factory methods and a concrete VectorSearchIndexDefinition implementation.
  • Added VectorSearchIndexFields builders (vector/filter/auto-embed fields) and HnswSearchIndexOptions for HNSW parameters.
  • Updated SearchIndexModel Javadoc and added unit tests covering common definition shapes and BSON output.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
driver-scala/src/main/scala/org/mongodb/scala/model/package.scala Exposes new Java model types to Scala via type aliases.
driver-core/src/test/unit/com/mongodb/client/model/SearchIndexDefinitionTest.java Adds unit tests asserting BSON output for the new vector index definition builders.
driver-core/src/main/com/mongodb/client/model/VectorSearchIndexFields.java Introduces fluent builders for vector search index field definitions.
driver-core/src/main/com/mongodb/client/model/VectorSearchIndexDefinition.java Implements a SearchIndexDefinition producing { fields: [...] }.
driver-core/src/main/com/mongodb/client/model/SearchIndexModel.java Updates Javadoc to reference the new vector index definition builders.
driver-core/src/main/com/mongodb/client/model/SearchIndexDefinition.java Adds a sealed interface + factories for typed search index definitions (currently vector search).
driver-core/src/main/com/mongodb/client/model/HnswSearchIndexOptions.java Adds a small fluent builder for HNSW-specific options, implementing Bson.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +484 to +506
/**
* A definition for an Atlas Search index.
* @since 5.8
*/
type SearchIndexDefinition = com.mongodb.client.model.SearchIndexDefinition

/**
* A vector search index definition.
* @since 5.8
*/
type VectorSearchIndexDefinition = com.mongodb.client.model.VectorSearchIndexDefinition

/**
* A factory for defining fields within a vector search index definition.
* @since 5.8
*/
type VectorSearchIndexFields = com.mongodb.client.model.VectorSearchIndexFields

/**
* Options for the HNSW indexing method in a vector search index.
* @since 5.8
*/
type HnswSearchIndexOptions = com.mongodb.client.model.HnswSearchIndexOptions
Comment on lines 24 to 33
/**
* A model describing the creation of a single Atlas Search index.
*
* <p>The {@code definition} parameter accepts any {@link org.bson.conversions.Bson} instance.
* For vector search indexes, use the builders provided by {@link SearchIndexDefinition#vectorSearch(Bson...)}
* and {@link VectorSearchIndexFields} to construct the definition.</p>
*
* @see SearchIndexDefinition
* @see VectorSearchIndexFields
* @since 4.11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants