Embeddings
Generate vector embbedings from text
Embeddings transform text into numerical vectors that encode semantic meaning. These vector representations enable machine learning applications to process and compare text mathematically. The InteractiveAI Router offers a unified interface for accessing embedding models across multiple providers.
Understanding Embeddings
When text is converted to an embedding, it becomes a point in a high-dimensional vector space. Semantically similar texts occupy nearby positions in this space. For example, "refund policy" and "return guidelines" will have vectors that are close together, while "refund policy" and "server configuration" will be far apart.
This mathematical representation of meaning forms the backbone of many production AI systems.
Use Cases
Retrieval-Augmented Generation (RAG): Build pipelines that fetch relevant context from your knowledge base before generating responses. Embeddings determine which documents should be included in the LLM's context window.
Semantic Search: Convert your document corpus and user queries into embeddings, then rank results by vector similarity. Unlike keyword matching, this approach understands meaning and surfaces relevant results even when exact terms don't match.
Recommendation Engines: Generate embeddings for content items (articles, products, support tickets) and user behavior to identify similar items. Vector proximity reveals relationships that keyword analysis would miss.
Anomaly Detection: Flag unusual content by identifying embeddings that fall outside normal patterns in your dataset.
Document Classification: Assign texts to categories or group related content by measuring embedding distances. Documents with similar embeddings typically address related subjects.
Duplicate Detection: Identify identical or near-identical content by comparing embeddings. This method catches duplicates even when the text has been reworded or paraphrased.
Generating Embeddings
Single Text Request
Send a POST request to /api/v1/embeddings with your text and chosen model:
Multiple Texts in One Request
Process several texts simultaneously by passing an array of strings:
Supported Models
The InteractiveAI Router connects to embedding models from various providers. View the complete catalog at:
https://interactiveai.com/models?fmt=cards&output_modalities=embeddings
Fetch the list of available models programmatically:
Implementation Example: Semantic Search
The following example demonstrates a complete semantic search implementation:
Expected Output:
Recommendations
Choose Models Based on Requirements: Embedding models present trade-offs between speed, cost, and quality. Compact models like qwen/qwen3-embedding-0.6b or openai/text-embedding-3-small respond quickly at lower cost. Larger models like openai/text-embedding-3-large produce higher-quality vectors. Test several options against your specific data.
Combine Texts into Single Requests: When you need embeddings for multiple strings, send them together in one API call rather than making separate requests. This approach minimizes latency and reduces costs.
Store and Reuse Embeddings: The same input always produces the same embedding vector. Cache these results in a database or vector store to eliminate redundant API calls.
Use Cosine Similarity for Comparisons: When measuring distance between embeddings, cosine similarity outperforms Euclidean distance in high-dimensional spaces because it focuses on directional alignment rather than absolute magnitude.
Respect Token Limits: Each model enforces a maximum input length. Documents exceeding this threshold require chunking or truncation. Consult model specifications before processing long texts.
Split Documents at Natural Boundaries: When dividing lengthy content, break at paragraph or section boundaries rather than arbitrary character positions. This approach maintains the semantic coherence of each chunk.
Controlling Provider Selection
The provider parameter lets you specify which providers handle your embedding requests. Common reasons to use this:
Restricting data to specific providers for compliance
Prioritizing providers based on cost or performance
Accessing provider-specific capabilities
Example configuration:
Errors
400 Bad Request
Malformed input or missing required fields. Verify your request structure.
401 Unauthorized
Missing or invalid API key. Confirm your key is correct and included in the Authorization header.
402 Payment Required
Account balance depleted. Add credits to continue.
404 Not Found
Model does not exist or does not support embeddings. Double-check the model identifier.
429 Too Many Requests
Rate limit hit. Implement backoff and retry logic.
529 Provider Overloaded
Upstream provider capacity exceeded. Set allow_fallbacks: true to route to alternative providers automatically.
Constraints
No Streaming Support: Embedding responses are delivered complete; incremental delivery is not available.
Input Length Restrictions: Models impose maximum token limits. Inputs beyond this threshold are truncated or rejected.
Deterministic Results: Given identical input, embeddings are always identical. Temperature and randomness parameters do not apply.
Language Performance Varies: Model effectiveness differs across languages. Review documentation to confirm support for your target languages.
Last updated
Was this helpful?

