Neural sparse query

Introduced 2.11

Use the neural_sparse query for vector field search in neural sparse search.

Request fields

Include the following request fields in the neural_sparse query:

  1. "neural_sparse": {
  2. "<vector_field>": {
  3. "query_text": "<query_text>",
  4. "model_id": "<model_id>"
  5. }
  6. }

The top-level vector_field specifies the vector field against which to run a search query. The following table lists the other neural_sparse query fields.

FieldData typeRequired/OptionalDescription
query_textStringRequiredThe query text from which to generate vector embeddings.
model_idStringRequiredThe ID of the sparse encoding model or tokenizer model that will be used to generate vector embeddings from the query text. The model must be deployed in OpenSearch before it can be used in sparse neural search. For more information, see Using custom models within OpenSearch and Neural sparse search.
max_token_scoreFloatOptional(Deprecated) The theoretical upper bound of the score for all tokens in the vocabulary (required for performance optimization). For OpenSearch-provided pretrained sparse embedding models, we recommend setting max_token_score to 2 for amazon/neural-sparse/opensearch-neural-sparse-encoding-doc-v1 and to 3.5 for amazon/neural-sparse/opensearch-neural-sparse-encoding-v1. This field has been deprecated as of OpenSearch 2.12.

Example request

  1. GET my-nlp-index/_search
  2. {
  3. "query": {
  4. "neural_sparse": {
  5. "passage_embedding": {
  6. "query_text": "Hi world",
  7. "model_id": "aP2Q8ooBpBj3wT4HVS8a"
  8. }
  9. }
  10. }
  11. }

copy