@@ -44,29 +44,35 @@ class IndexManager {
4444 }
4545
4646 buildSearchQuery ( embedding , filter = { } , options = { } ) {
47+ const vectorSearchQuery = {
48+ index : this . options . indexName ,
49+ path : "embedding" ,
50+ queryVector : embedding ,
51+ limit : options . maxResults || 10 ,
52+ exact : options . exact || false // Allow exact to be configurable
53+ } ;
54+
55+ // Only add numCandidates if exact is false
56+ if ( ! vectorSearchQuery . exact ) {
57+ vectorSearchQuery . numCandidates = options . numCandidates || 100 ;
58+ }
59+
4760 const pipeline = [
4861 {
49- $vectorSearch : {
50- index : this . options . indexName ,
51- path : "embedding" ,
52- queryVector : embedding ,
53- numCandidates : options . numCandidates || 100 ,
54- limit : options . maxResults || 10 ,
55- exact : true
56- }
62+ $vectorSearch : vectorSearchQuery
5763 } ,
5864 {
5965 $addFields : {
6066 score : { $meta : "searchScore" }
6167 }
6268 }
6369 ] ;
64-
70+
6571 // Add filter if present
6672 if ( Object . keys ( filter ) . length > 0 ) {
6773 pipeline [ 0 ] . $vectorSearch . filter = filter ;
6874 }
69-
75+
7076 if ( options . includeMetadata ) {
7177 pipeline . push ( {
7278 $project : {
@@ -77,10 +83,11 @@ class IndexManager {
7783 }
7884 } ) ;
7985 }
80-
86+
8187 console . log ( 'Generated search query:' , JSON . stringify ( pipeline , null , 2 ) ) ;
8288 return pipeline ;
8389 }
90+
8491
8592 async getIndexStats ( ) {
8693 try {
0 commit comments