Add typed builder API for vector search index definitions#1960
Merged
Conversation
e088d3c to
77460ff
Compare
5f0919d to
2c77a75
Compare
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
strogiyotec
approved these changes
May 20, 2026
|
|
||
| VectorSearchIndexDefinition(final List<? extends Bson> fields) { | ||
| doesNotContainNull("fields", notNull("fields", fields)); | ||
| this.fields = new ArrayList<>(fields); |
Contributor
There was a problem hiding this comment.
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()
Member
Author
There was a problem hiding this comment.
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(); |
Contributor
There was a problem hiding this comment.
NIT: we already know the size for this array , let's use another constructor
new BsonArray(this.fields.size())
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add typed builder API for vector search index definitions
Introduced
SearchIndexDefinitionsealed interface with factory methods,VectorSearchIndexFields(vectorField,filterField,autoEmbedFieldbuilders),HnswSearchIndexOptionsfor HNSW-specific parameters, andVectorSearchIndexDefinitionas the concrete implementation.Added Scala companion objects for
SearchIndexDefinitionandVectorSearchIndexFieldswith delegating factory methods, and aSearchIndexModel.applyoverload forVectorSearchIndexDefinition.Annotated mutable builders with
@NotThreadSafe. Added fail-fastnull-element validation using notNullElements in factory methods.
Includes unit tests (Java) and spec tests (Scala).
JAVA-6112
JAVA-6099