Text embedding processor

The text_embedding processor is used to generate vector embeddings from text fields for semantic search.

PREREQUISITE
Before using the text_embedding processor, you must set up a machine learning (ML) model. For more information, see Choosing a model.

The following is the syntax for the text_embedding processor:

  1. {
  2. "text_embedding": {
  3. "model_id": "<model_id>",
  4. "field_map": {
  5. "<input_field>": "<vector_field>"
  6. }
  7. }
  8. }

copy

Configuration parameters

The following table lists the required and optional parameters for the text_embedding processor.

ParameterData typeRequired/OptionalDescription
model_idStringRequiredThe ID of the model that will be used to generate the embeddings. 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 Semantic search.
field_mapObjectRequiredContains key-value pairs that specify the mapping of a text field to a vector field.
field_map.<input_field>StringRequiredThe name of the field from which to obtain text for generating text embeddings.
field_map.<vector_field>StringRequiredThe name of the vector field in which to store the generated text embeddings.
descriptionStringOptionalA brief description of the processor.
tagStringOptionalAn identifier tag for the processor. Useful for debugging to distinguish between processors of the same type.

Using the processor

Follow these steps to use the processor in a pipeline. You must provide a model ID when creating the processor. For more information, see Using custom models within OpenSearch.

Step 1: Create a pipeline.

The following example request creates an ingest pipeline where the text from passage_text will be converted into text embeddings and the embeddings will be stored in passage_embedding:

  1. PUT /_ingest/pipeline/nlp-ingest-pipeline
  2. {
  3. "description": "A text embedding pipeline",
  4. "processors": [
  5. {
  6. "text_embedding": {
  7. "model_id": "bQ1J8ooBpBj3wT4HVUsb",
  8. "field_map": {
  9. "passage_text": "passage_embedding"
  10. }
  11. }
  12. }
  13. ]
  14. }

copy

Step 2 (Optional): Test the pipeline.

It is recommended that you test your pipeline before you ingest documents.

To test the pipeline, run the following query:

  1. POST _ingest/pipeline/nlp-ingest-pipeline/_simulate
  2. {
  3. "docs": [
  4. {
  5. "_index": "testindex1",
  6. "_id": "1",
  7. "_source":{
  8. "passage_text": "hello world"
  9. }
  10. }
  11. ]
  12. }

copy

Response

The response confirms that in addition to the passage_text field, the processor has generated text embeddings in the passage_embedding field:

  1. {
  2. "docs": [
  3. {
  4. "doc": {
  5. "_index": "testindex1",
  6. "_id": "1",
  7. "_source": {
  8. "passage_embedding": [
  9. -0.048237972,
  10. -0.07612712,
  11. 0.3262124,
  12. ...
  13. -0.16352308
  14. ],
  15. "passage_text": "hello world"
  16. },
  17. "_ingest": {
  18. "timestamp": "2023-10-05T15:15:19.691345393Z"
  19. }
  20. }
  21. }
  22. ]
  23. }

Once you have created an ingest pipeline, you need to create an index for ingestion and ingest documents into the index. To learn more, see Step 2: Create an index for ingestion and Step 3: Ingest documents into the index of Semantic search.

Next steps