Skip to main contentwatsonx Developer Hub

Embeddings

Free token limit increased!
New 300k token limit for all new, free trials to use for LLM API calls and more. Sign up for free here.

Overview

Use an embedding model and the embeddings API to create text embeddings that capture the meaning of sentences or passages for use in your generative AI applications. Converting text into text embeddings helps with document comparison, question-answering, and in retrieval-augmented generation (RAG) tasks, when you need to retrieve relevant content quickly.

Embedding models that are used for this API request are detailed in this list.

Example

The following example uses the slate-125m-english-rtrvr to generate embeddings from three lines of text input. Replace {token} and {watsonx_ai_url} with your information.

1curl -X POST \
2-H "Authorization: Bearer {token}" \
3-H "Accept: application/json" \
4-d "{
5  "inputs": [
6    \"Youth craves thrills while adulthood cherishes wisdom.\",
7    \"Youth seeks ambition while adulthood finds contentment.\",
8    \"Dreams chased in youth while goals pursued in adulthood.\"
9  ],
10  \"model_id": \"ibm/slate-125m-english-rtrvr\",
11  \"project_id": \"12ac4cf1-252f-424b-b52d-5cdd9814987f\"
12}" \
13"{watsonx_ai_url}/ml/v1/text/embeddings?version=2024-05-31"

Response

The response is an array of embeddings for each input string, as in this sample.

1{
2  "model_id": "ibm/slate-125m-english-rtrvr",
3  "results": [
4    {
5      "embedding": [-0.006929283, -0.005336422, -0.024047505]
6    }
7  ],
8  "created_at": "2024-02-21T17:32:28Z",
9  "input_token_count": 10
10}

Next steps

For more examples and information about the embeddings API, see the following links: