@@ -1984,6 +1984,7 @@ public static PipelineStageDefinition<TInput, TInput> VectorSearch<TInput>(
1984
1984
Ensure . IsNotNull ( field , nameof ( field ) ) ;
1985
1985
Ensure . IsNotNull ( queryVector , nameof ( queryVector ) ) ;
1986
1986
Ensure . IsGreaterThanZero ( limit , nameof ( limit ) ) ;
1987
+ Ensure . That ( options ? . NumberOfCandidates is null || options . Exact == false , "Number of candidates must be omitted for exact nearest neighbour search (ENN)." ) ;
1987
1988
1988
1989
const string operatorName = "$vectorSearch" ;
1989
1990
var stage = new DelegatedPipelineStageDefinition < TInput , TInput > (
@@ -1996,9 +1997,10 @@ public static PipelineStageDefinition<TInput, TInput> VectorSearch<TInput>(
1996
1997
{ "queryVector" , queryVector . Array } ,
1997
1998
{ "path" , field . Render ( args ) . FieldName } ,
1998
1999
{ "limit" , limit } ,
1999
- { "numCandidates" , options ? . NumberOfCandidates ?? limit * 10 } ,
2000
+ { "numCandidates" , options ? . NumberOfCandidates ?? limit * 10 , options ? . Exact != true } ,
2000
2001
{ "index" , options ? . IndexName ?? "default" } ,
2001
- { "filter" , ( ) => options . Filter . Render ( args with { RenderDollarForm = true } ) , options ? . Filter != null } ,
2002
+ { "filter" , ( ) => options ? . Filter . Render ( args with { RenderDollarForm = true } ) , options ? . Filter != null } ,
2003
+ { "exact" , true , options ? . Exact == true }
2002
2004
} ;
2003
2005
2004
2006
var document = new BsonDocument ( operatorName , vectorSearchOperator ) ;
0 commit comments