Skip to content

Commit 5e486cb

Browse files
committed
Removed binary break.
1 parent 79a8b6a commit 5e486cb

File tree

6 files changed

+78
-103
lines changed

6 files changed

+78
-103
lines changed

src/MongoDB.Driver/CreateSearchIndexModel.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,19 @@ namespace MongoDB.Driver
2121
/// Defines a vector search index model using a <see cref="BsonDocument"/> definition. Consider using
2222
/// <see cref="CreateVectorIndexModel{TDocument}"/> to build Atlas indexes without specifying the BSON directly.
2323
/// </summary>
24-
public sealed class CreateSearchIndexModel : CreateSearchIndexModelBase
24+
public class CreateSearchIndexModel
2525
{
26+
/// <summary>Gets the index name.</summary>
27+
/// <value>The index name.</value>
28+
public string Name { get; }
29+
2630
/// <summary>Gets the index type.</summary>
2731
/// <value>The index type.</value>
28-
public override SearchIndexType? Type { get; }
32+
public SearchIndexType? Type { get; }
2933

3034
/// <summary>Gets the index definition.</summary>
3135
/// <value>The definition.</value>
32-
public BsonDocument Definition { get; }
36+
public virtual BsonDocument Definition { get; }
3337

3438
/// <summary>
3539
/// Initializes a new instance of the <see cref="CreateSearchIndexModel"/> class, passing the index
@@ -58,10 +62,22 @@ public CreateSearchIndexModel(string name, BsonDocument definition)
5862
/// <param name="type">The index type.</param>
5963
/// <param name="definition">The index definition.</param>
6064
public CreateSearchIndexModel(string name, SearchIndexType? type, BsonDocument definition)
61-
: base(name)
6265
{
66+
Name = name;
6367
Type = type;
6468
Definition = definition;
69+
70+
}
71+
72+
/// <summary>
73+
/// Initializes a new instance of the <see cref="CreateSearchIndexModel"/> class.
74+
/// </summary>
75+
/// <param name="name">The index name.</param>
76+
/// <param name="type">The index type.</param>
77+
protected CreateSearchIndexModel(string name, SearchIndexType? type)
78+
{
79+
Name = name;
80+
Type = type;
6581
}
6682
}
6783
}

src/MongoDB.Driver/CreateSearchIndexModelBase.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/MongoDB.Driver/CreateVectorIndexModel.cs

