--- title: Embeddings description: Generate vector embeddings for text using elizaOS Cloud embedding API. --- # Embeddings 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 ```bash 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" }' ``` ```javascript 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); ``` ```python 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']) ``` ### 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 ```json { "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: ```json { "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 Embedding model availability and dimensions are deployment-specific. Use `/api/v1/models`, the API Explorer, or the embeddings response metadata for the current catalog. --- ## Use Cases ### Semantic Search ```javascript // 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 ``` ### Cosine Similarity ```javascript 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); } ```