mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-25 15:47:23 -04:00
96 lines
No EOL
3.6 KiB
Text
96 lines
No EOL
3.6 KiB
Text
// tag::cohere[]
|
|
|
|
[source,console]
|
|
------------------------------------------------------------
|
|
PUT _inference/text_embedding/cohere_embeddings <1>
|
|
{
|
|
"service": "cohere",
|
|
"service_settings": {
|
|
"api_key": "<api_key>", <2>
|
|
"model_id": "embed-english-v3.0", <3>
|
|
"embedding_type": "byte"
|
|
}
|
|
}
|
|
------------------------------------------------------------
|
|
// TEST[skip:TBD]
|
|
<1> The task type is `text_embedding` in the path and the `inference_id` which
|
|
is the unique identifier of the {infer} endpoint is `cohere_embeddings`.
|
|
<2> The API key of your Cohere account. You can find your API keys in your
|
|
Cohere dashboard under the
|
|
https://dashboard.cohere.com/api-keys[API keys section]. You need to provide
|
|
your API key only once. The <<get-inference-api>> does not return your API
|
|
key.
|
|
<3> The name of the embedding model to use. You can find the list of Cohere
|
|
embedding models https://docs.cohere.com/reference/embed[here].
|
|
|
|
NOTE: 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.
|
|
|
|
|
|
|
|
// end::cohere[]
|
|
|
|
// tag::hugging-face[]
|
|
|
|
First, you need to create a new {infer} endpoint on
|
|
https://ui.endpoints.huggingface.co/[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 {infer} API
|
|
call.
|
|
|
|
[source,console]
|
|
------------------------------------------------------------
|
|
PUT _inference/text_embedding/hugging_face_embeddings <1>
|
|
{
|
|
"service": "hugging_face",
|
|
"service_settings": {
|
|
"api_key": "<access_token>", <2>
|
|
"url": "<url_endpoint>" <3>
|
|
}
|
|
}
|
|
------------------------------------------------------------
|
|
// TEST[skip:TBD]
|
|
<1> The task type is `text_embedding` in the path and the `inference_id` which
|
|
is the unique identifier of the {infer} endpoint is `hugging_face_embeddings`.
|
|
<2> A valid HuggingFace access token. You can find on the
|
|
https://huggingface.co/settings/tokens[settings page of your account].
|
|
<3> The {infer} endpoint URL you created on Hugging Face.
|
|
|
|
// end::hugging-face[]
|
|
|
|
|
|
// tag::openai[]
|
|
|
|
[source,console]
|
|
------------------------------------------------------------
|
|
PUT _inference/text_embedding/openai_embeddings <1>
|
|
{
|
|
"service": "openai",
|
|
"service_settings": {
|
|
"api_key": "<api_key>", <2>
|
|
"model_id": "text-embedding-ada-002" <3>
|
|
}
|
|
}
|
|
------------------------------------------------------------
|
|
// TEST[skip:TBD]
|
|
<1> The task type is `text_embedding` in the path and the `inference_id` which
|
|
is the unique identifier of the {infer} endpoint is `openai_embeddings`.
|
|
<2> The API key of your OpenAI account. You can find your OpenAI API keys in
|
|
your OpenAI account under the
|
|
https://platform.openai.com/api-keys[API keys section]. You need to provide
|
|
your API key only once. The <<get-inference-api>> does not return your API
|
|
key.
|
|
<3> The name of the embedding model to use. You can find the list of OpenAI
|
|
embedding models
|
|
https://platform.openai.com/docs/guides/embeddings/embedding-models[here].
|
|
|
|
NOTE: 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.
|
|
|
|
// end::openai[] |