Skip to Content

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 -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

ParameterTypeRequiredDescription
inputstring/arrayText to embed (string or array of strings)
modelstringEmbedding model. Default: text-embedding-3-small
encoding_formatstringOutput format: float or base64
dimensionsintegerNumber 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

ModelDimensionsDescription
text-embedding-3-small1536Fast, cost-effective (default)
text-embedding-3-large3072Higher quality embeddings
text-embedding-ada-0021536Legacy model

Use Cases

// 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 similarity

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); }