Lines changed: 45 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,51 @@ namespace MongoDB.Driver;
2424
/// <summary>
2525
/// Defines a vector index model using strongly-typed C# APIs.
2626
/// </summary>
27-
public sealed class CreateVectorIndexModel<TDocument> : CreateSearchIndexModelBase
27+
public sealed class CreateVectorIndexModel<TDocument> : CreateSearchIndexModel
2828
{
29+
/// <summary>
30+
/// The field containing the vectors to index.
31+
/// </summary>
32+
public FieldDefinition<TDocument> Field { get; }
33+
34+
/// <summary>
35+
/// The <see cref="VectorSimilarity"/> to use to search for top K-nearest neighbors.
36+
/// </summary>
37+
public VectorSimilarity Similarity { get; }
38+
39+
/// <summary>
40+
/// Number of vector dimensions that vector search enforces at index-time and query-time.
41+
/// </summary>
42+
public int Dimensions { get; }
43+
44+
/// <summary>
45+
/// Fields that may be used as filters in the vector query.
46+
/// </summary>
47+
public IReadOnlyList<FieldDefinition<TDocument>> FilterFields { get; }
48+
49+
/// <summary>
50+
/// Type of automatic vector quantization for your vectors.
51+
/// </summary>
52+
public VectorQuantization? Quantization { get; init; }
53+
54+
/// <summary>
55+
/// Maximum number of edges (or connections) that a node can have in the Hierarchical Navigable Small Worlds graph.
56+
/// </summary>
57+
public int? HnswMaxEdges { get; init; }
58+
59+
/// <summary>
60+
/// Analogous to numCandidates at query-time, this parameter controls the maximum number of nodes to evaluate to find the closest neighbors to connect to a new node.
61+
/// </summary>
62+
public int? HnswNumEdgeCandidates { get; init; }
63+
64+
/// <summary>
65+
/// This method should not be called on this subtype. Instead, call <see cref="Render"/> to create a BSON
66+
/// document for the index model.
67+
/// </summary>
68+
public override BsonDocument Definition
69+
=> throw new NotSupportedException(
70+
"This method should not be called on this subtype. Instead, call 'Render' to create a BSON document for the index model.");
71+
2972
/// <summary>
3073
/// Initializes a new instance of the <see cref="CreateVectorIndexModel{TDocument}"/> class, passing the
3174
/// required options for <see cref="VectorSimilarity"/> and the number of vector dimensions to the constructor.
@@ -41,7 +84,7 @@ public CreateVectorIndexModel(
4184
VectorSimilarity similarity,
4285
int dimensions,
4386
params FieldDefinition<TDocument>[] filterFields)
44-
: base(name)
87+
: base(name, SearchIndexType.VectorSearch)
4588
{
4689
Field = field;
4790
Similarity = similarity;
@@ -75,44 +118,6 @@ public CreateVectorIndexModel(
75118
{
76119
}
77120

78-
/// <summary>
79-
/// The field containing the vectors to index.
80-
/// </summary>
81-
public FieldDefinition<TDocument> Field { get; }
82-
83-
/// <summary>
84-
/// The <see cref="VectorSimilarity"/> to use to search for top K-nearest neighbors.
85-
/// </summary>
86-
public VectorSimilarity Similarity { get; }
87-
88-
/// <summary>
89-
/// Number of vector dimensions that vector search enforces at index-time and query-time.
90-
/// </summary>
91-
public int Dimensions { get; }
92-
93-
/// <summary>
94-
/// Fields that may be used as filters in the vector query.
95-
/// </summary>
96-
public IReadOnlyList<FieldDefinition<TDocument>> FilterFields { get; }
97-
98-
/// <summary>
99-
/// Type of automatic vector quantization for your vectors.
100-
/// </summary>
101-
public VectorQuantization? Quantization { get; init; }
102-
103-
/// <summary>
104-
/// Maximum number of edges (or connections) that a node can have in the Hierarchical Navigable Small Worlds graph.
105-
/// </summary>
106-
public int? HnswMaxEdges { get; init; }
107-
108-
/// <summary>
109-
/// Analogous to numCandidates at query-time, this parameter controls the maximum number of nodes to evaluate to find the closest neighbors to connect to a new node.
110-
/// </summary>
111-
public int? HnswNumEdgeCandidates { get; init; }
112-
113-
/// <inheritdoc/>
114-
public override SearchIndexType? Type => SearchIndexType.VectorSearch;
115-
116121
/// <summary>
117122
/// Renders the index model to a <see cref="BsonDocument"/>.
118123
/// </summary>

src/MongoDB.Driver/MongoCollectionImpl.cs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ public MongoSearchIndexManager(MongoCollectionImpl<TDocument> collection)
16551655
_collection = Ensure.IsNotNull(collection, nameof(collection));
16561656
}
16571657

1658-
public IEnumerable<string> CreateMany(IEnumerable<CreateSearchIndexModelBase> models, CancellationToken cancellationToken = default)
1658+
public IEnumerable<string> CreateMany(IEnumerable<CreateSearchIndexModel> models, CancellationToken cancellationToken = default)
16591659
{
16601660
using var session = _collection._operationExecutor.StartImplicitSession();
16611661
var operation = CreateCreateIndexesOperation(models);
@@ -1664,7 +1664,7 @@ public IEnumerable<string> CreateMany(IEnumerable<CreateSearchIndexModelBase> mo
16641664
return GetIndexNames(result);
16651665
}
16661666

1667-
public async Task<IEnumerable<string>> CreateManyAsync(IEnumerable<CreateSearchIndexModelBase> models, CancellationToken cancellationToken = default)
1667+
public async Task<IEnumerable<string>> CreateManyAsync(IEnumerable<CreateSearchIndexModel> models, CancellationToken cancellationToken = default)
16681668
{
16691669
using var session = _collection._operationExecutor.StartImplicitSession();
16701670
var operation = CreateCreateIndexesOperation(models);
@@ -1676,7 +1676,7 @@ public async Task<IEnumerable<string>> CreateManyAsync(IEnumerable<CreateSearchI
16761676
public string CreateOne(BsonDocument definition, string name = null, CancellationToken cancellationToken = default) =>
16771677
CreateOne(new CreateSearchIndexModel(name, definition), cancellationToken);
16781678

1679-
public string CreateOne(CreateSearchIndexModelBase model, CancellationToken cancellationToken = default)
1679+
public string CreateOne(CreateSearchIndexModel model, CancellationToken cancellationToken = default)
16801680
{
16811681
var result = CreateMany(new[] { model }, cancellationToken);
16821682
return result.Single();
@@ -1685,7 +1685,7 @@ public string CreateOne(CreateSearchIndexModelBase model, CancellationToken canc
16851685
public Task<string> CreateOneAsync(BsonDocument definition, string name = null, CancellationToken cancellationToken = default) =>
16861686
CreateOneAsync(new CreateSearchIndexModel(name, definition), cancellationToken);
16871687

1688-
public async Task<string> CreateOneAsync(CreateSearchIndexModelBase model, CancellationToken cancellationToken = default)
1688+
public async Task<string> CreateOneAsync(CreateSearchIndexModel model, CancellationToken cancellationToken = default)
16891689
{
16901690
var result = await CreateManyAsync(new[] { model }, cancellationToken).ConfigureAwait(false);
16911691
return result.Single();
@@ -1742,7 +1742,7 @@ private PipelineDefinition<TDocument, BsonDocument> CreateListIndexesStage(strin
17421742
}
17431743

17441744
private CreateSearchIndexesOperation CreateCreateIndexesOperation(
1745-
IEnumerable<CreateSearchIndexModelBase> models)
1745+
IEnumerable<CreateSearchIndexModel> models)
17461746
{
17471747
var renderArgs = _collection.GetRenderArgs();
17481748

@@ -1752,15 +1752,9 @@ private CreateSearchIndexesOperation CreateCreateIndexesOperation(
17521752
=> new CreateSearchIndexRequest(
17531753
model.Name,
17541754
model.Type,
1755-
model switch
1756-
{
1757-
CreateSearchIndexModel createSearchIndexModel
1758-
=> createSearchIndexModel.Definition,
1759-
CreateVectorIndexModel<TDocument> createAtlasVectorIndexModel
1760-
=> createAtlasVectorIndexModel.Render(renderArgs),
1761-
_ => throw new NotSupportedException(
1762-
$"'{model.GetType().Name}' is not a supported index model type.")
1763-
})),
1755+
model is CreateVectorIndexModel<TDocument> createVectorIndexModel
1756+
? createVectorIndexModel.Render(renderArgs)
1757+
: model.Definition)),
17641758
_collection._messageEncoderSettings);
17651759
}
17661760

src/MongoDB.Driver/Search/IMongoSearchIndexManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public interface IMongoSearchIndexManager
3333
/// <returns>
3434
/// An <see cref="IEnumerable{String}" /> of the names of the indexes that were created.
3535
/// </returns>
36-
IEnumerable<string> CreateMany(IEnumerable<CreateSearchIndexModelBase> models, CancellationToken cancellationToken = default);
36+
IEnumerable<string> CreateMany(IEnumerable<CreateSearchIndexModel> models, CancellationToken cancellationToken = default);
3737

3838
/// <summary>
3939
/// Creates multiple indexes.
@@ -43,7 +43,7 @@ public interface IMongoSearchIndexManager
4343
/// <returns>
4444
/// A Task whose result is an <see cref="IEnumerable{String}" /> of the names of the indexes that were created.
4545
/// </returns>
46-
Task<IEnumerable<string>> CreateManyAsync(IEnumerable<CreateSearchIndexModelBase> models, CancellationToken cancellationToken = default);
46+
Task<IEnumerable<string>> CreateManyAsync(IEnumerable<CreateSearchIndexModel> models, CancellationToken cancellationToken = default);
4747

4848
/// <summary>
4949
/// Creates a search index.
@@ -64,7 +64,7 @@ public interface IMongoSearchIndexManager
6464
/// <returns>
6565
/// The name of the index that was created.
6666
/// </returns>
67-
string CreateOne(CreateSearchIndexModelBase model, CancellationToken cancellationToken = default);
67+
string CreateOne(CreateSearchIndexModel model, CancellationToken cancellationToken = default);
6868

6969
/// <summary>
7070
/// Creates a search index.
@@ -85,7 +85,7 @@ public interface IMongoSearchIndexManager
8585
/// <returns>
8686
/// A Task whose result is the name of the index that was created.
8787
/// </returns>
88-
Task<string> CreateOneAsync(CreateSearchIndexModelBase model, CancellationToken cancellationToken = default);
88+
Task<string> CreateOneAsync(CreateSearchIndexModel model, CancellationToken cancellationToken = default);
8989

9090
/// <summary>
9191
/// Drops an index by its name.

src/MongoDB.Driver/VectorSimilarity.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public enum VectorSimilarity
3333
Cosine,
3434

3535
/// <summary>
36-
/// mMasures similarity like cosine, but takes into account the magnitude of the vector.
36+
/// Measures similarity like cosine, but takes into account the magnitude of the vector.
3737
/// </summary>
3838
DotProduct,
3939
}

0 commit comments

Comments
 (0)