diff --git a/src/MongoDB.Driver.Core/Core/Misc/Ensure.cs b/src/MongoDB.Driver.Core/Core/Misc/Ensure.cs
index 10560a1cbd7..44146b42cc6 100644
--- a/src/MongoDB.Driver.Core/Core/Misc/Ensure.cs
+++ b/src/MongoDB.Driver.Core/Core/Misc/Ensure.cs
@@ -267,6 +267,34 @@ public static string IsNotNullOrEmpty(string value, string paramName)
return value;
}
+ ///
+ /// Ensures that the value of a parameter is not null or empty.
+ ///
+ /// The value of the parameter.
+ /// The name of the parameter.
+ /// The value of the parameter.
+ public static IEnumerable IsNotNullOrEmpty(IEnumerable value, string paramName)
+ {
+ if (value == null)
+ {
+ throw new ArgumentNullException(paramName);
+ }
+
+ if (value is ICollection collection)
+ {
+ if (collection.Count == 0)
+ {
+ throw new ArgumentException("Value cannot be empty.", paramName);
+ }
+ }
+ else if (!value.Any())
+ {
+ throw new ArgumentException("Value cannot be empty.", paramName);
+ }
+
+ return value;
+ }
+
///
/// Ensures that the value of a parameter is null.
///
diff --git a/src/MongoDB.Driver/AggregateFluent.cs b/src/MongoDB.Driver/AggregateFluent.cs
index ea1c6020fb3..75b53d2f1a2 100644
--- a/src/MongoDB.Driver/AggregateFluent.cs
+++ b/src/MongoDB.Driver/AggregateFluent.cs
@@ -346,6 +346,15 @@ public override IAggregateFluent Unwind(FieldDefinition<
return WithPipeline(_pipeline.Unwind(field, options));
}
+ public override IAggregateFluent VectorSearch(
+ FieldDefinition field,
+ QueryVector queryVector,
+ int limit,
+ VectorSearchOptions options = null)
+ {
+ return WithPipeline(_pipeline.VectorSearch(field, queryVector, limit, options));
+ }
+
public override string ToString()
{
var linqProvider = Database.Client.Settings.LinqProvider;
diff --git a/src/MongoDB.Driver/AggregateFluentBase.cs b/src/MongoDB.Driver/AggregateFluentBase.cs
index fe584da27c6..b0619e4e633 100644
--- a/src/MongoDB.Driver/AggregateFluentBase.cs
+++ b/src/MongoDB.Driver/AggregateFluentBase.cs
@@ -307,6 +307,16 @@ public virtual IAggregateFluent Unwind(FieldDefinition
+ public virtual IAggregateFluent VectorSearch(
+ FieldDefinition field,
+ QueryVector queryVector,
+ int limit,
+ VectorSearchOptions options = null)
+ {
+ throw new NotImplementedException();
+ }
+
///
public virtual void ToCollection(CancellationToken cancellationToken)
{
diff --git a/src/MongoDB.Driver/IAggregateFluent.cs b/src/MongoDB.Driver/IAggregateFluent.cs
index fb13c35d742..8ad1ba38a0f 100644
--- a/src/MongoDB.Driver/IAggregateFluent.cs
+++ b/src/MongoDB.Driver/IAggregateFluent.cs
@@ -501,6 +501,20 @@ IAggregateFluent UnionWith(
/// The options.
/// The fluent aggregate interface.
IAggregateFluent Unwind(FieldDefinition field, AggregateUnwindOptions options = null);
+
+ ///
+ /// Appends a vector search stage.
+ ///
+ /// The field.
+ /// The query vector.
+ /// The limit.
+ /// The vector search options.
+ /// The fluent aggregate interface.
+ IAggregateFluent VectorSearch(
+ FieldDefinition field,
+ QueryVector queryVector,
+ int limit,
+ VectorSearchOptions options = null);
}
///
diff --git a/src/MongoDB.Driver/IAggregateFluentExtensions.cs b/src/MongoDB.Driver/IAggregateFluentExtensions.cs
index 9de9d7fe320..ac9a9b0b2a3 100644
--- a/src/MongoDB.Driver/IAggregateFluentExtensions.cs
+++ b/src/MongoDB.Driver/IAggregateFluentExtensions.cs
@@ -967,5 +967,27 @@ public static IAggregateFluent Unwind(this IAgg
return IAsyncCursorSourceExtensions.SingleOrDefaultAsync(aggregate.Limit(2), cancellationToken);
}
+
+ ///
+ /// Appends a $vectorSearch stage.
+ ///
+ /// The type of the result.
+ /// The aggregate.
+ /// The field.
+ /// The query vector.
+ /// The limit.
+ /// The vector search options.
+ /// The fluent aggregate interface.
+ public static IAggregateFluent VectorSearch(
+ this IAggregateFluent aggregate,
+ Expression> field,
+ QueryVector queryVector,
+ int limit,
+ VectorSearchOptions options = null)
+ {
+ Ensure.IsNotNull(aggregate, nameof(aggregate));
+
+ return aggregate.VectorSearch(new ExpressionFieldDefinition(field), queryVector, limit, options);
+ }
}
}
diff --git a/src/MongoDB.Driver/Linq/MongoQueryable.cs b/src/MongoDB.Driver/Linq/MongoQueryable.cs
index 229c28050c7..e6bce72c239 100644
--- a/src/MongoDB.Driver/Linq/MongoQueryable.cs
+++ b/src/MongoDB.Driver/Linq/MongoQueryable.cs
@@ -3484,6 +3484,56 @@ public static IOrderedMongoQueryable ThenByDescending(th
return (IOrderedMongoQueryable)Queryable.ThenByDescending(source, keySelector);
}
+ ///
+ /// Appends a $vectorSearch stage to the LINQ pipeline.
+ ///
+ /// The type of the elements of .
+ /// The type of the field.
+ /// A sequence of values.
+ /// The field.
+ /// The query vector.
+ /// The limit.
+ /// The options.
+ ///
+ /// The queryable with a new stage appended.
+ ///
+ public static IMongoQueryable VectorSearch(
+ this IMongoQueryable source,
+ FieldDefinition field,
+ QueryVector queryVector,
+ int limit,
+ VectorSearchOptions options = null)
+ {
+ return AppendStage(
+ source,
+ PipelineStageDefinitionBuilder.VectorSearch(field, queryVector, limit, options));
+ }
+
+ ///
+ /// Appends a $vectorSearch stage to the LINQ pipeline.
+ ///
+ /// The type of the elements of .
+ /// The type of the field.
+ /// A sequence of values.
+ /// The field.
+ /// The query vector.
+ /// The limit.
+ /// The options.
+ ///
+ /// The queryable with a new stage appended.
+ ///
+ public static IMongoQueryable VectorSearch(
+ this IMongoQueryable source,
+ Expression> field,
+ QueryVector queryVector,
+ int limit,
+ VectorSearchOptions options = null)
+ {
+ return AppendStage(
+ source,
+ PipelineStageDefinitionBuilder.VectorSearch(field, queryVector, limit, options));
+ }
+
///
/// Filters a sequence of values based on a predicate.
///
diff --git a/src/MongoDB.Driver/PipelineDefinitionBuilder.cs b/src/MongoDB.Driver/PipelineDefinitionBuilder.cs
index 4cbd27d433f..70e2d3d40fd 100644
--- a/src/MongoDB.Driver/PipelineDefinitionBuilder.cs
+++ b/src/MongoDB.Driver/PipelineDefinitionBuilder.cs
@@ -58,9 +58,7 @@ public static PipelineDefinition AppendStageThe type of the output documents.
/// The pipeline.
/// The output serializer.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition As(
this PipelineDefinition pipeline,
IBsonSerializer outputSerializer = null)
@@ -79,9 +77,7 @@ public static PipelineDefinition AsThe group by expression.
/// The boundaries.
/// The options.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition> Bucket(
this PipelineDefinition pipeline,
AggregateExpressionDefinition groupBy,
@@ -104,9 +100,7 @@ public static PipelineDefinition> BucketThe boundaries.
/// The output projection.
/// The options.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Bucket(
this PipelineDefinition pipeline,
AggregateExpressionDefinition groupBy,
@@ -129,9 +123,7 @@ public static PipelineDefinition BucketThe boundaries.
/// The options.
/// The translation options.
- ///
- /// The fluent aggregate interface.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition> Bucket(
this PipelineDefinition pipeline,
Expression> groupBy,
@@ -156,9 +148,7 @@ public static PipelineDefinition> BucketThe output projection.
/// The options.
/// The translation options.
- ///
- /// The fluent aggregate interface.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Bucket(
this PipelineDefinition pipeline,
Expression> groupBy,
@@ -181,9 +171,7 @@ public static PipelineDefinition BucketThe group by expression.
/// The number of buckets.
/// The options.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition> BucketAuto(
this PipelineDefinition pipeline,
AggregateExpressionDefinition groupBy,
@@ -206,9 +194,7 @@ public static PipelineDefinition> Buck
/// The number of buckets.
/// The output projection.
/// The options.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition BucketAuto(
this PipelineDefinition pipeline,
AggregateExpressionDefinition groupBy,
@@ -231,9 +217,7 @@ public static PipelineDefinition BucketAutoThe number of buckets.
/// The options (optional).
/// The translation options.
- ///
- /// The fluent aggregate interface.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition> BucketAuto(
this PipelineDefinition pipeline,
Expression> groupBy,
@@ -258,9 +242,7 @@ public static PipelineDefinition> Buck
/// The output projection.
/// The options (optional).
/// The translation options.
- ///
- /// The fluent aggregate interface.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition BucketAuto(
this PipelineDefinition pipeline,
Expression> groupBy,
@@ -286,9 +268,7 @@ public static PipelineDefinition BucketAutoThe output projection.
/// The options (optional).
/// The translation options.
- ///
- /// The fluent aggregate interface.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition BucketAutoForLinq2(
this PipelineDefinition pipeline,
Expression> groupBy,
@@ -311,9 +291,7 @@ public static PipelineDefinition BucketAutoForLinq2The type of the intermediate documents.
/// The pipeline.
/// The options.
- ///
- /// The fluent aggregate interface.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition> ChangeStream(
this PipelineDefinition pipeline,
ChangeStreamStageOptions options = null)
@@ -328,9 +306,7 @@ public static PipelineDefinition> Ch
/// The type of the input documents.
/// The type of the intermediate documents.
/// The pipeline.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Count(
this PipelineDefinition pipeline)
{
@@ -347,9 +323,7 @@ public static PipelineDefinition CountThe field.
/// The range.
/// The partition by fields.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Densify(
this PipelineDefinition pipeline,
FieldDefinition field,
@@ -369,9 +343,7 @@ public static PipelineDefinition Densify(
/// The field.
/// The range.
/// The partition by fields.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Densify(
this PipelineDefinition pipeline,
FieldDefinition field,
@@ -391,9 +363,7 @@ public static PipelineDefinition Densify(
/// The field.
/// The range.
/// The partition by fields.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Densify(
this PipelineDefinition pipeline,
Expression> field,
@@ -413,9 +383,7 @@ public static PipelineDefinition Densify(
/// The field.
/// The range.
/// The partition by fields.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Densify(
this PipelineDefinition pipeline,
Expression> field,
@@ -433,9 +401,7 @@ public static PipelineDefinition Densify(
/// The pipeline.
/// The documents.
/// The document serializer.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Documents(
this PipelineDefinition pipeline,
AggregateExpressionDefinition> documents,
@@ -452,9 +418,7 @@ public static PipelineDefinition DocumentsThe pipeline.
/// The documents.
/// The document serializer.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Documents(
this PipelineDefinition pipeline,
IEnumerable documents,
@@ -473,9 +437,7 @@ public static PipelineDefinition DocumentsThe pipeline.
/// The facets.
/// The options.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Facet(
this PipelineDefinition pipeline,
IEnumerable> facets,
@@ -492,9 +454,7 @@ public static PipelineDefinition FacetThe type of the intermediate documents.
/// The pipeline.
/// The facets.
- ///
- /// The fluent aggregate interface.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Facet(
this PipelineDefinition pipeline,
IEnumerable> facets)
@@ -510,9 +470,7 @@ public static PipelineDefinition FacetThe type of the intermediate documents.
/// The pipeline.
/// The facets.
- ///
- /// The fluent aggregate interface.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Facet(
this PipelineDefinition pipeline,
params AggregateFacet[] facets)
@@ -529,9 +487,7 @@ public static PipelineDefinition FacetThe type of the output documents.
/// The pipeline.
/// The facets.
- ///
- /// The fluent aggregate interface.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Facet(
this PipelineDefinition pipeline,
params AggregateFacet[] facets)
@@ -545,9 +501,7 @@ public static PipelineDefinition Facet
/// The type of the output.
/// The inputSerializer serializer.
- ///
- /// The fluent aggregate interface.
- ///
+ /// An empty pipeline.
public static PipelineDefinition For(IBsonSerializer inputSerializer = null)
{
return new EmptyPipelineDefinition(inputSerializer);
@@ -573,7 +527,7 @@ public static PipelineDefinition For(IBsonSerializerThe as field.
/// The depth field.
/// The options.
- /// The fluent aggregate interface.
+ /// A new pipeline with an additional stage.
public static PipelineDefinition GraphLookup(
this PipelineDefinition pipeline,
IMongoCollection from,
@@ -607,7 +561,7 @@ public static PipelineDefinition GraphLookupThe start with value.
/// The as field.
/// The options.
- /// The stage.
+ /// A new pipeline with an additional stage.
public static PipelineDefinition GraphLookup(
this PipelineDefinition pipeline,
IMongoCollection from,
@@ -635,7 +589,7 @@ public static PipelineDefinition GraphLookupThe start with value.
/// The as field.
/// The depth field.
- /// The fluent aggregate interface.
+ /// A new pipeline with an additional stage.
public static PipelineDefinition GraphLookup(
this PipelineDefinition pipeline,
IMongoCollection from,
@@ -668,7 +622,7 @@ public static PipelineDefinition GraphLookupThe as field.
/// The options.
/// The translation options.
- /// The stage.
+ /// A new pipeline with an additional stage.
public static PipelineDefinition GraphLookup(
this PipelineDefinition pipeline,
IMongoCollection from,
@@ -705,7 +659,7 @@ public static PipelineDefinition GraphLookupThe depth field.
/// The options.
/// The translation options.
- /// The stage.
+ /// A new pipeline with an additional stage.
public static PipelineDefinition GraphLookup(
this PipelineDefinition pipeline,
IMongoCollection from,
@@ -730,9 +684,7 @@ public static PipelineDefinition GraphLookupThe type of the output documents.
/// The pipeline.
/// The group projection.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.s
public static PipelineDefinition Group(
this PipelineDefinition pipeline,
ProjectionDefinition group)
@@ -748,9 +700,7 @@ public static PipelineDefinition GroupThe type of the intermediate documents.
/// The pipeline.
/// The group projection.
- ///
- /// The fluent aggregate interface.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Group(
this PipelineDefinition pipeline,
ProjectionDefinition group)
@@ -770,9 +720,7 @@ public static PipelineDefinition GroupThe id.
/// The group projection.
/// The translation options.
- ///
- /// The fluent aggregate interface.
- ///
+ /// A new pipeline with an additional stage.
/// This method can only be used with LINQ2 but that can't be verified until Render is called.
public static PipelineDefinition Group(
this PipelineDefinition pipeline,
@@ -791,9 +739,7 @@ public static PipelineDefinition GroupThe type of the output documents.
/// The pipeline.
/// The limit.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Limit(
this PipelineDefinition pipeline,
long limit)
@@ -815,9 +761,7 @@ public static PipelineDefinition Limit(
/// The foreign field.
/// The "as" field.
/// The options.
- ///
- /// A new pipeline with an additional stage.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Lookup(
this PipelineDefinition pipeline,
IMongoCollection foreignCollection,
@@ -843,9 +787,7 @@ public static PipelineDefinition LookupThe foreign field.
/// The "as" field.
/// The options.
- ///
- /// The fluent aggregate interface.
- ///
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Lookup(
this PipelineDefinition pipeline,
IMongoCollection foreignCollection,
@@ -873,7 +815,7 @@ public static PipelineDefinition LookupThe lookup pipeline.
/// The as field in in which to place the results of the lookup pipeline.
/// The options.
- /// The stage.
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Lookup(
this PipelineDefinition pipeline,
IMongoCollection foreignCollection,
@@ -908,7 +850,7 @@ public static PipelineDefinition LookupThe lookup pipeline.
/// The as field in in which to place the results of the lookup pipeline.
/// The options.
- /// The stage.
+ /// A new pipeline with an additional stage.
public static PipelineDefinition Lookup(
this PipelineDefinition pipeline,
IMongoCollection