packages/cloud-frontend/content/api/embeddings.mdx
import { Callout, Tabs } from "@/docs/components";
Generate vector embeddings for text to power semantic search and RAG applications.
Generate vector embeddings for the provided text.
<Tabs items={['cURL', 'JavaScript', 'Python']}> <Tabs.Tab>
curl -X POST "https://elizacloud.ai/api/v1/embeddings" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "The quick brown fox jumps over the lazy dog",
"model": "text-embedding-3-small"
}'
</Tabs.Tab> <Tabs.Tab>
const response = await fetch('https://elizacloud.ai/api/v1/embeddings', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
body: JSON.stringify({
input: 'The quick brown fox jumps over the lazy dog',
model: 'text-embedding-3-small',
}),
});
const data = await response.json();
console.log(data.data[0].embedding);
</Tabs.Tab> <Tabs.Tab>
import requests
response = requests.post(
'https://elizacloud.ai/api/v1/embeddings',
headers={
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
},
json={
'input': 'The quick brown fox jumps over the lazy dog',
'model': 'text-embedding-3-small',
}
)
data = response.json()
print(data['data'][0]['embedding'])
</Tabs.Tab> </Tabs>
| Parameter | Type | Required | Description |
|---|---|---|---|
input | string/array | ✓ | Text to embed (string or array of strings) |
model | string | Embedding model. Default: text-embedding-3-small | |
encoding_format | string | Output format: float or base64 | |
dimensions | integer | Number of dimensions for output |
{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [0.0023, -0.0145, 0.0312, ...],
"index": 0
}
],
"model": "text-embedding-3-small",
"usage": {
"prompt_tokens": 10,
"total_tokens": 10
}
}
Embed multiple texts in a single request:
{
"input": [
"First sentence to embed",
"Second sentence to embed",
"Third sentence to embed"
],
"model": "text-embedding-3-small"
}
Embedding model availability and dimensions are deployment-specific. Use
/api/v1/models, the API Explorer, or the embeddings response metadata for the
current catalog.
// Embed your query
const queryResponse = await fetch("https://elizacloud.ai/api/v1/embeddings", {
method: "POST",
headers: {
Authorization: "Bearer YOUR_API_KEY",
"Content-Type": "application/json",
},
body: JSON.stringify({
input: "How do I reset my password?",
model: "text-embedding-3-small",
}),
});
const queryEmbedding = (await queryResponse.json()).data[0].embedding;
// Find similar documents using cosine similarity
function cosineSimilarity(a, b) {
const dotProduct = a.reduce((sum, val, i) => sum + val * b[i], 0);
const magnitudeA = Math.sqrt(a.reduce((sum, val) => sum + val * val, 0));
const magnitudeB = Math.sqrt(b.reduce((sum, val) => sum + val * val, 0));
return dotProduct / (magnitudeA * magnitudeB);
}