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
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@ The ordering of results returned from the inner retriever is preserved.
:::

`query_vector`
: (Optional, array of `float` or `byte`)
: (Optional, array of `float` or `byte`, or string)

Query vector. Must have the same number of dimensions as the vector field you are searching against.
Must be either an array of floats or a hex-encoded byte vector.
Must be one of:
- An array of floats
- A hex-encoded byte vector (one byte per dimension; for `bit`, one byte per 8 dimensions){applies_to}`stack: ga 9.0-9.3`
- A base64-encoded vector string. Base64 supports `float` and `bfloat16` (big-endian), `byte`, and `bit` encodings depending on the target field type. {applies_to}`stack: ga 9.4`
If you provide a `query_vector`, you cannot also provide a `query_vector_builder`.

`query_vector_builder`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,13 @@ A kNN retriever returns top documents from a [k-nearest neighbor search (kNN)](d


`query_vector`
: (Required if `query_vector_builder` is not defined, array of `float`)
: (Required if `query_vector_builder` is not defined, array of `float` or string)

Query vector. Must have the same number of dimensions as the vector field you are searching against. Must be either an array of floats or a hex-encoded byte vector.
Query vector. Must have the same number of dimensions as the vector field you are searching against.
Must be one of:
- An array of floats
- A hex-encoded byte vector (one byte per dimension; for `bit`, one byte per 8 dimensions). {applies_to}`stack: ga 9.0-9.3`
- A base64-encoded vector string. Base64 supports `float` and `bfloat16` (big-endian), `byte`, and `bit` encodings depending on the target field type. {applies_to}`stack: ga 9.4` {applies_to}`serverless: ga`


`query_vector_builder`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,40 @@
```
% TEST[continued]

3. {applies_to}`stack: ga 9.0-9.3` You can also provide a hex-encoded query vector string. Hex query vectors are byte-oriented (one byte per dimension, represented as two hex characters). For example, `[-5, 9, -12]` as signed bytes is `fb09f4`.

```console
POST my-image-index/_search
{
"size" : 3,
"query" : {
"knn": {
"field": "image-vector",
"query_vector": "fb09f4",
"k": 10
}
}
}
```
% TEST[continued]

4. {applies_to}`stack: ga 9.4` You can also provide a base64-encoded query vector string. For example, `[-5, 9, -12]` encoded as float32 big-endian bytes is `wKAAAEEQAADBQAAA`.

```console
POST my-image-index/_search
{
"size" : 3,
"query" : {
"knn": {
"field": "image-vector",
"query_vector": "wKAAAEEQAADBQAAA",
"k": 10
}
}
}
```
% TEST[continued]


## Top-level parameters for `knn` [knn-query-top-level-parameters]

Expand All @@ -74,7 +108,12 @@


`query_vector`
: (Optional, array of floats or string) Query vector. Must have the same number of dimensions as the vector field you are searching against. Must be either an array of floats or a hex-encoded byte vector. Either this or `query_vector_builder` must be provided.
: (Optional, array of floats or string) Query vector. Must have the same number of dimensions as the vector field you are searching against.
Must be one of:
- An array of floats
- A hex-encoded byte vector (one byte per dimension; for `bit`, one byte per 8 dimensions). {applies_to}`stack: ga 9.0-9.3`

Check notice on line 114 in docs/reference/query-languages/query-dsl/query-dsl-knn-query.md

View workflow job for this annotation

GitHub Actions / docs-preview / vale

Elastic.Semicolons: Use semicolons judiciously.
- A base64-encoded vector string. Base64 supports `float` and `bfloat16` (big-endian), `byte`, and `bit` encodings depending on the target field type. {applies_to}`stack: ga 9.4` {applies_to}`serverless: ga`
Either this or `query_vector_builder` must be provided.


`query_vector_builder`
Expand Down
Loading