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 <#>
Azure OpenAI¶
The examples in this tutorial use models available through Azure OpenAI.
Requirements¶
- An Azure subscription
- Access granted to Azure OpenAI in the desired Azure subscription. You can apply for access to Azure OpenAI by completing the form at https://aka.ms/oai/access.
- An embedding model deployed in Azure OpenAI Studio.
Create an inference endpoint¶
Create an inference endpoint by using the Create inference API:
PUT _inference/text_embedding/azure_openai_embeddings
{
"service": "azureopenai",
"service_settings": {
"api_key": "<api_key>",
"resource_name": "<resource_name>",
"deployment_id": "<deployment_id>",
"api_version": "2024-02-01"
}
}
- The task type is
text_embedding
in the path and theinference_id
which is the unique identifier of the inference endpoint isamazon_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.
PUT azure-openai-embeddings
{
"mappings": {
"properties": {
"content_embedding": {
"type": "dense_vector",
"dims": 1536,
"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. Find this value in the Azure OpenAI documentation of the model you use.
- For Azure OpenAI embeddings, the
dot_product
function should be used to calculate similarity as Azure OpenAI embeddings are normalised to unit length. See the Azure OpenAI embeddingsdocumentation for more information on the model specifications. - 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.