Method VectorSearch
- Namespace
- Microsoft.EntityFrameworkCore
- Assembly
- MongoDB.EntityFrameworkCore.dll
VectorSearch<TSource, TProperty>(DbSet<TSource>, Expression<Func<TSource, TProperty>>, QueryVector, int, VectorQueryOptions?)
Adds a MongoDB Atlas Vector Search to this LINQ query. This method must be called at the root of an EF Core query against MongoDB, except that a Where<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>) clause can be used to add a pre-query filter.
public static IQueryable<TSource> VectorSearch<TSource, TProperty>(this DbSet<TSource> source, Expression<Func<TSource, TProperty>> property, QueryVector queryVector, int limit, VectorQueryOptions? options = null) where TSource : class
Parameters
sourceDbSet<TSource>The IQueryable<T> LINQ expression from EF Core.
propertyExpression<Func<TSource, TProperty>>The model property mapped to the BSON property containing vectors in the database.
queryVectorQueryVectorThe vector to search with.
limitintThe number of items to limit the vector search to.
optionsVectorQueryOptions?An optional VectorQueryOptions with options for the search, including the specific index name to use.
Returns
- IQueryable<TSource>
An IQueryable<T> that will perform a vector search when executed.
Type Parameters
TSourceThe type of the elements of
source.TPropertyThe type of the vector property to search.
Remarks
Note that MongoDB Atlas Vector Search can only be used with MongoDB Atlas, not with other MongoDB configurations.
VectorSearch<TSource, TProperty>(DbSet<TSource>, Expression<Func<TSource, TProperty>>, Expression<Func<TSource, bool>>?, QueryVector, int, VectorQueryOptions?)
Adds a MongoDB Atlas Vector Search to this LINQ query. This method must be called at the root of an EF Core query against MongoDB, except that a Where<TSource>(IQueryable<TSource>, Expression<Func<TSource, bool>>) clause can be used to add a pre-query filter.
public static IQueryable<TSource> VectorSearch<TSource, TProperty>(this DbSet<TSource> source, Expression<Func<TSource, TProperty>> property, Expression<Func<TSource, bool>>? preFilter, QueryVector queryVector, int limit, VectorQueryOptions? options = null) where TSource : class
Parameters
sourceDbSet<TSource>The IQueryable<T> LINQ expression from EF Core.
propertyExpression<Func<TSource, TProperty>>The model property mapped to the BSON property containing vectors in the database.
preFilterExpression<Func<TSource, bool>>A predicate used to filter out documents before starting vector search.
queryVectorQueryVectorThe vector to search with.
limitintThe number of items to limit the vector search to.
optionsVectorQueryOptions?An optional VectorQueryOptions with options for the search, including the specific index name to use.
Returns
- IQueryable<TSource>
An IQueryable<T> that will perform a vector search when executed.
Type Parameters
TSourceThe type of the elements of
source.TPropertyThe type of the vector property to search.
Remarks
Note that MongoDB Atlas Vector Search can only be used with MongoDB Atlas, not with other MongoDB configurations.