Embeddings API
Note: Requires an embedding provider API key (or local Ollama embedding model) when run live.
Turn text into vectors in one call
Underneath semantic RAG sits a simple idea: embeddings turn sentences into lists of numbers so sentences with similar meanings sit close together even when they use different words.
PraisonAI exposes a top-level embedding(…) helper directly from praisonai that works across OpenAI, Gemini, Ollama, and 20+ embedding providers. Expected output: prints the embedding vector length (for example, 1536 dimensions).
Example
from praisonai import embedding
result = embedding(
input=['PraisonAI runs agents locally.', 'Offline AI keeps data private.'],
model='text-embedding-3-small',
)
print('Vectors returned:', len(result.embeddings))
print('Dimensions:', len(result.embeddings[0]))Example explained
- from praisonai import embedding — Imports PraisonAI's unified multi-provider embedding function.
- result.embeddings — Contains the numeric vector for each input string.
Matching embedding dimensions and models consistently
Every vector stored in an index must be queried with the exact same embedding model and dimensions used at indexing time. If you switch embedding models later, re-index your corpus cleanly.
Common pitfall: calling embeddings() on every user query for the entire document corpus instead of caching document vectors once during ingestion.
Reference: documentation