Neural query

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

Request fields

Include the following request fields in the neural query:

  1. "neural": {
  2. "<vector_field>": {
  3. "query_text": "<query_text>",
  4. "query_image": "<image_binary>",
  5. "model_id": "<model_id>",
  6. "k": 100
  7. }
  8. }

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.

FieldData typeRequired/OptionalDescription
query_textStringOptionalThe query text from which to generate vector embeddings. You must specify at least one query_text or query_image.
query_imageStringOptionalA 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_idStringRequired 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.
kIntegerOptionalThe number of results returned by the k-NN search. Default is 10.

Example request

  1. GET /my-nlp-index/_search
  2. {
  3. "query": {
  4. "neural": {
  5. "passage_embedding": {
  6. "query_text": "Hi world",
  7. "query_image": "iVBORw0KGgoAAAAN...",
  8. "k": 100
  9. }
  10. }
  11. }
  12. }

copy