Skip to content

Commit 39eb68e

Browse files
authored
Merge branch '9.1' into backport/9.1/130033
2 parents 6120305 + 9fbd946 commit 39eb68e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

docs/reference/query-languages/query-dsl/query-dsl-knn-query.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,36 @@ A sample query can look like below:
229229

230230
Note that nested `knn` only supports `score_mode=max`.
231231

232+
## Knn query on a semantic_text field [knn-query-with-semantic-text]
233+
234+
Elasticsearch supports knn queries over a [
235+
`semantic_text` field](/reference/elasticsearch/mapping-reference/semantic-text.md).
236+
237+
Here is an example using the `query_vector_builder`:
238+
239+
```json
240+
{
241+
"query": {
242+
"knn": {
243+
"field": "inference_field",
244+
"k": 10,
245+
"num_candidates": 100,
246+
"query_vector_builder": {
247+
"text_embedding": {
248+
"model_text": "test"
249+
}
250+
}
251+
}
252+
}
253+
}
254+
```
255+
256+
Note that for `semantic_text` fields, the `model_id` does not have to be
257+
provided as it can be inferred from the `semantic_text` field mapping.
258+
259+
Knn search using query vectors over `semantic_text` fields is also supported,
260+
with no change to the API.
261+
232262
## Knn query with aggregations [knn-query-aggregations]
233263

234264
`knn` query calculates aggregations on top `k` documents from each shard. Thus, the final results from aggregations contain `k * number_of_shards` documents. This is different from the [top level knn section](docs-content://solutions/search/vector/knn.md) where aggregations are calculated on the global top `k` nearest documents.

0 commit comments

Comments
 (0)