Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/changelog/131081.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 131081
summary: Fix knn search error when dimensions are not set
area: Vector Search
type: bug
issues:
- 129550
Original file line number Diff line number Diff line change
Expand Up @@ -670,3 +670,36 @@ setup:
properties:
embedding:
type: dense_vector


---
"Searching with no data dimensions specified":
- requires:
cluster_features: "search.vectors.no_dimensions_bugfix"
reason: "Search with no dimensions bugfix"

- do:
indices.create:
index: empty-test
body:
mappings:
properties:
vector:
type: dense_vector
index: true

- do:
search:
index: empty-test
body:
fields: [ "name" ]
knn:
field: vector
query_vector: [ -0.5, 90.0, -10, 14.8, -156.0 ]
k: 3
num_candidates: 3
rescore_vector:
oversample: 1.5
similarity: 0.1

- match: { hits.total.value: 0 }
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.apache.lucene.search.FieldExistsQuery;
import org.apache.lucene.search.KnnByteVectorQuery;
import org.apache.lucene.search.KnnFloatVectorQuery;
import org.apache.lucene.search.MatchNoDocsQuery;
import org.apache.lucene.search.PatienceKnnVectorQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.join.BitSetProducer;
Expand Down Expand Up @@ -2530,6 +2531,9 @@ public Query createKnnQuery(
"to perform knn search on field [" + name() + "], its mapping must have [index] set to [true]"
);
}
if (dims == null) {
return new MatchNoDocsQuery("No data has been indexed for field [" + name() + "]");
}
KnnSearchStrategy knnSearchStrategy = heuristic.getKnnSearchStrategy();
return switch (getElementType()) {
case BYTE -> createKnnByteQuery(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public Set<NodeFeature> getFeatures() {
public static final NodeFeature INT_SORT_FOR_INT_SHORT_BYTE_FIELDS = new NodeFeature("search.sort.int_sort_for_int_short_byte_fields");
static final NodeFeature MULTI_MATCH_CHECKS_POSITIONS = new NodeFeature("search.multi.match.checks.positions");
public static final NodeFeature BBQ_HNSW_DEFAULT_INDEXING = new NodeFeature("search.vectors.mappers.default_bbq_hnsw");
public static final NodeFeature SEARCH_WITH_NO_DIMENSIONS_BUGFIX = new NodeFeature("search.vectors.no_dimensions_bugfix");

@Override
public Set<NodeFeature> getTestFeatures() {
Expand All @@ -41,7 +42,8 @@ public Set<NodeFeature> getTestFeatures() {
RESCORER_MISSING_FIELD_BAD_REQUEST,
INT_SORT_FOR_INT_SHORT_BYTE_FIELDS,
MULTI_MATCH_CHECKS_POSITIONS,
BBQ_HNSW_DEFAULT_INDEXING
BBQ_HNSW_DEFAULT_INDEXING,
SEARCH_WITH_NO_DIMENSIONS_BUGFIX
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ chartreuse | [127.0, 255.0, 0.0]
// end::knn-function-result[]
;

# https://github.com/elastic/elasticsearch/issues/129550 - Add as an example to knn function documentation
knnSearchWithSimilarityOption-Ignore
knnSearchWithSimilarityOption
required_capability: knn_function_v2

from colors metadata _score
Expand Down Expand Up @@ -208,8 +207,7 @@ green | false
maroon | false
;

# https://github.com/elastic/elasticsearch/issues/129550
testKnnWithNonPushableDisjunctions-Ignore
testKnnWithNonPushableDisjunctions
required_capability: knn_function_v2

from colors metadata _score
Expand All @@ -225,8 +223,7 @@ lemon chiffon
papaya whip
;

# https://github.com/elastic/elasticsearch/issues/129550
testKnnWithNonPushableDisjunctionsOnComplexExpressions-Ignore
testKnnWithNonPushableDisjunctionsOnComplexExpressions
required_capability: knn_function_v2

from colors metadata _score
Expand Down
Loading