Skip to content

Add typed builder API for vector search index definitions#1960

Merged
rozza merged 4 commits into
mongodb:mainfrom
rozza:JAVA-6112
May 20, 2026
Merged

Add typed builder API for vector search index definitions#1960
rozza merged 4 commits into
mongodb:mainfrom
rozza:JAVA-6112

Conversation

@rozza
Copy link
Copy Markdown
Member

@rozza rozza commented May 5, 2026

Add typed builder API for vector search index definitions

Introduced SearchIndexDefinition sealed interface with factory methods,
VectorSearchIndexFields (vectorField, filterField, autoEmbedField builders),
HnswSearchIndexOptions for HNSW-specific parameters, and
VectorSearchIndexDefinition as the concrete implementation.

Added Scala companion objects for SearchIndexDefinition and
VectorSearchIndexFields with delegating factory methods, and a
SearchIndexModel.apply overload for VectorSearchIndexDefinition.

Annotated mutable builders with @NotThreadSafe. Added fail-fast
null-element validation using notNullElements in factory methods.

Includes unit tests (Java) and spec tests (Scala).

JAVA-6112
JAVA-6099

This comment was marked as outdated.

This comment was marked as outdated.

@rozza rozza force-pushed the JAVA-6112 branch 3 times, most recently from e088d3c to 77460ff Compare May 6, 2026 10:07
@rozza rozza requested a review from Copilot May 6, 2026 10:08

This comment was marked as outdated.

@rozza rozza force-pushed the JAVA-6112 branch 2 times, most recently from 5f0919d to 2c77a75 Compare May 6, 2026 10:46
@rozza rozza marked this pull request as ready for review May 6, 2026 11:32
@rozza rozza requested a review from a team as a code owner May 6, 2026 11:32
@rozza rozza requested a review from vbabanin May 6, 2026 11:32
@nhachicha nhachicha requested a review from Copilot May 6, 2026 12:23

This comment was marked as outdated.

This comment was marked as outdated.

Introduced SearchIndexDefinition sealed interface with factory methods,
VectorSearchIndexFields (vectorField, filterField, autoEmbedField builders),
HnswSearchIndexOptions for HNSW-specific parameters, and
VectorSearchIndexDefinition as the concrete implementation.

Added Scala companion objects for SearchIndexDefinition and
VectorSearchIndexFields with delegating factory methods, and a
SearchIndexModel.apply overload for VectorSearchIndexDefinition.

Annotated mutable builders with @NotThreadSafe. Added fail-fast
null-element validation using notNullElements in factory methods.

Includes unit tests (Java) and spec tests (Scala).

JAVA-6112
JAVA-6099
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

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

Comment thread driver-core/src/main/com/mongodb/client/model/VectorSearchIndexFields.java Outdated
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

Copilot reviewed 12 out of 12 changed files in this pull request and generated no new comments.


VectorSearchIndexDefinition(final List<? extends Bson> fields) {
doesNotContainNull("fields", notNull("fields", fields));
this.fields = new ArrayList<>(fields);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NIT: does this list have to be mutable ? I can only see it being used in toBsonDocument if the intention was to make a fresh copy that can't by modified through the fields list passed in constructor let's use
List.of()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

List.of will be usable in the future once we drop Java 8 :)


@Override
public <TDocument> BsonDocument toBsonDocument(final Class<TDocument> documentClass, final CodecRegistry codecRegistry) {
BsonArray fieldArray = new BsonArray();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

NIT: we already know the size for this array , let's use another constructor
new BsonArray(this.fields.size())

@rozza rozza merged commit a50345f into mongodb:main May 20, 2026
53 checks passed
@rozza rozza deleted the JAVA-6112 branch May 20, 2026 08:44
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.

3 participants