19
19
import java .util .List ;
20
20
21
21
import org .bson .Document ;
22
+ import org .jspecify .annotations .Nullable ;
22
23
23
24
import org .springframework .data .domain .Limit ;
24
25
import org .springframework .data .domain .Range ;
46
47
import org .springframework .data .repository .query .ValueExpressionDelegate ;
47
48
import org .springframework .data .repository .query .parser .Part ;
48
49
import org .springframework .data .repository .query .parser .PartTree ;
49
- import org .springframework .lang .Nullable ;
50
50
import org .springframework .util .StringUtils ;
51
51
52
52
/**
@@ -145,7 +145,8 @@ public QueryMetadata createQuery(ValueExpressionEvaluator evaluator, ResultProce
145
145
numCandidates = ((Number ) evaluator .evaluate (this .numCandidatesExpression )).intValue ();
146
146
} else if (this .numCandidates != null ) {
147
147
numCandidates = this .numCandidates ;
148
- } else if (query .query ().isLimited () && searchType == VectorSearchOperation .SearchType .ANN ) {
148
+ } else if (query .query ().isLimited () && (searchType == VectorSearchOperation .SearchType .ANN
149
+ || searchType == VectorSearchOperation .SearchType .DEFAULT )) {
149
150
150
151
/*
151
152
MongoDB: We recommend that you specify a number at least 20 times higher than the number of documents to return (limit) to increase accuracy.
@@ -195,7 +196,7 @@ ScoringFunction getSimilarityFunction(MongoParameterAccessor accessor) {
195
196
* @param scoringFunction
196
197
*/
197
198
public record QueryMetadata (String path , String scoreField , Query query , VectorSearchOperation .SearchType searchType ,
198
- Class <?> outputType , @ org . jspecify . annotations . Nullable Integer numCandidates , ScoringFunction scoringFunction ) {
199
+ Class <?> outputType , @ Nullable Integer numCandidates , ScoringFunction scoringFunction ) {
199
200
200
201
/**
201
202
* Create the Aggregation Pipeline.
@@ -210,12 +211,10 @@ public List<AggregationOperation> getAggregationPipeline(MongoQueryMethod queryM
210
211
Vector vector = accessor .getVector ();
211
212
Score score = accessor .getScore ();
212
213
Range <Score > distance = accessor .getScoreRange ();
213
- int limit ;
214
+ Limit limit = Limit . unlimited () ;
214
215
215
216
if (query .isLimited ()) {
216
- limit = query .getLimit ();
217
- } else {
218
- limit = Math .max (1 , numCandidates () != null ? numCandidates () / 20 : 1 );
217
+ limit = Limit .of (query .getLimit ());
219
218
}
220
219
221
220
List <AggregationOperation > stages = new ArrayList <>();
0 commit comments