Link Search Menu Expand Document Documentation Menu

This version of the OpenSearch documentation is no longer maintained. For the latest version, see the current documentation. For information about OpenSearch version maintenance, see Release Schedule and Maintenance Policy.

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:

"neural_sparse": {
  "<vector_field>": {
    "query_text": "<query_text>",
    "model_id": "<model_id>",
    "max_token_score": "<max_token_score>"
  }
}

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.

Field Data type Required/Optional Description
query_text String Required The query text from which to generate vector embeddings.
model_id String Required The 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_score Float Optional 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.

Example request

GET my-nlp-index/_search
{
  "query": {
    "neural_sparse": {
      "passage_embedding": {
        "query_text": "Hi world",
        "model_id": "aP2Q8ooBpBj3wT4HVS8a",
        "max_token_score": 2
      }
    }
  }
}

350 characters left

Have a question? .

Want to contribute? or .