Convert text into numerical vector representations that capture semantic meaning. This is essential for building search systems, recommendation engines, and similarity detection features.
Embeddings are high-dimensional vectors (typically 384 to 1536 dimensions) that encode semantic meaning. Similar texts will have similar embeddings, making them perfect for semantic search and clustering tasks.
Prerequisites
- A Paradigm API key: if you do not have one, go to your Paradigm profile (
/settings/api-key
in your instance) and generate a new API key.
- The desired embedding model available in Paradigm: By default the embedding model used for the chat with docs should be available. If you want to use another embedding model, you must add it to Paradigm from the admin interface.
Use the same embedding model consistently across your application. Mixing embeddings from different models will produce unreliable similarity results.
Usage methods
There are several ways to call the endpoint:
- With the python
requests
package
- Through a curl request: for quick testing or first-time use
Python requests
package
You can directly send request to the API endpoint through the requests
package.
import requests
import os
# Get API key and base URL from environment
api_key = os.getenv("PARADIGM_API_KEY")
base_url = os.getenv("PARADIGM_BASE_URL", "https://paradigm.lighton.ai/api/v2")
response = requests.request(
method="POST",
url=f"{base_url}/embeddings",
headers={
'accept': "application/json",
'Authorization': f"Bearer {api_key}"
},
json={
"model": "multilingual-e5-large",
"input": "This a test string"
}
)
print(response.json())
You would then get a JSON answer as a dictionary:
{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [
0.0071225623,
-0.008990367,
"...",
-0.023343408,
0.016777039
],
"index": 0
}
],
"model": "multilingual-e5-large",
"usage": {
"prompt_tokens": 6,
"total_tokens": 6
},
"id": "fe922faf-50bd-4f5f-90a0-4abd0de10a78"
}
cURL request
If you would prefer sending a request to Paradigm with a simple cURL command, here is an example:
curl --request POST \
--url $PARADIGM_BASE_URL/embeddings \
--header "Authorization: Bearer $PARADIGM_API_KEY" \
--header 'accept: application/json' \
--data '{
"model": "multilingual-e5-large",
"input": "This a test string"
}'