Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,20 @@ The instructions in this tutorial shows you how to use the {infer} API workflow

IMPORTANT: For the easiest way to perform semantic search in the {stack}, refer to the <<semantic-search-semantic-text, `semantic_text`>> end-to-end tutorial.

The following examples use Cohere's `embed-english-v3.0` model, the `all-mpnet-base-v2` model from HuggingFace, and OpenAI's `text-embedding-ada-002` second generation embedding model.
The following examples use the:

* `embed-english-v3.0` model for https://docs.cohere.com/docs/cohere-embed[Cohere]
* `all-mpnet-base-v2` model from https://huggingface.co/sentence-transformers/all-mpnet-base-v2[HuggingFace]
* `text-embedding-ada-002` second generation embedding model for OpenAI
* models available through https://ai.azure.com/explore/models?selectedTask=embeddings[Azure AI Studio] or https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models[Azure OpenAI]
* `text-embedding-004` model for https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/text-embeddings-api[Google Vertex AI]
* `mistral-embed` model for https://docs.mistral.ai/getting-started/models/[Mistral]
* `amazon.titan-embed-text-v1` model for https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html[Amazon Bedrock]
* `ops-text-embedding-zh-001` model for https://help.aliyun.com/zh/open-search/search-platform/developer-reference/text-embedding-api-details[AlibabaCloud AI]

You can use any Cohere and OpenAI models, they are all supported by the {infer} API.
For a list of recommended models available on HuggingFace, refer to <<inference-example-hugging-face-supported-models, the supported model list>>.

Azure based examples use models available through https://ai.azure.com/explore/models?selectedTask=embeddings[Azure AI Studio]
or https://learn.microsoft.com/en-us/azure/ai-services/openai/concepts/models[Azure OpenAI].
Mistral examples use the `mistral-embed` model from https://docs.mistral.ai/getting-started/models/[the Mistral API].
Amazon Bedrock examples use the `amazon.titan-embed-text-v1` model from https://docs.aws.amazon.com/bedrock/latest/userguide/model-ids.html[the Amazon Bedrock base models].
AlibabaCloud AI Search examples use the `ops-text-embedding-zh-001` model from https://help.aliyun.com/zh/open-search/search-platform/developer-reference/text-embedding-api-details[the AlibabaCloud AI Search base models].

Click the name of the service you want to use on any of the widgets below to review the corresponding instructions.

[discrete]
Expand Down Expand Up @@ -74,8 +78,8 @@ Once the upload is complete, you can see an index named `test-data` with 182469
[[reindexing-data-infer]]
==== Ingest the data through the {infer} ingest pipeline

Create the embeddings from the text by reindexing the data through the {infer}
pipeline that uses the chosen model as the inference model.
Create embeddings from the text by reindexing the data through the {infer} pipeline that uses your chosen model.
This step uses the {ref}/docs-reindex.html[reindex API] to simulate data ingestion through a pipeline.

include::{es-ref-dir}/tab-widgets/inference-api/infer-api-reindex-widget.asciidoc[]

Expand Down Expand Up @@ -114,5 +118,6 @@ include::{es-ref-dir}/tab-widgets/inference-api/infer-api-search-widget.asciidoc

You can also find tutorials in an interactive Colab notebook format using the
{es} Python client:

* https://colab.research.google.com/github/elastic/elasticsearch-labs/blob/main/notebooks/integrations/cohere/inference-cohere.ipynb[Cohere {infer} tutorial notebook]
* https://colab.research.google.com/github/elastic/elasticsearch-labs/blob/main/notebooks/search/07-inference.ipynb[OpenAI {infer} tutorial notebook]
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
id="infer-api-ingest-azure-ai-studio">
Azure AI Studio
</button>
<button role="tab"
aria-selected="false"
aria-controls="infer-api-ingest-google-vertex-ai-tab"
id="infer-api-ingest-google-vertex-ai">
Google Vertex AI
</button>
<button role="tab"
aria-selected="false"
aria-controls="infer-api-ingest-mistral-tab"
Expand Down Expand Up @@ -119,6 +125,17 @@ include::infer-api-ingest-pipeline.asciidoc[tag=azure-openai]

