Link Search Menu Expand Document Documentation Menu

You're viewing version 2.14 of the OpenSearch documentation. This version 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 query

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

Request fields

Include the following request fields in the neural query:

"neural": {
  "<vector_field>": {
    "query_text": "<query_text>",
    "query_image": "<image_binary>",
    "model_id": "<model_id>",
    "k": 100
  }
}

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

Field Data type Required/Optional Description
query_text String Optional The query text from which to generate vector embeddings. You must specify at least one query_text or query_image.
query_image String Optional A base-64 encoded string that corresponds to the query image from which to generate vector embeddings. You must specify at least one query_text or query_image.
model_id String Required if the default model ID is not set. For more information, see Setting a default model on an index or field. The ID of the 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 neural search. For more information, see Using custom models within OpenSearch and Neural search.
k Integer Optional The number of results returned by the k-NN search. Only one variable, either k, min_score, or max_distance, can be specified. If a variable is not specified, the default is k with a value of 10.
min_score Float Optional The minimum score threshold for the search results. Only one variable, either k, min_score, or max_distance, can be specified. For more information, see k-NN radial search.
max_distance Float Optional The maximum distance threshold for the search results. Only one variable, either k, min_score, or max_distance, can be specified. For more information, see k-NN radial search.
filter Object Optional A query that can be used to reduce the number of documents considered. For more information about filter usage, see k-NN search with filters. Important: Filter can only be used with the faiss or lucene engines.

Example request

The following example shows a search with a k value of 100 and a filter that includes a range query and a term query:

GET /my-nlp-index/_search
{
  "query": {
    "neural": {
      "passage_embedding": {
        "query_text": "Hi world",
        "query_image": "iVBORw0KGgoAAAAN...",
        "k": 100,
        "filter": {
          "bool": {
            "must": [
              {
                "range": {
                  "rating": {
                    "gte": 8,
                    "lte": 10
                  }
                }
              },
              {
                "term": {
                  "parking": "true"
                }
              }
            ]
          }
        }
      }
    }
  }
}

The following search query includes a k-NN radial search min_score of 0.95 and a filter that includes a range query and a term query:

GET /my-nlp-index/_search
{
  "query": {
    "neural": {
      "passage_embedding": {
        "query_text": "Hi world",
        "query_image": "iVBORw0KGgoAAAAN...",
        "min_score": 0.95,
        "filter": {
          "bool": {
            "must": [
              {
                "range": {
                  "rating": {
                    "gte": 8,
                    "lte": 10
                  }
                }
              },
              {
                "term": {
                  "parking": "true"
                }
              }
            ]
          }
        }
      }
    }
  }
}

The following search query includes a k-NN radial search max_distance of 10 and a filter that includes a range query and a term query:

GET /my-nlp-index/_search
{
  "query": {
    "neural": {
      "passage_embedding": {
        "query_text": "Hi world",
        "query_image": "iVBORw0KGgoAAAAN...",
        "max_distance": 10,
        "filter": {
          "bool": {
            "must": [
              {
                "range": {
                  "rating": {
                    "gte": 8,
                    "lte": 10
                  }
                }
              },
              {
                "term": {
                  "parking": "true"
                }
              }
            ]
          }
        }
      }
    }
  }
}

350 characters left

Have a question? .

Want to contribute? or .