Embeddings
Stable
Generate vector embeddings for text to power semantic search and RAG applications.
Create Embedding
POST/api/v1/embeddings
Generate vector embeddings for the provided text.
Request
cURL
curl -X POST "https://cloud.milady.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"
}'Parameters
| 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 |
Response
{
"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
}
}Batch Embeddings
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"
}Batch requests are more efficient. You can embed up to 100 texts per request.
Available Models
| Model | Dimensions | Description |
|---|---|---|
text-embedding-3-small | 1536 | Fast, cost-effective (default) |
text-embedding-3-large | 3072 | Higher quality embeddings |
text-embedding-ada-002 | 1536 | Legacy model |
Use Cases
Semantic Search
// Embed your query
const queryResponse = await fetch("https://cloud.milady.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 similarityCosine 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);
}