include::infer-api-ingest-pipeline.asciidoc[tag=azure-ai-studio]

++++
</div>
<div tabindex="0"
role="tabpanel"
id="infer-api-ingest-google-vertex-ai-tab"
aria-labelledby="infer-api-ingest-google-vertex-ai"
hidden="">
++++

include::infer-api-ingest-pipeline.asciidoc[tag=google-vertex-ai]

++++
</div>
<div tabindex="0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,32 @@ and the `output_field` that will contain the {infer} results.

// end::azure-ai-studio[]

// tag::google-vertex-ai[]

[source,console]
--------------------------------------------------
PUT _ingest/pipeline/google_vertex_ai_embeddings
{
"processors": [
{
"inference": {
"model_id": "google_vertex_ai_embeddings", <1>
"input_output": { <2>
"input_field": "content",
"output_field": "content_embedding"
}
}
}
]
}
--------------------------------------------------
<1> The name of the inference endpoint you created by using the
<<put-inference-api>>, it's referred to as `inference_id` in that step.
<2> Configuration object that defines the `input_field` for the {infer} process
and the `output_field` that will contain the {infer} results.

// end::google-vertex-ai[]

// tag::mistral[]

[source,console]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
id="infer-api-mapping-azure-ai-studio">
Azure AI Studio
</button>
<button role="tab"
aria-selected="false"
aria-controls="infer-api-mapping-google-vertex-ai-tab"
id="infer-api-mapping-google-vertex-ai">
Google Vertex AI
</button>
<button role="tab"
aria-selected="false"
aria-controls="infer-api-mapping-mistral-tab"
Expand Down Expand Up @@ -119,6 +125,17 @@ include::infer-api-mapping.asciidoc[tag=azure-openai]

include::infer-api-mapping.asciidoc[tag=azure-ai-studio]

++++
</div>
<div tabindex="0"
role="tabpanel"
id="infer-api-mapping-google-vertex-ai-tab"
aria-labelledby="infer-api-mapping-google-vertex-ai"
hidden="">
++++

include::infer-api-mapping.asciidoc[tag=google-vertex-ai]

++++
</div>
<div tabindex="0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,39 @@ the {infer} pipeline configuration in the next step.

// end::azure-ai-studio[]

// tag::google-vertex-ai[]

[source,console]
--------------------------------------------------
PUT google-vertex-ai-embeddings
{
"mappings": {
"properties": {
"content_embedding": { <1>
"type": "dense_vector", <2>
"dims": 768, <3>
"element_type": "float",
"similarity": "dot_product" <4>
},
"content": { <5>
"type": "text" <6>
}
}
}
}
--------------------------------------------------
<1> The name of the field to contain the generated embeddings. It must be referenced in the {infer} pipeline configuration in the next step.
<2> The field to contain the embeddings is a `dense_vector` field.
<3> The output dimensions of the model. This value may be found on the https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/text-embeddings-api[Google Vertex AI model reference].
The {infer} API attempts to calculate the output dimensions automatically if `dims` are not specified.
<4> For Google Vertex AI embeddings, the `dot_product` function should be used to calculate similarity.
<5> 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 {infer} pipeline configuration in the next step.
<6> The field type which is `text` in this example.

// end::google-vertex-ai[]

// tag::mistral[]

[source,console]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@
id="infer-api-reindex-azure-ai-studio">
Azure AI Studio
</button>
<button role="tab"
aria-selected="false"
aria-controls="infer-api-reindex-google-vertex-ai-tab"
id="infer-api-reindex-google-vertex-ai">
Google Vertex AI
</button>
<button role="tab"
aria-selected="false"
aria-controls="infer-api-reindex-mistral-tab"
Expand Down Expand Up @@ -119,6 +125,17 @@ include::infer-api-reindex.asciidoc[tag=azure-openai]

