Skip to main content

Embedding Models Overview

Transform text, images, and video into numerical vectors that capture semantic meaning, enabling powerful search, similarity comparison, and classification capabilities.

Available Models

Amazon Models

  • Titan Embed Text V2: Latest text embedding model with improved quality
  • Titan Embed Text: Reliable text embedding model
  • Titan Embed Image: Multimodal embeddings for text and images
  • Titan E1M Medium: Multimodal text and image embeddings
  • Nova 2 Multimodal Embeddings: Advanced multimodal embeddings for text and images

Cohere Models

  • Embed V4: Latest multimodal embedding model for text and images
  • Embed English: Optimized for English text
  • Embed Multilingual: Support for 100+ languages

Twelve Labs Models

  • Marengo Embed 3.0: Video and text embeddings for multimodal search
  • Marengo Embed 2.7: Video and text embeddings

Model Capabilities

Semantic Search

Find relevant content based on meaning, not just keywords

Similarity Comparison

Measure semantic similarity between texts

Classification

Categorize content based on embedded features

Multimodal Search

Search across text, images, and video content

Embeddings API

Convert text to numerical vectors:
POST /v1/embeddings

Basic Example

curl -X POST "https://api.anyapi.ai/v1/embeddings" \
  -H "Authorization: Bearer your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "cohere/embed-v4",
    "input": "The quick brown fox jumps over the lazy dog",
    "encoding_format": "float"
  }'

Response Format

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "index": 0,
      "embedding": [
        -0.006929283495992422,
        -0.005336422007530928,
        0.014362285844981098,
        ...
      ]
    }
  ],
  "model": "cohere/embed-v4",
  "usage": {
    "prompt_tokens": 10,
    "total_tokens": 10
  }
}

Batch Processing

Process multiple texts efficiently:
Python
import requests

texts = [
    "Artificial intelligence is transforming technology",
    "Machine learning enables computers to learn patterns",
    "Deep learning uses neural networks for complex tasks",
    "Natural language processing helps computers understand text"
]

response = requests.post(
    "https://api.anyapi.ai/v1/embeddings",
    headers={
        "Authorization": "Bearer your_api_key",
        "Content-Type": "application/json"
    },
    json={
        "model": "cohere/embed-v4",
        "input": texts,
        "encoding_format": "float"
    }
)

embeddings = response.json()["data"]
for i, embedding in enumerate(embeddings):
    print(f"Text {i+1}: {len(embedding['embedding'])} dimensions")

Model Comparison

ModelProviderModalitiesStrengthsAccess
Embed V4CohereText, ImageLatest multimodal, high qualityBasic
Embed EnglishCohereTextOptimized for EnglishBasic
Embed MultilingualCohereText100+ languagesBasic
Titan Embed Text V2AmazonTextLatest generation, improved qualityBasic
Titan Embed TextAmazonTextReliable, affordableBasic
Titan Embed ImageAmazonText, ImageMultimodal searchBasic
Titan E1M MediumAmazonText, ImageMultimodal, affordableBasic
Nova 2 MultimodalAmazonText, ImageAdvanced multimodalBasic
Marengo Embed 3.0Twelve LabsText, VideoVideo search and understandingBasic
Marengo Embed 2.7Twelve LabsText, VideoVideo embeddingsBasic

Advanced Use Cases

Semantic Search Engine

Python
import requests
from sklearn.metrics.pairwise import cosine_similarity

class SemanticSearchEngine:
    def __init__(self, model="cohere/embed-v4"):
        self.model = model
        self.documents = []
        self.embeddings = []

    def add_documents(self, texts):
        """Add documents to search index"""
        response = requests.post(
            "https://api.anyapi.ai/v1/embeddings",
            headers={"Authorization": "Bearer your_api_key"},
            json={
                "model": self.model,
                "input": texts
            }
        )

        embeddings = response.json()["data"]

        for i, text in enumerate(texts):
            self.documents.append(text)
            self.embeddings.append(embeddings[i]["embedding"])

    def search(self, query, top_k=5):
        """Search for similar documents"""
        response = requests.post(
            "https://api.anyapi.ai/v1/embeddings",
            headers={"Authorization": "Bearer your_api_key"},
            json={
                "model": self.model,
                "input": query
            }
        )

        query_embedding = response.json()["data"][0]["embedding"]

        similarities = []
        for i, doc_embedding in enumerate(self.embeddings):
            similarity = cosine_similarity([query_embedding], [doc_embedding])[0][0]
            similarities.append({
                "document": self.documents[i],
                "similarity": similarity,
                "index": i
            })

        similarities.sort(key=lambda x: x["similarity"], reverse=True)
        return similarities[:top_k]

# Usage example
search_engine = SemanticSearchEngine()

documents = [
    "Python is a programming language",
    "Machine learning algorithms learn from data",
    "Cats are popular pets",
    "Neural networks are used in AI",
    "Dogs need regular exercise"
]

search_engine.add_documents(documents)
results = search_engine.search("artificial intelligence", top_k=3)

for result in results:
    print(f"Similarity: {result['similarity']:.3f} - {result['document']}")

RAG (Retrieval-Augmented Generation)

Python
import requests

def rag_system(query, knowledge_base):
    """Simple RAG implementation"""
    # 1. Get relevant documents using embeddings
    search_engine = SemanticSearchEngine()
    search_engine.add_documents(knowledge_base)
    relevant_docs = search_engine.search(query, top_k=3)

    # 2. Create context from relevant documents
    context = "\n".join([doc["document"] for doc in relevant_docs])

    # 3. Generate answer using context
    response = requests.post(
        "https://api.anyapi.ai/v1/chat/completions",
        headers={"Authorization": "Bearer your_api_key"},
        json={
            "model": "google/gemini-2.5-flash",
            "messages": [
                {
                    "role": "user",
                    "content": f"Context: {context}\n\nQuestion: {query}\n\nAnswer based on the context:"
                }
            ]
        }
    )

    return response.json()["choices"][0]["message"]["content"]

Best Practices

Choosing the Right Model

  1. cohere/embed-v4: Best for multimodal (text + image) use cases
  2. cohere/embed-multilingual: Best for multilingual content
  3. amazon/titan-embed-text-v2: Good general-purpose text embeddings
  4. twelvelabs/marengo-embed-3-0: Best for video search and understanding

Optimization Tips

  • Batch processing: Send multiple texts in one request
  • Caching: Store embeddings to avoid recomputation
  • Preprocessing: Clean and normalize text before embedding
  • Chunking: Split long documents into smaller segments

Common Use Cases

Search & Retrieval

Document search, FAQ systems, knowledge bases

Recommendation Systems

Content recommendations, similar item suggestions

Content Moderation

Detect inappropriate content, spam filtering

Data Analysis

Clustering, topic modeling, trend analysis

Getting Started

Quick Start

Generate your first embeddings

SDKs

Use our libraries