Skip to main content
Docs
Embeddings

Embeddings

Generate vector embeddings for text using the embeddings endpoint.

The embeddings endpoint converts text into numerical vectors that capture semantic meaning. Use embeddings for similarity search, clustering, and RAG applications.

Endpoint

POST https://api.elyxir.ai/v1/embeddings

Request

Headers

HeaderRequiredDescription
AuthorizationYesBearer token: Bearer elyxir_xxx
Content-TypeYesMust be application/json

Body Parameters

ParameterTypeRequiredDescription
modelstringYesEmbedding model ID
inputstring/arrayYesText to embed
encoding_formatstringNofloat (default) or base64

Example Request

curl -X POST https://api.elyxir.ai/v1/embeddings \
  -H "Authorization: Bearer elyxir_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-3-small",
    "input": "The quick brown fox jumps over the lazy dog"
  }'

Response

Success (200 OK)

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [0.0023, -0.0093, 0.0152, ...]
    }
  ],
  "model": "text-embedding-3-small",
  "usage": {
    "prompt_tokens": 9,
    "total_tokens": 9
  }
}

Batch Embeddings

Embed multiple texts in one request:

response = requests.post(
    "https://api.elyxir.ai/v1/embeddings",
    headers=headers,
    json={
        "model": "text-embedding-3-small",
        "input": [
            "First document to embed",
            "Second document to embed",
            "Third document to embed"
        ]
    }
)
 
# Response includes embedding for each input
for item in response.json()["data"]:
    print(f"Index {item['index']}: {len(item['embedding'])} dimensions")

Available Models

ModelProviderDimensionsMax Input
text-embedding-3-largeOpenAI30728191
text-embedding-3-smallOpenAI15368191
text-embedding-ada-002OpenAI15368191
embed-english-v3.0Cohere1024512
embed-multilingual-v3.0Cohere1024512

Use Cases

Find similar documents:

import numpy as np
 
def cosine_similarity(a, b):
    return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
 
# Embed query and documents
query_embedding = get_embedding("How do I reset my password?")
doc_embeddings = [get_embedding(doc) for doc in documents]
 
# Find most similar
similarities = [cosine_similarity(query_embedding, doc) for doc in doc_embeddings]
most_similar_idx = np.argmax(similarities)

RAG (Retrieval-Augmented Generation)

  1. Embed your documents and store in a vector database
  2. Embed the user's query
  3. Find similar documents using vector similarity
  4. Include relevant documents in the LLM prompt

Clustering

Group similar texts:

from sklearn.cluster import KMeans
 
# Get embeddings for all texts
embeddings = [get_embedding(text) for text in texts]
 
# Cluster into groups
kmeans = KMeans(n_clusters=5)
clusters = kmeans.fit_predict(embeddings)

Best Practices

Text Length

  • Shorter texts (1-2 sentences) work well for questions/queries
  • Longer texts (paragraphs) capture more context
  • Very long texts may exceed model limits

Preprocessing

  • Clean text of irrelevant formatting
  • Consider chunking long documents
  • Normalize text (lowercase, remove special characters) if needed

Choosing a Model

Use CaseRecommended Model
English text, high qualitytext-embedding-3-large
English text, cost-effectivetext-embedding-3-small
Multilingualembed-multilingual-v3.0
Legacy compatibilitytext-embedding-ada-002
Embeddings | elyxir