-
Notifications
You must be signed in to change notification settings - Fork 1.3k
CSHARP-5717: Typed builders for vector indexes #1795
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 implements typed builders for creating vector indexes in MongoDB Atlas, providing a strongly-typed C# API as an alternative to manually constructing BsonDocument definitions. The changes introduce new enums for vector similarity and quantization, a base class for index models, and a generic CreateVectorIndexModel<TDocument>
class that leverages C# expressions for field selection.
Key changes:
- Adds
VectorSimilarity
andVectorQuantization
enums to represent vector search configuration options - Introduces
CreateSearchIndexModelBase
abstract class and refactorsCreateSearchIndexModel
to inherit from it - Implements
CreateVectorIndexModel<TDocument>
for type-safe vector index creation with support for filter fields and HNSW options
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
src/MongoDB.Driver/VectorSimilarity.cs | Defines enum for vector similarity functions (Euclidean, Cosine, DotProduct) |
src/MongoDB.Driver/VectorQuantization.cs | Defines enum for vector quantization types (None, Scalar, Binary) |
src/MongoDB.Driver/CreateSearchIndexModelBase.cs | Introduces abstract base class for search index models |
src/MongoDB.Driver/CreateSearchIndexModel.cs | Refactors to inherit from base class and updates documentation |
src/MongoDB.Driver/CreateVectorIndexModel.cs | Implements typed vector index model with field expressions and rendering logic |
src/MongoDB.Driver/Search/IMongoSearchIndexManager.cs | Updates interface to accept base class type |
src/MongoDB.Driver/MongoCollectionImpl.cs | Updates implementation to handle both search and vector index models |
tests/MongoDB.Driver.Tests/Search/AtlasSearchIndexManagmentTests.cs | Adds comprehensive tests for typed vector index API and updates existing tests |
evergreen/evergreen.yml | Updates MongoDB version from 7.0 to 8.0 for search index tests |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
@rstam This is a new implementation which, I think, does the rendering properly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two minor questions/suggestions.
/// <summary> | ||
/// Defines a vector index model using strongly-typed C# APIs. | ||
/// </summary> | ||
public sealed class CreateVectorIndexModel<TDocument> : CreateSearchIndexModel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, but should this class be named CreateVectorSearchIndexModel
?
The server calls this type of index a "vector search index"?
} | ||
} | ||
|
||
return new BsonDocument { { "fields", BsonArray.Create(fieldDocuments) } }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would use new BsonArray(fieldDocuments)
instead of BsonArray.Create(fieldDocuments)
.
BsonArray.Create
takes a single object
parameter and does all sorts of weird obsolete mappings.
Replaces #1769