include::infer-api-reindex.asciidoc[tag=azure-ai-studio]

++++
</div>
<div tabindex="0"
role="tabpanel"
id="infer-api-reindex-google-vertex-ai-tab"
aria-labelledby="infer-api-reindex-google-vertex-ai"
hidden="">
++++

include::infer-api-reindex.asciidoc[tag=google-vertex-ai]

++++
</div>
<div tabindex="0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,28 @@ might affect the throughput of the reindexing process. If this happens, change

// end::azure-ai-studio[]

// tag::google-vertex-ai[]

[source,console]
----
POST _reindex?wait_for_completion=false
{
"source": {
"index": "test-data",
"size": 50 <1>
},
"dest": {
"index": "google-vertex-ai-embeddings",
"pipeline": "google_vertex_ai_embeddings"
}
}
----
// TEST[skip:TBD]
<1> The default batch size for reindexing is 1000. Reducing `size` will make updates to the reindexing process faster. This enables you to
follow the progress closely and detect errors early.

// end::google-vertex-ai[]

// tag::mistral[]

[source,console]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@
aria-selected="false"
aria-controls="infer-api-requirements-azure-ai-studio-tab"
id="infer-api-requirements-azure-ai-studio">
Azure AI Studio
Azure AI Studio
</button>
<button role="tab"
aria-selected="false"
aria-controls="infer-api-requirements-google-vertex-ai-tab"
id="infer-api-requirements-google-vertex-ai">
Google Vertex AI
</button>
<button role="tab"
aria-selected="false"
Expand Down Expand Up @@ -119,6 +125,17 @@ include::infer-api-requirements.asciidoc[tag=azure-openai]

include::infer-api-requirements.asciidoc[tag=azure-ai-studio]

++++
</div>
<div tabindex="0"
role="tabpanel"
id="infer-api-requirements-google-vertex-ai-tab"
aria-labelledby="infer-api-requirements-google-vertex-ai"
hidden="">
++++

include::infer-api-requirements.asciidoc[tag=google-vertex-ai]

++++
</div>
<div tabindex="0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,15 @@ You can apply for access to Azure OpenAI by completing the form at https://aka.m

// end::azure-ai-studio[]

// tag::google-vertex-ai[]
* A https://console.cloud.google.com/[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.

// end::google-vertex-ai[]

// tag::mistral[]
* A Mistral Account on https://console.mistral.ai/[La Plateforme]
* An API key generated for your account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
aria-controls="infer-api-search-azure-ai-studio-tab"
id="infer-api-search-azure-ai-studio">
Azure AI Studio
</button>
<button role="tab"
aria-selected="false"
aria-controls="infer-api-search-google-vertex-ai-tab"
id="infer-api-search-google-vertex-ai">
Google Vertex AI
</button>
<button role="tab"
aria-selected="false"
Expand Down Expand Up @@ -119,6 +125,17 @@ include::infer-api-search.asciidoc[tag=azure-openai]

include::infer-api-search.asciidoc[tag=azure-ai-studio]

++++
</div>
<div tabindex="0"
role="tabpanel"
id="infer-api-search-google-vertex-ai-tab"
aria-labelledby="infer-api-search-google-vertex-ai"
hidden="">
++++

include::infer-api-search.asciidoc[tag=google-vertex-ai]

++++
</div>
<div tabindex="0"
Expand Down
65 changes: 65 additions & 0 deletions docs/reference/tab-widgets/inference-api/infer-api-search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,71 @@ query from the `azure-ai-studio-embeddings` index sorted by their proximity to t

// end::azure-ai-studio[]

// tag::google-vertex-ai[]

[source,console]
--------------------------------------------------
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"
]
}
--------------------------------------------------
// TEST[skip:TBD]

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:

[source,console-result]
--------------------------------------------------
"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, ..."
}
},
(...)
]
--------------------------------------------------
// NOTCONSOLE

// end::google-vertex-ai[]

// tag::mistral[]

[source,console]
Expand Down
Loading