Skip to content

Commit cbae622

Browse files
committed
add patience and saturation threshold params
1 parent 98c42d2 commit cbae622

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

server/src/main/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldMapper.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ public IndexOptions parseIndexOptions(String fieldName, Map<String, ?> indexOpti
13961396
efConstructionNode = Lucene99HnswVectorsFormat.DEFAULT_BEAM_WIDTH;
13971397
}
13981398
if (earlyExitNode == null) {
1399-
earlyExitNode = true;
1399+
earlyExitNode = DEFAULT_EARLY_EXIT;
14001400
}
14011401
boolean earlyExit = XContentMapValues.nodeBooleanValue(earlyExitNode);
14021402
int m = XContentMapValues.nodeIntegerValue(mNode);
@@ -1707,7 +1707,7 @@ boolean updatableTo(IndexOptions update) {
17071707

17081708
@Override
17091709
boolean earlyExit() {
1710-
return DEFAULT_EARLY_EXIT;
1710+
return false;
17111711
}
17121712
}
17131713

@@ -1740,7 +1740,7 @@ boolean updatableTo(IndexOptions update) {
17401740

17411741
@Override
17421742
boolean earlyExit() {
1743-
return DEFAULT_EARLY_EXIT;
1743+
return false;
17441744
}
17451745

17461746
@Override
@@ -1899,7 +1899,7 @@ boolean updatableTo(IndexOptions update) {
18991899

19001900
@Override
19011901
boolean earlyExit() {
1902-
return DEFAULT_EARLY_EXIT;
1902+
return false;
19031903
}
19041904

19051905
}
@@ -2077,7 +2077,7 @@ public static class BBQHnswIndexOptions extends QuantizedIndexOptions {
20772077
private final boolean earlyExit;
20782078

20792079
public BBQHnswIndexOptions(int m, int efConstruction, RescoreVector rescoreVector) {
2080-
this(m, efConstruction, rescoreVector, true);
2080+
this(m, efConstruction, rescoreVector, DEFAULT_EARLY_EXIT);
20812081
}
20822082

20832083
public BBQHnswIndexOptions(int m, int efConstruction, RescoreVector rescoreVector, boolean earlyExit) {
@@ -2429,8 +2429,10 @@ private Query createKnnBitQuery(
24292429
KnnByteVectorQuery knnByteVectorQuery = parentFilter != null
24302430
? new ESDiversifyingChildrenByteKnnVectorQuery(name(), queryVector, filter, k, numCands, parentFilter, searchStrategy)
24312431
: new ESKnnByteVectorQuery(name(), queryVector, k, numCands, filter, searchStrategy);
2432-
// TODO: add saturation threshold and patience params ?
2433-
Query knnQuery = indexOptions.earlyExit() ? PatienceKnnVectorQuery.fromByteQuery(knnByteVectorQuery) : knnByteVectorQuery;
2432+
// TODO : fix reading of saturation threshold and patience params ?
2433+
Query knnQuery = indexOptions != null && indexOptions.earlyExit()
2434+
? PatienceKnnVectorQuery.fromByteQuery(knnByteVectorQuery, 0.95, (int) (k*0.3))
2435+
: knnByteVectorQuery;
24342436
if (similarityThreshold != null) {
24352437
knnQuery = new VectorSimilarityQuery(
24362438
knnQuery,
@@ -2459,8 +2461,10 @@ private Query createKnnByteQuery(
24592461
KnnByteVectorQuery knnByteVectorQuery = parentFilter != null
24602462
? new ESDiversifyingChildrenByteKnnVectorQuery(name(), queryVector, filter, k, numCands, parentFilter, searchStrategy)
24612463
: new ESKnnByteVectorQuery(name(), queryVector, k, numCands, filter, searchStrategy);
2462-
// TODO: add saturation threshold and patience params ?
2463-
Query knnQuery = indexOptions.earlyExit() ? PatienceKnnVectorQuery.fromByteQuery(knnByteVectorQuery) : knnByteVectorQuery;
2464+
// TODO: fix reading of saturation threshold and patience params ?
2465+
Query knnQuery = indexOptions != null && indexOptions.earlyExit()
2466+
? PatienceKnnVectorQuery.fromByteQuery(knnByteVectorQuery, 0.95, (int) (k*0.3))
2467+
: knnByteVectorQuery;
24642468

24652469
if (similarityThreshold != null) {
24662470
knnQuery = new VectorSimilarityQuery(
@@ -2524,8 +2528,10 @@ && isNotUnitVector(squaredMagnitude)) {
25242528
knnSearchStrategy
25252529
)
25262530
: new ESKnnFloatVectorQuery(name(), queryVector, adjustedK, numCands, filter, knnSearchStrategy);
2527-
// TODO: add saturation threshold and patience params ?
2528-
Query knnQuery = indexOptions.earlyExit() ? PatienceKnnVectorQuery.fromFloatQuery(knnFloatVectorQuery) : knnFloatVectorQuery;
2531+
// TODO: fix reading of saturation threshold and patience params ?
2532+
Query knnQuery = indexOptions != null && indexOptions.earlyExit()
2533+
? PatienceKnnVectorQuery.fromFloatQuery(knnFloatVectorQuery, 0.95, (int) (k*0.3))
2534+
: knnFloatVectorQuery;
25292535

25302536
if (rescore) {
25312537
knnQuery = new RescoreKnnVectorQuery(

server/src/test/java/org/elasticsearch/index/mapper/vectors/DenseVectorFieldTypeTests.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
package org.elasticsearch.index.mapper.vectors;
1111

12-
import org.apache.lucene.search.KnnByteVectorQuery;
1312
import org.apache.lucene.search.KnnFloatVectorQuery;
1413
import org.apache.lucene.search.PatienceKnnVectorQuery;
1514
import org.apache.lucene.search.Query;

0 commit comments

Comments
 (0)