Table of Contents

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

source DbSet<TSource>

The IQueryable<T> LINQ expression from EF Core.

property Expression<Func<TSource, TProperty>>

The model property mapped to the BSON property containing vectors in the database.

queryVector QueryVector

The vector to search with.

limit int

The number of items to limit the vector search to.

options VectorQueryOptions?

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

TSource

The type of the elements of source.

TProperty

The 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

source DbSet<TSource>

The IQueryable<T> LINQ expression from EF Core.

property Expression<Func<TSource, TProperty>>

The model property mapped to the BSON property containing vectors in the database.

preFilter Expression<Func<TSource, bool>>

A predicate used to filter out documents before starting vector search.

queryVector QueryVector

The vector to search with.

limit int

The number of items to limit the vector search to.

options VectorQueryOptions?

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

TSource

The type of the elements of source.

TProperty

The 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.