Tutorial: semantic search with the inference API
editTutorial: semantic search with the inference API
editThe instructions in this tutorial shows you how to use the inference API workflow with various services to perform semantic search on your data.
For the easiest way to perform semantic search in the Elastic Stack, refer to the semantic_text
end-to-end tutorial.
The following examples use the:
-
embed-english-v3.0
model for Cohere -
all-mpnet-base-v2
model from HuggingFace -
text-embedding-ada-002
second generation embedding model for OpenAI - models available through Azure AI Studio or Azure OpenAI
-
text-embedding-004
model for Google Vertex AI -
mistral-embed
model for Mistral -
amazon.titan-embed-text-v1
model for Amazon Bedrock -
ops-text-embedding-zh-001
model for AlibabaCloud AI
You can use any Cohere and OpenAI models, they are all supported by the inference API. For a list of recommended models available on HuggingFace, refer to the supported model list.
Click the name of the service you want to use on any of the widgets below to review the corresponding instructions.
Requirements
editA Cohere account is required to use the inference API with the Cohere service.
ELSER is a model trained by Elastic. If you have an Elasticsearch deployment, there is no
further requirement for using the inference API with the elasticsearch
service.
A HuggingFace account is required to use the inference API with the HuggingFace service.
An OpenAI account is required to use the inference API with the OpenAI service.
- 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.
- An Azure subscription
- Access to Azure AI Studio
- A deployed embeddings or chat completion model.
- A Google Cloud account
- A project in Google Cloud
- The Vertex AI API enabled in your project
- A valid service account for the Google Vertex AI API
-
The service account must have the Vertex AI User role and the
aiplatform.endpoints.predict
permission.
- A Mistral Account on La Plateforme
- An API key generated for your account
- An AWS Account with Amazon Bedrock access
- A pair of access and secret keys used to access Amazon Bedrock
- An AlibabaCloud Account with AlibabaCloud access
- An API key generated for your account from the API keys section
Create an inference endpoint
editCreate an inference endpoint by using the Create inference API:
resp = client.inference.put( task_type="text_embedding", inference_id="cohere_embeddings", inference_config={ "service": "cohere", "service_settings": { "api_key": "<api_key>", "model_id": "embed-english-v3.0", "embedding_type": "byte" } }, ) print(resp)
const response = await client.inference.put({ task_type: "text_embedding", inference_id: "cohere_embeddings", inference_config: { service: "cohere", service_settings: { api_key: "<api_key>", model_id: "embed-english-v3.0", embedding_type: "byte", }, }, }); console.log(response);
PUT _inference/text_embedding/cohere_embeddings { "service": "cohere", "service_settings": { "api_key": "<api_key>", "model_id": "embed-english-v3.0", "embedding_type": "byte" } }
The task type is |
|
The API key of your Cohere account. You can find your API keys in your Cohere dashboard under the API keys section. You need to provide your API key only once. The Get inference API does not return your API key. |
|
The name of the embedding model to use. You can find the list of Cohere embedding models here. |
When using this model the recommended similarity measure to use in the
dense_vector
field mapping is dot_product
. In the case of Cohere models, the
embeddings are normalized to unit length in which case the dot_product
and
the cosine
measures are equivalent.
PUT _inference/sparse_embedding/elser_embeddings { "service": "elasticsearch", "service_settings": { "num_allocations": 1, "num_threads": 1 } }
The task type is |
You don’t need to download and deploy the ELSER model upfront, the API request above will download the model if it’s not downloaded yet and then deploy it.
You might see a 502 bad gateway error in the response when using the Kibana Console.
This error usually just reflects a timeout, while the model downloads in the background.
You can check the download progress in the Machine Learning UI.
If using the Python client, you can set the timeout
parameter to a higher value.
First, you need to create a new inference endpoint on
the Hugging Face endpoint page to get an
endpoint URL. Select the model all-mpnet-base-v2
on the new endpoint creation
page, then select the Sentence Embeddings
task under the Advanced
configuration section. Create the endpoint. Copy the URL after the endpoint
initialization has been finished, you need the URL in the following inference API
call.
resp = client.inference.put( task_type="text_embedding", inference_id="hugging_face_embeddings", inference_config={ "service": "hugging_face", "service_settings": { "api_key": "<access_token>", "url": "<url_endpoint>" } }, ) print(resp)
const response = await client.inference.put({ task_type: "text_embedding", inference_id: "hugging_face_embeddings", inference_config: { service: "hugging_face", service_settings: { api_key: "<access_token>", url: "<url_endpoint>", }, }, }); console.log(response);
PUT _inference/text_embedding/hugging_face_embeddings { "service": "hugging_face", "service_settings": { "api_key": "<access_token>", "url": "<url_endpoint>" } }
The task type is |
|
A valid HuggingFace access token. You can find on the settings page of your account. |
|
The inference endpoint URL you created on Hugging Face. |
resp = client.inference.put( task_type="text_embedding", inference_id="openai_embeddings", inference_config={ "service": "openai", "service_settings": { "api_key": "<api_key>", "model_id": "text-embedding-ada-002" } }, ) print(resp)
const response = await client.inference.put({ task_type: "text_embedding", inference_id: "openai_embeddings", inference_config: { service: "openai", service_settings: { api_key: "<api_key>", model_id: "text-embedding-ada-002", }, }, }); console.log(response);
PUT _inference/text_embedding/openai_embeddings { "service": "openai", "service_settings": { "api_key": "<api_key>", "model_id": "text-embedding-ada-002" } }
The task type is |
|
The API key of your OpenAI account. You can find your OpenAI API keys in your OpenAI account under the API keys section. You need to provide your API key only once. The Get inference API does not return your API key. |
|
The name of the embedding model to use. You can find the list of OpenAI embedding models here. |
When using this model the recommended similarity measure to use in the
dense_vector
field mapping is dot_product
. In the case of OpenAI models, the
embeddings are normalized to unit length in which case the dot_product
and
the cosine
measures are equivalent.
resp = client.inference.put( task_type="text_embedding", inference_id="azure_openai_embeddings", inference_config={ "service": "azureopenai", "service_settings": { "api_key": "<api_key>", "resource_name": "<resource_name>", "deployment_id": "<deployment_id>", "api_version": "2024-02-01" } }, ) print(resp)
const response = await client.inference.put({ task_type: "text_embedding", inference_id: "azure_openai_embeddings", inference_config: { service: "azureopenai", service_settings: { api_key: "<api_key>", resource_name: "<resource_name>", deployment_id: "<deployment_id>", api_version: "2024-02-01", }, }, }); console.log(response);
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 |
|
The API key for accessing your Azure OpenAI services.
Alternately, you can provide an |
|
The name our your Azure resource. |
|
The id of your deployed model. |
It may take a few minutes for your model’s deployment to become available
after it is created. If you try and create the model as above and receive a
404
error message, wait a few minutes and try again.
Also, when using this model the recommended similarity measure to use in the
dense_vector
field mapping is dot_product
.
In the case of Azure OpenAI models, the embeddings are normalized to unit
length in which case the dot_product
and the cosine
measures are equivalent.
resp = client.inference.put( task_type="text_embedding", inference_id="azure_ai_studio_embeddings", inference_config={ "service": "azureaistudio", "service_settings": { "api_key": "<api_key>", "target": "<target_uri>", "provider": "<provider>", "endpoint_type": "<endpoint_type>" } }, ) print(resp)
const response = await client.inference.put({ task_type: "text_embedding", inference_id: "azure_ai_studio_embeddings", inference_config: { service: "azureaistudio", service_settings: { api_key: "<api_key>", target: "<target_uri>", provider: "<provider>", endpoint_type: "<endpoint_type>", }, }, }); console.log(response);
PUT _inference/text_embedding/azure_ai_studio_embeddings { "service": "azureaistudio", "service_settings": { "api_key": "<api_key>", "target": "<target_uri>", "provider": "<provider>", "endpoint_type": "<endpoint_type>" } }
The task type is |
|
The API key for accessing your Azure AI Studio deployed model. You can find this on your model deployment’s overview page. |
|
The target URI for accessing your Azure AI Studio deployed model. You can find this on your model deployment’s overview page. |
|
The model provider, such as |
|
The deployed endpoint type. This can be |
It may take a few minutes for your model’s deployment to become available
after it is created. If you try and create the model as above and receive a
404
error message, wait a few minutes and try again.
Also, when using this model the recommended similarity measure to use in the
dense_vector
field mapping is dot_product
.
resp = client.inference.put( task_type="text_embedding", inference_id="google_vertex_ai_embeddings", inference_config={ "service": "googlevertexai", "service_settings": { "service_account_json": "<service_account_json>", "model_id": "text-embedding-004", "location": "<location>", "project_id": "<project_id>" } }, ) print(resp)
const response = await client.inference.put({ task_type: "text_embedding", inference_id: "google_vertex_ai_embeddings", inference_config: { service: "googlevertexai", service_settings: { service_account_json: "<service_account_json>", model_id: "text-embedding-004", location: "<location>", project_id: "<project_id>", }, }, }); console.log(response);
PUT _inference/text_embedding/google_vertex_ai_embeddings { "service": "googlevertexai", "service_settings": { "service_account_json": "<service_account_json>", "model_id": "text-embedding-004", "location": "<location>", "project_id": "<project_id>" } }
The task type is |
|
A valid service account in JSON format for the Google Vertex AI API. |
|
For the list of the available models, refer to the Text embeddings API page. |
|
The name of the location to use for the inference task. Refer to Generative AI on Vertex AI locations for available locations. |
|
The name of the project to use for the inference task. |
resp = client.inference.put( task_type="text_embedding", inference_id="mistral_embeddings", inference_config={ "service": "mistral", "service_settings": { "api_key": "<api_key>", "model": "<model_id>" } }, ) print(resp)
const response = await client.inference.put({ task_type: "text_embedding", inference_id: "mistral_embeddings", inference_config: { service: "mistral", service_settings: { api_key: "<api_key>", model: "<model_id>", }, }, }); console.log(response);
PUT _inference/text_embedding/mistral_embeddings { "service": "mistral", "service_settings": { "api_key": "<api_key>", "model": "<model_id>" } }
The task type is |
|
The API key for accessing the Mistral API. You can find this in your Mistral account’s API Keys page. |
|
The Mistral embeddings model name, for example |
resp = client.inference.put( task_type="text_embedding", inference_id="amazon_bedrock_embeddings", inference_config={ "service": "amazonbedrock", "service_settings": { "access_key": "<aws_access_key>", "secret_key": "<aws_secret_key>", "region": "<region>", "provider": "<provider>", "model": "<model_id>" } }, ) print(resp)
const response = await client.inference.put({ task_type: "text_embedding", inference_id: "amazon_bedrock_embeddings", inference_config: { service: "amazonbedrock", service_settings: { access_key: "<aws_access_key>", secret_key: "<aws_secret_key>", region: "<region>", provider: "<provider>", model: "<model_id>", }, }, }); console.log(response);
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 |
|
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. |
resp = client.inference.put( task_type="text_embedding", inference_id="alibabacloud_ai_search_embeddings", inference_config={ "service": "alibabacloud-ai-search", "service_settings": { "api_key": "<api_key>", "service_id": "<service_id>", "host": "<host>", "workspace": "<workspace>" } }, ) print(resp)
const response = await client.inference.put({ task_type: "text_embedding", inference_id: "alibabacloud_ai_search_embeddings", inference_config: { service: "alibabacloud-ai-search", service_settings: { api_key: "<api_key>", service_id: "<service_id>", host: "<host>", workspace: "<workspace>", }, }, }); console.log(response);
PUT _inference/text_embedding/alibabacloud_ai_search_embeddings { "service": "alibabacloud-ai-search", "service_settings": { "api_key": "<api_key>", "service_id": "<service_id>", "host": "<host>", "workspace": "<workspace>" } }
The task type is |
|
The API key for accessing the AlibabaCloud AI Search API. You can find your API keys in your AlibabaCloud account under the API keys section. You need to provide your API key only once. The Get inference API does not return your API key. |
|
The AlibabaCloud AI Search embeddings model name, for example |
|
The name our your AlibabaCloud AI Search host address. |
|
The name our your AlibabaCloud AI Search workspace. |
Create the index mapping
editThe 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 elasticsearch
service to index the output of the used model.
resp = client.indices.create( index="cohere-embeddings", mappings={ "properties": { "content_embedding": { "type": "dense_vector", "dims": 1024, "element_type": "byte" }, "content": { "type": "text" } } }, ) print(resp)
response = client.indices.create( index: 'cohere-embeddings', body: { mappings: { properties: { content_embedding: { type: 'dense_vector', dims: 1024, element_type: 'byte' }, content: { type: 'text' } } } } ) puts response
const response = await client.indices.create({ index: "cohere-embeddings", mappings: { properties: { content_embedding: { type: "dense_vector", dims: 1024, element_type: "byte", }, content: { type: "text", }, }, }, }); console.log(response);
PUT cohere-embeddings { "mappings": { "properties": { "content_embedding": { "type": "dense_vector", "dims": 1024, "element_type": "byte" }, "content": { "type": "text" } } } }
The name of the field to contain the generated tokens. It must be refrenced in the inference pipeline configuration in the next step. |
|
The field to contain the tokens is a |
|
The output dimensions of the model. Find this value in the Cohere documentation of the model you use. |
|
The name of the field from which to create the dense vector representation.
In this example, the name of the field is |
|
The field type which is text in this example. |
resp = client.indices.create( index="elser-embeddings", mappings={ "properties": { "content_embedding": { "type": "sparse_vector" }, "content": { "type": "text" } } }, ) print(resp)
const response = await client.indices.create({ index: "elser-embeddings", mappings: { properties: { content_embedding: { type: "sparse_vector", }, content: { type: "text", }, }, }, }); console.log(response);
PUT elser-embeddings { "mappings": { "properties": { "content_embedding": { "type": "sparse_vector" }, "content": { "type": "text" } } } }
The name of the field to contain the generated tokens. It must be refrenced in the inference pipeline configuration in the next step. |
|
The field to contain the tokens is a |
|
The name of the field from which to create the dense vector representation.
In this example, the name of the field is |
|
The field type which is text in this example. |
resp = client.indices.create( index="hugging-face-embeddings", mappings={ "properties": { "content_embedding": { "type": "dense_vector", "dims": 768, "element_type": "float" }, "content": { "type": "text" } } }, ) print(resp)
response = client.indices.create( index: 'hugging-face-embeddings', body: { mappings: { properties: { content_embedding: { type: 'dense_vector', dims: 768, element_type: 'float' }, content: { type: 'text' } } } } ) puts response
const response = await client.indices.create({ index: "hugging-face-embeddings", mappings: { properties: { content_embedding: { type: "dense_vector", dims: 768, element_type: "float", }, content: { type: "text", }, }, }, }); console.log(response);
PUT hugging-face-embeddings { "mappings": { "properties": { "content_embedding": { "type": "dense_vector", "dims": 768, "element_type": "float" }, "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 |
|
The output dimensions of the model. Find this value in the HuggingFace model documentation. |
|
The name of the field from which to create the dense vector representation.
In this example, the name of the field is |
|
The field type which is text in this example. |
resp = client.indices.create( index="openai-embeddings", mappings={ "properties": { "content_embedding": { "type": "dense_vector", "dims": 1536, "element_type": "float", "similarity": "dot_product" }, "content": { "type": "text" } } }, ) print(resp)
response = client.indices.create( index: 'openai-embeddings', body: { mappings: { properties: { content_embedding: { type: 'dense_vector', dims: 1536, element_type: 'float', similarity: 'dot_product' }, content: { type: 'text' } } } } ) puts response
const response = await client.indices.create({ index: "openai-embeddings", mappings: { properties: { content_embedding: { type: "dense_vector", dims: 1536, element_type: "float", similarity: "dot_product", }, content: { type: "text", }, }, }, }); console.log(response);
PUT 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 |
|
The output dimensions of the model. Find this value in the OpenAI documentation of the model you use. |
|
The faster` dot_product` function can be used to calculate similarity because OpenAI embeddings are normalised to unit length. You can check the OpenAI docs about which similarity function to use. |
|
The name of the field from which to create the dense vector representation.
In this example, the name of the field is |
|
The field type which is text in this example. |
resp = client.indices.create( index="azure-openai-embeddings", mappings={ "properties": { "content_embedding": { "type": "dense_vector", "dims": 1536, "element_type": "float", "similarity": "dot_product" }, "content": { "type": "text" } } }, ) print(resp)
response = client.indices.create( index: 'azure-openai-embeddings', body: { mappings: { properties: { content_embedding: { type: 'dense_vector', dims: 1536, element_type: 'float', similarity: 'dot_product' }, content: { type: 'text' } } } } ) puts response
const response = await client.indices.create({ index: "azure-openai-embeddings", mappings: { properties: { content_embedding: { type: "dense_vector", dims: 1536, element_type: "float", similarity: "dot_product", }, content: { type: "text", }, }, }, }); console.log(response);
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 |
|
The output dimensions of the model. Find this value in the Azure OpenAI documentation of the model you use. |
|
For Azure OpenAI embeddings, the |
|
The name of the field from which to create the dense vector representation.
In this example, the name of the field is |
|
The field type which is text in this example. |
resp = client.indices.create( index="azure-ai-studio-embeddings", mappings={ "properties": { "content_embedding": { "type": "dense_vector", "dims": 1536, "element_type": "float", "similarity": "dot_product" }, "content": { "type": "text" } } }, ) print(resp)
const response = await client.indices.create({ index: "azure-ai-studio-embeddings", mappings: { properties: { content_embedding: { type: "dense_vector", dims: 1536, element_type: "float", similarity: "dot_product", }, content: { type: "text", }, }, }, }); console.log(response);
PUT azure-ai-studio-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 |
|
The output dimensions of the model. This value may be found on the model card in your Azure AI Studio deployment. |
|
For Azure AI Studio embeddings, the |
|
The name of the field from which to create the dense vector representation.
In this example, the name of the field is |
|
The field type which is text in this example. |
resp = client.indices.create( index="google-vertex-ai-embeddings", mappings={ "properties": { "content_embedding": { "type": "dense_vector", "dims": 768, "element_type": "float", "similarity": "dot_product" }, "content": { "type": "text" } } }, ) print(resp)
const response = await client.indices.create({ index: "google-vertex-ai-embeddings", mappings: { properties: { content_embedding: { type: "dense_vector", dims: 768, element_type: "float", similarity: "dot_product", }, content: { type: "text", }, }, }, }); console.log(response);
PUT google-vertex-ai-embeddings { "mappings": { "properties": { "content_embedding": { "type": "dense_vector", "dims": 768, "element_type": "float", "similarity": "dot_product" }, "content": { "type": "text" } } } }
The name of the field to contain the generated embeddings. It must be referenced in the inference pipeline configuration in the next step. |
|
The field to contain the embeddings is a |
|
The output dimensions of the model. This value may be found on the Google Vertex AI model reference.
The inference API attempts to calculate the output dimensions automatically if |
|
For Google Vertex AI embeddings, the |
|
The name of the field from which to create the dense vector representation.
In this example, the name of the field is |
|
The field type which is |
resp = client.indices.create( index="mistral-embeddings", mappings={ "properties": { "content_embedding": { "type": "dense_vector", "dims": 1024, "element_type": "float", "similarity": "dot_product" }, "content": { "type": "text" } } }, ) print(resp)
const response = await client.indices.create({ index: "mistral-embeddings", mappings: { properties: { content_embedding: { type: "dense_vector", dims: 1024, element_type: "float", similarity: "dot_product", }, content: { type: "text", }, }, }, }); console.log(response);
PUT mistral-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 |
|
The output dimensions of the model. This value may be found on the Mistral model reference. |
|
For Mistral embeddings, the |
|
The name of the field from which to create the dense vector representation.
In this example, the name of the field is |
|
The field type which is text in this example. |
resp = client.indices.create( index="amazon-bedrock-embeddings", mappings={ "properties": { "content_embedding": { "type": "dense_vector", "dims": 1024, "element_type": "float", "similarity": "dot_product" }, "content": { "type": "text" } } }, ) print(resp)
const response = await client.indices.create({ index: "amazon-bedrock-embeddings", mappings: { properties: { content_embedding: { type: "dense_vector", dims: 1024, element_type: "float", similarity: "dot_product", }, content: { type: "text", }, }, }, }); console.log(response);
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 |
|
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 |
|
The name of the field from which to create the dense vector representation.
In this example, the name of the field is |
|
The field type which is text in this example. |
resp = client.indices.create( index="alibabacloud-ai-search-embeddings", mappings={ "properties": { "content_embedding": { "type": "dense_vector", "dims": 1024, "element_type": "float" }, "content": { "type": "text" } } }, ) print(resp)
const response = await client.indices.create({ index: "alibabacloud-ai-search-embeddings", mappings: { properties: { content_embedding: { type: "dense_vector", dims: 1024, element_type: "float", }, content: { type: "text", }, }, }, }); console.log(response);
PUT alibabacloud-ai-search-embeddings { "mappings": { "properties": { "content_embedding": { "type": "dense_vector", "dims": 1024, "element_type": "float" }, "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 |
|
The output dimensions of the model. This value may be different depending on the underlying model used. See the AlibabaCloud AI Search embedding model documentation. |
|
The name of the field from which to create the dense vector representation.
In this example, the name of the field is |
|
The field type which is text in this example. |
Create an ingest pipeline with an inference processor
editCreate an ingest pipeline with an inference processor and use the model you created above to infer against the data that is being ingested in the pipeline.
resp = client.ingest.put_pipeline( id="cohere_embeddings_pipeline", processors=[ { "inference": { "model_id": "cohere_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ], ) print(resp)
const response = await client.ingest.putPipeline({ id: "cohere_embeddings_pipeline", processors: [ { inference: { model_id: "cohere_embeddings", input_output: { input_field: "content", output_field: "content_embedding", }, }, }, ], }); console.log(response);
PUT _ingest/pipeline/cohere_embeddings_pipeline { "processors": [ { "inference": { "model_id": "cohere_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ] }
The name of the inference endpoint you created by using the
Create inference API, it’s referred to as |
|
Configuration object that defines the |
resp = client.ingest.put_pipeline( id="elser_embeddings_pipeline", processors=[ { "inference": { "model_id": "elser_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ], ) print(resp)
const response = await client.ingest.putPipeline({ id: "elser_embeddings_pipeline", processors: [ { inference: { model_id: "elser_embeddings", input_output: { input_field: "content", output_field: "content_embedding", }, }, }, ], }); console.log(response);
PUT _ingest/pipeline/elser_embeddings_pipeline { "processors": [ { "inference": { "model_id": "elser_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ] }
The name of the inference endpoint you created by using the
Create inference API, it’s referred to as |
|
Configuration object that defines the |
resp = client.ingest.put_pipeline( id="hugging_face_embeddings_pipeline", processors=[ { "inference": { "model_id": "hugging_face_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ], ) print(resp)
const response = await client.ingest.putPipeline({ id: "hugging_face_embeddings_pipeline", processors: [ { inference: { model_id: "hugging_face_embeddings", input_output: { input_field: "content", output_field: "content_embedding", }, }, }, ], }); console.log(response);
PUT _ingest/pipeline/hugging_face_embeddings_pipeline { "processors": [ { "inference": { "model_id": "hugging_face_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ] }
The name of the inference endpoint you created by using the
Create inference API, it’s referred to as |
|
Configuration object that defines the |
resp = client.ingest.put_pipeline( id="openai_embeddings_pipeline", processors=[ { "inference": { "model_id": "openai_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ], ) print(resp)
const response = await client.ingest.putPipeline({ id: "openai_embeddings_pipeline", processors: [ { inference: { model_id: "openai_embeddings", input_output: { input_field: "content", output_field: "content_embedding", }, }, }, ], }); console.log(response);
PUT _ingest/pipeline/openai_embeddings_pipeline { "processors": [ { "inference": { "model_id": "openai_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ] }
The name of the inference endpoint you created by using the
Create inference API, it’s referred to as |
|
Configuration object that defines the |
resp = client.ingest.put_pipeline( id="azure_openai_embeddings_pipeline", processors=[ { "inference": { "model_id": "azure_openai_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ], ) print(resp)
const response = await client.ingest.putPipeline({ id: "azure_openai_embeddings_pipeline", processors: [ { inference: { model_id: "azure_openai_embeddings", input_output: { input_field: "content", output_field: "content_embedding", }, }, }, ], }); console.log(response);
PUT _ingest/pipeline/azure_openai_embeddings_pipeline { "processors": [ { "inference": { "model_id": "azure_openai_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ] }
The name of the inference endpoint you created by using the
Create inference API, it’s referred to as |
|
Configuration object that defines the |
resp = client.ingest.put_pipeline( id="azure_ai_studio_embeddings_pipeline", processors=[ { "inference": { "model_id": "azure_ai_studio_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ], ) print(resp)
const response = await client.ingest.putPipeline({ id: "azure_ai_studio_embeddings_pipeline", processors: [ { inference: { model_id: "azure_ai_studio_embeddings", input_output: { input_field: "content", output_field: "content_embedding", }, }, }, ], }); console.log(response);
PUT _ingest/pipeline/azure_ai_studio_embeddings_pipeline { "processors": [ { "inference": { "model_id": "azure_ai_studio_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ] }
The name of the inference endpoint you created by using the
Create inference API, it’s referred to as |
|
Configuration object that defines the |
resp = client.ingest.put_pipeline( id="google_vertex_ai_embeddings_pipeline", processors=[ { "inference": { "model_id": "google_vertex_ai_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ], ) print(resp)
const response = await client.ingest.putPipeline({ id: "google_vertex_ai_embeddings_pipeline", processors: [ { inference: { model_id: "google_vertex_ai_embeddings", input_output: { input_field: "content", output_field: "content_embedding", }, }, }, ], }); console.log(response);
PUT _ingest/pipeline/google_vertex_ai_embeddings_pipeline { "processors": [ { "inference": { "model_id": "google_vertex_ai_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ] }
The name of the inference endpoint you created by using the
Create inference API, it’s referred to as |
|
Configuration object that defines the |
resp = client.ingest.put_pipeline( id="mistral_embeddings_pipeline", processors=[ { "inference": { "model_id": "mistral_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ], ) print(resp)
const response = await client.ingest.putPipeline({ id: "mistral_embeddings_pipeline", processors: [ { inference: { model_id: "mistral_embeddings", input_output: { input_field: "content", output_field: "content_embedding", }, }, }, ], }); console.log(response);
PUT _ingest/pipeline/mistral_embeddings_pipeline { "processors": [ { "inference": { "model_id": "mistral_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ] }
The name of the inference endpoint you created by using the
Create inference API, it’s referred to as |
|
Configuration object that defines the |
resp = client.ingest.put_pipeline( id="amazon_bedrock_embeddings_pipeline", processors=[ { "inference": { "model_id": "amazon_bedrock_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ], ) print(resp)
const response = await client.ingest.putPipeline({ id: "amazon_bedrock_embeddings_pipeline", processors: [ { inference: { model_id: "amazon_bedrock_embeddings", input_output: { input_field: "content", output_field: "content_embedding", }, }, }, ], }); console.log(response);
PUT _ingest/pipeline/amazon_bedrock_embeddings_pipeline { "processors": [ { "inference": { "model_id": "amazon_bedrock_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ] }
The name of the inference endpoint you created by using the
Create inference API, it’s referred to as |
|
Configuration object that defines the |
resp = client.ingest.put_pipeline( id="alibabacloud_ai_search_embeddings_pipeline", processors=[ { "inference": { "model_id": "alibabacloud_ai_search_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ], ) print(resp)
const response = await client.ingest.putPipeline({ id: "alibabacloud_ai_search_embeddings_pipeline", processors: [ { inference: { model_id: "alibabacloud_ai_search_embeddings", input_output: { input_field: "content", output_field: "content_embedding", }, }, }, ], }); console.log(response);
PUT _ingest/pipeline/alibabacloud_ai_search_embeddings_pipeline { "processors": [ { "inference": { "model_id": "alibabacloud_ai_search_embeddings", "input_output": { "input_field": "content", "output_field": "content_embedding" } } } ] }
The name of the inference endpoint you created by using the
Create inference API, it’s referred to as |
|
Configuration object that defines the |
Load data
editIn this step, you load the data that you later use in the inference ingest pipeline to create embeddings from it.
Use the msmarco-passagetest2019-top1000
data set, which is a subset of the MS MARCO Passage Ranking data set.
It consists of 200 queries, each accompanied by a list of relevant text passages.
All unique passages, along with their IDs, have been extracted from that data set and compiled into a
tsv file.
Download the file and upload it to your cluster using the Data Visualizer in the Machine Learning UI.
After your data is analyzed, click Override settings.
Under Edit field names, assign id
to the first column and content
to the second.
Click Apply, then Import.
Name the index test-data
, and click Import.
After the upload is complete, you will see an index named test-data
with 182,469 documents.
Ingest the data through the inference ingest pipeline
editCreate embeddings from the text by reindexing the data through the inference pipeline that uses your chosen model. This step uses the reindex API to simulate data ingestion through a pipeline.
resp = client.reindex( wait_for_completion=False, source={ "index": "test-data", "size": 50 }, dest={ "index": "cohere-embeddings", "pipeline": "cohere_embeddings_pipeline" }, ) print(resp)
const response = await client.reindex({ wait_for_completion: "false", source: { index: "test-data", size: 50, }, dest: { index: "cohere-embeddings", pipeline: "cohere_embeddings_pipeline", }, }); console.log(response);
POST _reindex?wait_for_completion=false { "source": { "index": "test-data", "size": 50 }, "dest": { "index": "cohere-embeddings", "pipeline": "cohere_embeddings_pipeline" } }
The default batch size for reindexing is 1000. Reducing |
The rate limit of your Cohere account may affect the throughput of the reindexing process.
resp = client.reindex( wait_for_completion=False, source={ "index": "test-data", "size": 50 }, dest={ "index": "elser-embeddings", "pipeline": "elser_embeddings_pipeline" }, ) print(resp)
const response = await client.reindex({ wait_for_completion: "false", source: { index: "test-data", size: 50, }, dest: { index: "elser-embeddings", pipeline: "elser_embeddings_pipeline", }, }); console.log(response);
resp = client.reindex( wait_for_completion=False, source={ "index": "test-data", "size": 50 }, dest={ "index": "hugging-face-embeddings", "pipeline": "hugging_face_embeddings_pipeline" }, ) print(resp)
const response = await client.reindex({ wait_for_completion: "false", source: { index: "test-data", size: 50, }, dest: { index: "hugging-face-embeddings", pipeline: "hugging_face_embeddings_pipeline", }, }); console.log(response);
resp = client.reindex( wait_for_completion=False, source={ "index": "test-data", "size": 50 }, dest={ "index": "openai-embeddings", "pipeline": "openai_embeddings_pipeline" }, ) print(resp)
const response = await client.reindex({ wait_for_completion: "false", source: { index: "test-data", size: 50, }, dest: { index: "openai-embeddings", pipeline: "openai_embeddings_pipeline", }, }); console.log(response);
POST _reindex?wait_for_completion=false { "source": { "index": "test-data", "size": 50 }, "dest": { "index": "openai-embeddings", "pipeline": "openai_embeddings_pipeline" } }
The default batch size for reindexing is 1000. Reducing |
The
rate limit of your OpenAI account
may affect the throughput of the reindexing process. If this happens, change
size
to 3
or a similar value in magnitude.
resp = client.reindex( wait_for_completion=False, source={ "index": "test-data", "size": 50 }, dest={ "index": "azure-openai-embeddings", "pipeline": "azure_openai_embeddings_pipeline" }, ) print(resp)
const response = await client.reindex({ wait_for_completion: "false", source: { index: "test-data", size: 50, }, dest: { index: "azure-openai-embeddings", pipeline: "azure_openai_embeddings_pipeline", }, }); console.log(response);
POST _reindex?wait_for_completion=false { "source": { "index": "test-data", "size": 50 }, "dest": { "index": "azure-openai-embeddings", "pipeline": "azure_openai_embeddings_pipeline" } }
The default batch size for reindexing is 1000. Reducing |
The
rate limit of your Azure OpenAI account
may affect the throughput of the reindexing process. If this happens, change
size
to 3
or a similar value in magnitude.
resp = client.reindex( wait_for_completion=False, source={ "index": "test-data", "size": 50 }, dest={ "index": "azure-ai-studio-embeddings", "pipeline": "azure_ai_studio_embeddings_pipeline" }, ) print(resp)
const response = await client.reindex({ wait_for_completion: "false", source: { index: "test-data", size: 50, }, dest: { index: "azure-ai-studio-embeddings", pipeline: "azure_ai_studio_embeddings_pipeline", }, }); console.log(response);
POST _reindex?wait_for_completion=false { "source": { "index": "test-data", "size": 50 }, "dest": { "index": "azure-ai-studio-embeddings", "pipeline": "azure_ai_studio_embeddings_pipeline" } }
The default batch size for reindexing is 1000. Reducing |
Your Azure AI Studio model deployment may have rate limits in place that
might affect the throughput of the reindexing process. If this happens, change
size
to 3
or a similar value in magnitude.
resp = client.reindex( wait_for_completion=False, source={ "index": "test-data", "size": 50 }, dest={ "index": "google-vertex-ai-embeddings", "pipeline": "google_vertex_ai_embeddings_pipeline" }, ) print(resp)
const response = await client.reindex({ wait_for_completion: "false", source: { index: "test-data", size: 50, }, dest: { index: "google-vertex-ai-embeddings", pipeline: "google_vertex_ai_embeddings_pipeline", }, }); console.log(response);
resp = client.reindex( wait_for_completion=False, source={ "index": "test-data", "size": 50 }, dest={ "index": "mistral-embeddings", "pipeline": "mistral_embeddings_pipeline" }, ) print(resp)
const response = await client.reindex({ wait_for_completion: "false", source: { index: "test-data", size: 50, }, dest: { index: "mistral-embeddings", pipeline: "mistral_embeddings_pipeline", }, }); console.log(response);
resp = client.reindex( wait_for_completion=False, source={ "index": "test-data", "size": 50 }, dest={ "index": "amazon-bedrock-embeddings", "pipeline": "amazon_bedrock_embeddings_pipeline" }, ) print(resp)
const response = await client.reindex({ wait_for_completion: "false", source: { index: "test-data", size: 50, }, dest: { index: "amazon-bedrock-embeddings", pipeline: "amazon_bedrock_embeddings_pipeline", }, }); console.log(response);
resp = client.reindex( wait_for_completion=False, source={ "index": "test-data", "size": 50 }, dest={ "index": "alibabacloud-ai-search-embeddings", "pipeline": "alibabacloud_ai_search_embeddings_pipeline" }, ) print(resp)
const response = await client.reindex({ wait_for_completion: "false", source: { index: "test-data", size: 50, }, dest: { index: "alibabacloud-ai-search-embeddings", pipeline: "alibabacloud_ai_search_embeddings_pipeline", }, }); console.log(response);
The call returns a task ID to monitor the progress:
resp = client.tasks.get( task_id="<task_id>", ) print(resp)
const response = await client.tasks.get({ task_id: "<task_id>", }); console.log(response);
GET _tasks/<task_id>
Reindexing large datasets can take a long time. You can test this workflow using only a subset of the dataset. Do this by cancelling the reindexing process, and only generating embeddings for the subset that was reindexed. The following API request will cancel the reindexing task:
resp = client.tasks.cancel( task_id="<task_id>", ) print(resp)
const response = await client.tasks.cancel({ task_id: "<task_id>", }); console.log(response);
POST _tasks/<task_id>/_cancel
Semantic search
editAfter the data set has been enriched with the embeddings, you can query the data using semantic search.
In case of dense vector models, pass a query_vector_builder
to the k-nearest neighbor (kNN) vector search API, and provide the query text and the model you have used to create the embeddings.
In case of a sparse vector model like ELSER, use a sparse_vector
query, and provide the query text with the model you have used to create the embeddings.
If you cancelled the reindexing process, you run the query only a part of the data which affects the quality of your results.
resp = client.search( index="cohere-embeddings", knn={ "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "cohere_embeddings", "model_text": "Muscles in human body" } }, "k": 10, "num_candidates": 100 }, source=[ "id", "content" ], ) print(resp)
response = client.search( index: 'cohere-embeddings', body: { knn: { field: 'content_embedding', query_vector_builder: { text_embedding: { model_id: 'cohere_embeddings', model_text: 'Muscles in human body' } }, k: 10, num_candidates: 100 }, _source: [ 'id', 'content' ] } ) puts response
const response = await client.search({ index: "cohere-embeddings", knn: { field: "content_embedding", query_vector_builder: { text_embedding: { model_id: "cohere_embeddings", model_text: "Muscles in human body", }, }, k: 10, num_candidates: 100, }, _source: ["id", "content"], }); console.log(response);
GET cohere-embeddings/_search { "knn": { "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "cohere_embeddings", "model_text": "Muscles in human body" } }, "k": 10, "num_candidates": 100 }, "_source": [ "id", "content" ] }
As a result, you receive the top 10 documents that are closest in meaning to the
query from the cohere-embeddings
index sorted by their proximity to the query:
"hits": [ { "_index": "cohere-embeddings", "_id": "-eFWCY4BECzWLnMZuI78", "_score": 0.737484, "_source": { "id": 1690948, "content": "Oxygen is supplied to the muscles via red blood cells. Red blood cells carry hemoglobin which oxygen bonds with as the hemoglobin rich blood cells pass through the blood vessels of the lungs.The now oxygen rich blood cells carry that oxygen to the cells that are demanding it, in this case skeletal muscle cells.ther ways in which muscles are supplied with oxygen include: 1 Blood flow from the heart is increased. 2 Blood flow to your muscles in increased. 3 Blood flow from nonessential organs is transported to working muscles." } }, { "_index": "cohere-embeddings", "_id": "HuFWCY4BECzWLnMZuI_8", "_score": 0.7176013, "_source": { "id": 1692482, "content": "The thoracic cavity is separated from the abdominal cavity by the diaphragm. This is a broad flat muscle. (muscular) diaphragm The diaphragm is a muscle that separat…e the thoracic from the abdominal cavity. The pelvis is the lowest part of the abdominal cavity and it has no physical separation from it Diaphragm." } }, { "_index": "cohere-embeddings", "_id": "IOFWCY4BECzWLnMZuI_8", "_score": 0.7154432, "_source": { "id": 1692489, "content": "Muscular Wall Separating the Abdominal and Thoracic Cavities; Thoracic Cavity of a Fetal Pig; In Mammals the Diaphragm Separates the Abdominal Cavity from the" } }, { "_index": "cohere-embeddings", "_id": "C-FWCY4BECzWLnMZuI_8", "_score": 0.695313, "_source": { "id": 1691493, "content": "Burning, aching, tenderness and stiffness are just some descriptors of the discomfort you may feel in the muscles you exercised one to two days ago.For the most part, these sensations you experience after exercise are collectively known as delayed onset muscle soreness.urning, aching, tenderness and stiffness are just some descriptors of the discomfort you may feel in the muscles you exercised one to two days ago." } }, (...) ]
resp = client.search( index="elser-embeddings", query={ "sparse_vector": { "field": "content_embedding", "inference_id": "elser_embeddings", "query": "How to avoid muscle soreness after running?" } }, source=[ "id", "content" ], ) print(resp)
const response = await client.search({ index: "elser-embeddings", query: { sparse_vector: { field: "content_embedding", inference_id: "elser_embeddings", query: "How to avoid muscle soreness after running?", }, }, _source: ["id", "content"], }); console.log(response);
GET elser-embeddings/_search { "query":{ "sparse_vector":{ "field": "content_embedding", "inference_id": "elser_embeddings", "query": "How to avoid muscle soreness after running?" } }, "_source": [ "id", "content" ] }
As a result, you receive the top 10 documents that are closest in meaning to the
query from the cohere-embeddings
index sorted by their proximity to the query:
"hits": [ { "_index": "elser-embeddings", "_id": "ZLGc_pABZbBmsu5_eCoH", "_score": 21.472063, "_source": { "id": 2258240, "content": "You may notice some muscle aches while you are exercising. This is called acute soreness. More often, you may begin to feel sore about 12 hours after exercising, and the discomfort usually peaks at 48 to 72 hours after exercise. This is called delayed-onset muscle soreness.It is thought that, during this time, your body is repairing the muscle, making it stronger and bigger.You may also notice the muscles feel better if you exercise lightly. This is normal.his is called delayed-onset muscle soreness. It is thought that, during this time, your body is repairing the muscle, making it stronger and bigger. You may also notice the muscles feel better if you exercise lightly. This is normal." } }, { "_index": "elser-embeddings", "_id": "ZbGc_pABZbBmsu5_eCoH", "_score": 21.421381, "_source": { "id": 2258242, "content": "Photo Credit Jupiterimages/Stockbyte/Getty Images. That stiff, achy feeling you get in the days after exercise is a normal physiological response known as delayed onset muscle soreness. You can take it as a positive sign that your muscles have felt the workout, but the pain may also turn you off to further exercise.ou are more likely to develop delayed onset muscle soreness if you are new to working out, if you’ve gone a long time without exercising and start up again, if you have picked up a new type of physical activity or if you have recently boosted the intensity, length or frequency of your exercise sessions." } }, { "_index": "elser-embeddings", "_id": "ZrGc_pABZbBmsu5_eCoH", "_score": 20.542095, "_source": { "id": 2258248, "content": "They found that stretching before and after exercise has no effect on muscle soreness. Exercise might cause inflammation, which leads to an increase in the production of immune cells (comprised mostly of macrophages and neutrophils). Levels of these immune cells reach a peak 24-48 hours after exercise.These cells, in turn, produce bradykinins and prostaglandins, which make the pain receptors in your body more sensitive. Whenever you move, these pain receptors are stimulated.hey found that stretching before and after exercise has no effect on muscle soreness. Exercise might cause inflammation, which leads to an increase in the production of immune cells (comprised mostly of macrophages and neutrophils). Levels of these immune cells reach a peak 24-48 hours after exercise." } }, (...) ]
resp = client.search( index="hugging-face-embeddings", knn={ "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "hugging_face_embeddings", "model_text": "What's margin of error?" } }, "k": 10, "num_candidates": 100 }, source=[ "id", "content" ], ) print(resp)
response = client.search( index: 'hugging-face-embeddings', body: { knn: { field: 'content_embedding', query_vector_builder: { text_embedding: { model_id: 'hugging_face_embeddings', model_text: "What's margin of error?" } }, k: 10, num_candidates: 100 }, _source: [ 'id', 'content' ] } ) puts response
const response = await client.search({ index: "hugging-face-embeddings", knn: { field: "content_embedding", query_vector_builder: { text_embedding: { model_id: "hugging_face_embeddings", model_text: "What's margin of error?", }, }, k: 10, num_candidates: 100, }, _source: ["id", "content"], }); console.log(response);
GET hugging-face-embeddings/_search { "knn": { "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "hugging_face_embeddings", "model_text": "What's margin of error?" } }, "k": 10, "num_candidates": 100 }, "_source": [ "id", "content" ] }
As a result, you receive the top 10 documents that are closest in meaning to the
query from the hugging-face-embeddings
index sorted by their proximity to the query:
"hits": [ { "_index": "hugging-face-embeddings", "_id": "ljEfo44BiUQvMpPgT20E", "_score": 0.8522128, "_source": { "id": 7960255, "content": "The margin of error can be defined by either of the following equations. Margin of error = Critical value x Standard deviation of the statistic. Margin of error = Critical value x Standard error of the statistic. If you know the standard deviation of the statistic, use the first equation to compute the margin of error. Otherwise, use the second equation. Previously, we described how to compute the standard deviation and standard error." } }, { "_index": "hugging-face-embeddings", "_id": "lzEfo44BiUQvMpPgT20E", "_score": 0.7865497, "_source": { "id": 7960259, "content": "1 y ou are told only the size of the sample and are asked to provide the margin of error for percentages which are not (yet) known. 2 This is typically the case when you are computing the margin of error for a survey which is going to be conducted in the future." } }, { "_index": "hugging-face-embeddings1", "_id": "DjEfo44BiUQvMpPgT20E", "_score": 0.6229427, "_source": { "id": 2166183, "content": "1. In general, the point at which gains equal losses. 2. In options, the market price that a stock must reach for option buyers to avoid a loss if they exercise. For a call, it is the strike price plus the premium paid. For a put, it is the strike price minus the premium paid." } }, { "_index": "hugging-face-embeddings1", "_id": "VzEfo44BiUQvMpPgT20E", "_score": 0.6034223, "_source": { "id": 2173417, "content": "How do you find the area of a circle? Can you measure the area of a circle and use that to find a value for Pi?" } }, (...) ]
resp = client.search( index="openai-embeddings", knn={ "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "openai_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, source=[ "id", "content" ], ) print(resp)
response = client.search( index: 'openai-embeddings', body: { knn: { field: 'content_embedding', query_vector_builder: { text_embedding: { model_id: 'openai_embeddings', model_text: 'Calculate fuel cost' } }, k: 10, num_candidates: 100 }, _source: [ 'id', 'content' ] } ) puts response
const response = await client.search({ index: "openai-embeddings", knn: { field: "content_embedding", query_vector_builder: { text_embedding: { model_id: "openai_embeddings", model_text: "Calculate fuel cost", }, }, k: 10, num_candidates: 100, }, _source: ["id", "content"], }); console.log(response);
GET openai-embeddings/_search { "knn": { "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "openai_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, "_source": [ "id", "content" ] }
As a result, you receive the top 10 documents that are closest in meaning to the
query from the openai-embeddings
index sorted by their proximity to the query:
"hits": [ { "_index": "openai-embeddings", "_id": "DDd5OowBHxQKHyc3TDSC", "_score": 0.83704096, "_source": { "id": 862114, "body": "How to calculate fuel cost for a road trip. By Tara Baukus Mello • Bankrate.com. Dear Driving for Dollars, My family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost.It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes.y family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost. It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes." } }, { "_index": "openai-embeddings", "_id": "ajd5OowBHxQKHyc3TDSC", "_score": 0.8345704, "_source": { "id": 820622, "body": "Home Heating Calculator. Typically, approximately 50% of the energy consumed in a home annually is for space heating. When deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important.This calculator can help you estimate the cost of fuel for different heating appliances.hen deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important. This calculator can help you estimate the cost of fuel for different heating appliances." } }, { "_index": "openai-embeddings", "_id": "Djd5OowBHxQKHyc3TDSC", "_score": 0.8327426, "_source": { "id": 8202683, "body": "Fuel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel.If you are paying $4 per gallon, the trip would cost you $200.Most boats have much larger gas tanks than cars.uel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel." } }, (...) ]
resp = client.search( index="azure-openai-embeddings", knn={ "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "azure_openai_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, source=[ "id", "content" ], ) print(resp)
response = client.search( index: 'azure-openai-embeddings', body: { knn: { field: 'content_embedding', query_vector_builder: { text_embedding: { model_id: 'azure_openai_embeddings', model_text: 'Calculate fuel cost' } }, k: 10, num_candidates: 100 }, _source: [ 'id', 'content' ] } ) puts response
const response = await client.search({ index: "azure-openai-embeddings", knn: { field: "content_embedding", query_vector_builder: { text_embedding: { model_id: "azure_openai_embeddings", model_text: "Calculate fuel cost", }, }, k: 10, num_candidates: 100, }, _source: ["id", "content"], }); console.log(response);
GET azure-openai-embeddings/_search { "knn": { "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "azure_openai_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, "_source": [ "id", "content" ] }
As a result, you receive the top 10 documents that are closest in meaning to the
query from the azure-openai-embeddings
index sorted by their proximity to the query:
"hits": [ { "_index": "azure-openai-embeddings", "_id": "DDd5OowBHxQKHyc3TDSC", "_score": 0.83704096, "_source": { "id": 862114, "body": "How to calculate fuel cost for a road trip. By Tara Baukus Mello • Bankrate.com. Dear Driving for Dollars, My family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost.It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes.y family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost. It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes." } }, { "_index": "azure-openai-embeddings", "_id": "ajd5OowBHxQKHyc3TDSC", "_score": 0.8345704, "_source": { "id": 820622, "body": "Home Heating Calculator. Typically, approximately 50% of the energy consumed in a home annually is for space heating. When deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important.This calculator can help you estimate the cost of fuel for different heating appliances.hen deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important. This calculator can help you estimate the cost of fuel for different heating appliances." } }, { "_index": "azure-openai-embeddings", "_id": "Djd5OowBHxQKHyc3TDSC", "_score": 0.8327426, "_source": { "id": 8202683, "body": "Fuel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel.If you are paying $4 per gallon, the trip would cost you $200.Most boats have much larger gas tanks than cars.uel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel." } }, (...) ]
resp = client.search( index="azure-ai-studio-embeddings", knn={ "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "azure_ai_studio_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, source=[ "id", "content" ], ) print(resp)
const response = await client.search({ index: "azure-ai-studio-embeddings", knn: { field: "content_embedding", query_vector_builder: { text_embedding: { model_id: "azure_ai_studio_embeddings", model_text: "Calculate fuel cost", }, }, k: 10, num_candidates: 100, }, _source: ["id", "content"], }); console.log(response);
GET azure-ai-studio-embeddings/_search { "knn": { "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "azure_ai_studio_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, "_source": [ "id", "content" ] }
As a result, you receive the top 10 documents that are closest in meaning to the
query from the azure-ai-studio-embeddings
index sorted by their proximity to the query:
"hits": [ { "_index": "azure-ai-studio-embeddings", "_id": "DDd5OowBHxQKHyc3TDSC", "_score": 0.83704096, "_source": { "id": 862114, "body": "How to calculate fuel cost for a road trip. By Tara Baukus Mello • Bankrate.com. Dear Driving for Dollars, My family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost.It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes.y family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost. It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes." } }, { "_index": "azure-ai-studio-embeddings", "_id": "ajd5OowBHxQKHyc3TDSC", "_score": 0.8345704, "_source": { "id": 820622, "body": "Home Heating Calculator. Typically, approximately 50% of the energy consumed in a home annually is for space heating. When deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important.This calculator can help you estimate the cost of fuel for different heating appliances.hen deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important. This calculator can help you estimate the cost of fuel for different heating appliances." } }, { "_index": "azure-ai-studio-embeddings", "_id": "Djd5OowBHxQKHyc3TDSC", "_score": 0.8327426, "_source": { "id": 8202683, "body": "Fuel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel.If you are paying $4 per gallon, the trip would cost you $200.Most boats have much larger gas tanks than cars.uel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel." } }, (...) ]
resp = client.search( index="google-vertex-ai-embeddings", knn={ "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "google_vertex_ai_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, source=[ "id", "content" ], ) print(resp)
const response = await client.search({ index: "google-vertex-ai-embeddings", knn: { field: "content_embedding", query_vector_builder: { text_embedding: { model_id: "google_vertex_ai_embeddings", model_text: "Calculate fuel cost", }, }, k: 10, num_candidates: 100, }, _source: ["id", "content"], }); console.log(response);
GET google-vertex-ai-embeddings/_search { "knn": { "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "google_vertex_ai_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, "_source": [ "id", "content" ] }
As a result, you receive the top 10 documents that are closest in meaning to the
query from the mistral-embeddings
index sorted by their proximity to the query:
"hits": [ { "_index": "google-vertex-ai-embeddings", "_id": "Ryv0nZEBBFPLbFsdCbGn", "_score": 0.86815524, "_source": { "id": 3041038, "content": "For example, the cost of the fuel could be 96.9, the amount could be 10 pounds, and the distance covered could be 80 miles. To convert between Litres per 100KM and Miles Per Gallon, please provide a value and click on the required button.o calculate how much fuel you'll need for a given journey, please provide the distance in miles you will be covering on your journey, and the estimated MPG of your vehicle. To work out what MPG you are really getting, please provide the cost of the fuel, how much you spent on the fuel, and how far it took you." } }, { "_index": "google-vertex-ai-embeddings", "_id": "w4j0nZEBZ1nFq1oiHQvK", "_score": 0.8676357, "_source": { "id": 1541469, "content": "This driving cost calculator takes into consideration the fuel economy of the vehicle that you are travelling in as well as the fuel cost. This road trip gas calculator will give you an idea of how much would it cost to drive before you actually travel.his driving cost calculator takes into consideration the fuel economy of the vehicle that you are travelling in as well as the fuel cost. This road trip gas calculator will give you an idea of how much would it cost to drive before you actually travel." } }, { "_index": "google-vertex-ai-embeddings", "_id": "Hoj0nZEBZ1nFq1oiHQjJ", "_score": 0.80510974, "_source": { "id": 7982559, "content": "What's that light cost you? 1 Select your electric rate (or click to enter your own). 2 You can calculate results for up to four types of lights. 3 Select the type of lamp (i.e. 4 Select the lamp wattage (lamp lumens). 5 Enter the number of lights in use. 6 Select how long the lamps are in use (or click to enter your own; enter hours on per year). 7 Finally, ..." } }, (...) ]
resp = client.search( index="mistral-embeddings", knn={ "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "mistral_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, source=[ "id", "content" ], ) print(resp)
const response = await client.search({ index: "mistral-embeddings", knn: { field: "content_embedding", query_vector_builder: { text_embedding: { model_id: "mistral_embeddings", model_text: "Calculate fuel cost", }, }, k: 10, num_candidates: 100, }, _source: ["id", "content"], }); console.log(response);
GET mistral-embeddings/_search { "knn": { "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "mistral_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, "_source": [ "id", "content" ] }
As a result, you receive the top 10 documents that are closest in meaning to the
query from the mistral-embeddings
index sorted by their proximity to the query:
"hits": [ { "_index": "mistral-embeddings", "_id": "DDd5OowBHxQKHyc3TDSC", "_score": 0.83704096, "_source": { "id": 862114, "body": "How to calculate fuel cost for a road trip. By Tara Baukus Mello • Bankrate.com. Dear Driving for Dollars, My family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost.It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes.y family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost. It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes." } }, { "_index": "mistral-embeddings", "_id": "ajd5OowBHxQKHyc3TDSC", "_score": 0.8345704, "_source": { "id": 820622, "body": "Home Heating Calculator. Typically, approximately 50% of the energy consumed in a home annually is for space heating. When deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important.This calculator can help you estimate the cost of fuel for different heating appliances.hen deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important. This calculator can help you estimate the cost of fuel for different heating appliances." } }, { "_index": "mistral-embeddings", "_id": "Djd5OowBHxQKHyc3TDSC", "_score": 0.8327426, "_source": { "id": 8202683, "body": "Fuel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel.If you are paying $4 per gallon, the trip would cost you $200.Most boats have much larger gas tanks than cars.uel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel." } }, (...) ]
resp = client.search( index="amazon-bedrock-embeddings", knn={ "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "amazon_bedrock_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, source=[ "id", "content" ], ) print(resp)
const response = await client.search({ index: "amazon-bedrock-embeddings", knn: { field: "content_embedding", query_vector_builder: { text_embedding: { model_id: "amazon_bedrock_embeddings", model_text: "Calculate fuel cost", }, }, k: 10, num_candidates: 100, }, _source: ["id", "content"], }); console.log(response);
GET amazon-bedrock-embeddings/_search { "knn": { "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "amazon_bedrock_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, "_source": [ "id", "content" ] }
As a result, you receive the top 10 documents that are closest in meaning to the
query from the amazon-bedrock-embeddings
index sorted by their proximity to the query:
"hits": [ { "_index": "amazon-bedrock-embeddings", "_id": "DDd5OowBHxQKHyc3TDSC", "_score": 0.83704096, "_source": { "id": 862114, "body": "How to calculate fuel cost for a road trip. By Tara Baukus Mello • Bankrate.com. Dear Driving for Dollars, My family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost.It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes.y family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost. It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes." } }, { "_index": "amazon-bedrock-embeddings", "_id": "ajd5OowBHxQKHyc3TDSC", "_score": 0.8345704, "_source": { "id": 820622, "body": "Home Heating Calculator. Typically, approximately 50% of the energy consumed in a home annually is for space heating. When deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important.This calculator can help you estimate the cost of fuel for different heating appliances.hen deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important. This calculator can help you estimate the cost of fuel for different heating appliances." } }, { "_index": "amazon-bedrock-embeddings", "_id": "Djd5OowBHxQKHyc3TDSC", "_score": 0.8327426, "_source": { "id": 8202683, "body": "Fuel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel.If you are paying $4 per gallon, the trip would cost you $200.Most boats have much larger gas tanks than cars.uel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel." } }, (...) ]
resp = client.search( index="alibabacloud-ai-search-embeddings", knn={ "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "alibabacloud_ai_search_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, source=[ "id", "content" ], ) print(resp)
const response = await client.search({ index: "alibabacloud-ai-search-embeddings", knn: { field: "content_embedding", query_vector_builder: { text_embedding: { model_id: "alibabacloud_ai_search_embeddings", model_text: "Calculate fuel cost", }, }, k: 10, num_candidates: 100, }, _source: ["id", "content"], }); console.log(response);
GET alibabacloud-ai-search-embeddings/_search { "knn": { "field": "content_embedding", "query_vector_builder": { "text_embedding": { "model_id": "alibabacloud_ai_search_embeddings", "model_text": "Calculate fuel cost" } }, "k": 10, "num_candidates": 100 }, "_source": [ "id", "content" ] }
As a result, you receive the top 10 documents that are closest in meaning to the
query from the alibabacloud-ai-search-embeddings
index sorted by their proximity to the query:
"hits": [ { "_index": "alibabacloud-ai-search-embeddings", "_id": "DDd5OowBHxQKHyc3TDSC", "_score": 0.83704096, "_source": { "id": 862114, "body": "How to calculate fuel cost for a road trip. By Tara Baukus Mello • Bankrate.com. Dear Driving for Dollars, My family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost.It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes.y family is considering taking a long road trip to finish off the end of the summer, but I'm a little worried about gas prices and our overall fuel cost. It doesn't seem easy to calculate since we'll be traveling through many states and we are considering several routes." } }, { "_index": "alibabacloud-ai-search-embeddings", "_id": "ajd5OowBHxQKHyc3TDSC", "_score": 0.8345704, "_source": { "id": 820622, "body": "Home Heating Calculator. Typically, approximately 50% of the energy consumed in a home annually is for space heating. When deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important.This calculator can help you estimate the cost of fuel for different heating appliances.hen deciding on a heating system, many factors will come into play: cost of fuel, installation cost, convenience and life style are all important. This calculator can help you estimate the cost of fuel for different heating appliances." } }, { "_index": "alibabacloud-ai-search-embeddings", "_id": "Djd5OowBHxQKHyc3TDSC", "_score": 0.8327426, "_source": { "id": 8202683, "body": "Fuel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel.If you are paying $4 per gallon, the trip would cost you $200.Most boats have much larger gas tanks than cars.uel is another important cost. This cost will depend on your boat, how far you travel, and how fast you travel. A 33-foot sailboat traveling at 7 knots should be able to travel 300 miles on 50 gallons of diesel fuel." } }, (...) ]
Interactive tutorials
editYou can also find tutorials in an interactive Colab notebook format using the Elasticsearch Python client: