54 lines
1.2 KiB
Plaintext
54 lines
1.2 KiB
Plaintext
// tag::elser[]
|
|
|
|
ELSER text embeddings can be queried using a
|
|
<<query-dsl-text-expansion-query,text expansion query>>. The text expansion
|
|
query enables you to query a rank features field or a sparse vector field, by
|
|
providing the model ID of the NLP model, and the query text:
|
|
|
|
[source,console]
|
|
----
|
|
GET my-index/_search
|
|
{
|
|
"query":{
|
|
"text_expansion":{
|
|
"my_tokens":{ <1>
|
|
"model_id":".elser_model_2",
|
|
"model_text":"the query string"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
----
|
|
// TEST[skip:TBD]
|
|
<1> The field of type `sparse_vector`.
|
|
|
|
// end::elser[]
|
|
|
|
|
|
// tag::dense-vector[]
|
|
|
|
Text embeddings produced by dense vector models can be queried using a
|
|
<<knn-semantic-search,kNN search>>. In the `knn` clause, provide the name of the
|
|
dense vector field, and a `query_vector_builder` clause with the model ID and
|
|
the query text.
|
|
|
|
[source,console]
|
|
----
|
|
GET my-index/_search
|
|
{
|
|
"knn": {
|
|
"field": "my_embeddings.predicted_value",
|
|
"k": 10,
|
|
"num_candidates": 100,
|
|
"query_vector_builder": {
|
|
"text_embedding": {
|
|
"model_id": "sentence-transformers__msmarco-minilm-l-12-v3",
|
|
"model_text": "the query string"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
----
|
|
// TEST[skip:TBD]
|
|
|
|
// end::dense-vector[] |