Semantic search with the inference API

Semantic search helps you find data based on the intent and contextual meaning of a search query, instead of a match on query terms (lexical search).

In this tutorial, learn how to use the inference API workflow with various services to perform semantic search on your data.

Amazon Bedrock <amazon-bedrock.html>
Azure AI Studio <azure-ai-studio.html>
Azure OpenAI <azure-openai.html>
Cohere <cohere.html>
ELSER <elser.html>
HuggingFace <#>
Mistral <#>
OpenAI <#>
Service Alpha <#>
Service Bravo <#>
Service Charlie <#>
Service Delta <#>
Service Echo <#>
Service Foxtrot <#>


Amazon Bedrock¶

The examples in this tutorial use the amazon.titan-embed-text-v1 model from the Amazon Bedrock base models.

Requirements¶

  • An AWS Account with Amazon Bedrock access
  • A pair of access and secret keys used to access Amazon Bedrock

Create an inference endpoint¶

Create an inference endpoint by using the Create inference API:

Create inference example for `Amazon Bedrock` ¶
PUT _inference/text_embedding/amazon_bedrock_embeddings
{
    "service": "amazonbedrock",
    "service_settings": {
        "access_key": "<aws_access_key>",
        "secret_key": "<aws_secret_key>",
        "region": "<region>",
        "provider": "<provider>",
        "model": "<model_id>"
    }
}
  • The task type is text_embedding in the path and the inference_id which is the unique identifier of the inference endpoint is amazon_bedrock_embeddings.
  • The access key can be found on your AWS IAM management page for the user account to access Amazon Bedrock.
  • The secret key should be the paired key for the specified access key.
  • Specify the region that your model is hosted in.
  • Specify the model provider.
  • The model ID or ARN of the model to use.

Create the index mapping¶

The mapping of the destination index—the index that contains the embeddings that the model will create based on your input text—must be created. The destination index must have a field with the dense_vector field type for most models and the sparse_vector field type for the sparse vector models like in the case of the elser service to index the output of the used model.

Create index mapping for `Amazon Bedrock` ¶
PUT amazon-bedrock-embeddings
{
  "mappings": {
    "properties": {
      "content_embedding": {
        "type": "dense_vector",
        "dims": 1024,
        "element_type": "float",
        "similarity": "dot_product"
      },
      "content": {
        "type": "text"
      }
    }
  }
}
  • The name of the field to contain the generated tokens. It must be referenced in the inference pipeline configuration in the next step.
  • The field to contain the tokens is a dense_vector field.
  • The output dimensions of the model. This value may be different depending on the underlying model used. See the Amazon Titan model or the Cohere Embeddings model documentation.
  • For Amazon Bedrock embeddings, the dot_product function should be used to calculate similarity for Amazon titan models, or cosine for Cohere models.
  • The name of the field from which to create the dense vector representation. In this example, the name of the field is content. It must be referenced in the inference pipeline configuration in the next step.
  • The field type which is text in this example.