Skip to main content

Text Embedding

Text embedding tasks take a string as input and generates a list of embeddings for the sentences.

info

For a detailed API reference for text embedding, please refer to API Reference.

Specify the model of your choice

TaskingAI-Inference has integrated a wide range of models from different providers. Different models perform differently and are suitable for different tasks. To specify the model you want to use, you need to provide the provider_id and provider_model_id in the body of the request.

Here's an example to specify using the 'embed-english-light-v2.0' model from Cohere:

{
...
"provider_id": "cohere",
"provider_model_id": "embed-english-light-v2.0",
... other parameters in body
}

For a full list of provider and models, please refer to Provider and Model.

Set up credentials

To access the models provided by the LLM providers through TaskingAI, your API Key toward your chosen provider is required. All credentials should be passed under the credentials field in the body of the request.

Here's an example of passing credentials for accessing Cohere's models:

{
"credentials": {
"COHERE_API_KEY": "{{COHERE_API_KEY}}"
},
... other parameters in body
}

For a full list of credentials required for each provider, please refer to Credentials. Note: you don't need to pass all the credentials on the table, only the one required by your chosen provider is enough.

Input sequences

Input sequences are the input for the text embedding task. It is a list of sentences that you want to embed. The sequences to be embedded should be passed under the input field in the body of the request.

An example of requests body with two items in input can be:

{   
"provider_id": "cohere",
"provider_model_id": "embed-english-light-v2.0",
"credentials": {
"COHERE_API_KEY": "$COHERE_API_KEY"
},
"input": [
"The earth has been existing for 4.5 billion years, ...",
"The galaxy is 13.8 billion years old, ..."
]
}

Request Example

curl --location 'http://127.0.0.1:8000/v1/text_embedding' \
--header 'Content-Type: application/json' \
--data '{
"model_schema_id": "openai/text-embedding-ada-002",
"input": ["hello, nice to meet you", "i'\''m fine thank you"],
"credentials": {
"OPENAI_API_KEY": "YOUR_OPENAI_API_KEY"
}
}'

Response

The response of the text embedding task is a list of embeddings for the input sequences. And each embedding result is a list of floats. The response is in the following format:

{
"data": [
{
"index": 0,
"embedding": [0.1, 0.2, 0.3, ...]
},
{
"index": 1,
"embedding": [0.4, 0.5, 0.6, ...]
}
]
}