Embedding API Reference
Overview
The Embedding API provides the bridge between raw textual data and the multi-modal localized database. It enables developers to transform text into high-dimensional vectors (embeddings) for use in semantic search, Retrieval-Augmented Generation (RAG), and long-term memory for AI agents.
By utilizing this API, you can bypass context window limitations by dynamically retrieving relevant content based on user queries.
Initializing the Embedding Client
Before performing vector operations, initialize the Deeptrain client. The embedding engine is model-agnostic and can be configured to use specific providers.
from deeptrain import Deeptrain
# Initialize the client
dt = Deeptrain(api_key="your_api_key")
# Access the embedding module
embedding_engine = dt.embeddings
Core Methods
generate
Converts a string or a list of strings into numerical vector representations.
Parameters:
input(str | List[str]): The text content to vectorize.model(str, optional): The specific embedding model to use. Defaults to the system's optimized base model.
Returns:
EmbeddingResponse: An object containing the vector data and token usage.
Example:
response = dt.embeddings.generate(
input="Deeptrain enables multi-modal AI integration."
)
vector = response.data[0].embedding
print(f"Vector Dimensions: {len(vector)}")
index_content
Vectorizes text and stores it directly into the localized embedding database for future retrieval.
Parameters:
content(str): The text to be indexed.metadata(dict, optional): Key-value pairs to store alongside the vector (e.g., source URL, timestamps).collection_name(str, optional): Target collection for organizing data.
Returns:
Status: Confirmation of successful indexing and the generatedrecord_id.
Example:
dt.embeddings.index_content(
content="The Transcribe API supports YouTube and Vimeo integration.",
metadata={"source": "documentation", "category": "video-api"},
collection_name="platform-docs"
)
search
Performs a semantic similarity search against the localized database to retrieve relevant context.
Parameters:
query(str): The natural language string to search for.top_k(int): Number of relevant results to return. Default is5.filter(dict, optional): Metadata filters to narrow down the search.
Returns:
List[SearchResult]: A list of objects containing the content, metadata, and similarity score.
Example:
results = dt.embeddings.search(
query="How do I process video files?",
top_k=3,
filter={"category": "video-api"}
)
for match in results:
print(f"Score: {match.score} | Content: {match.text}")
Multi-modal Integration
The Embedding API works in tandem with the Transcribe API to facilitate text-based search over non-textual media.
transcribe_and_index
A pipeline method that processes audio or video input, generates a text transcript, and automatically stores the resulting embeddings.
Parameters:
source_url(str): URL to a local file, YouTube, or Vimeo video.media_type(str): One ofaudioorvideo.
Usage:
# Automatically transcribe a video and prepare it for RAG
dt.embeddings.transcribe_and_index(
source_url="https://www.youtube.com/watch?v=example",
media_type="video"
)
Data Objects
SearchResult
| Attribute | Type | Description |
| :--- | :--- | :--- |
| text | string | The original text content retrieved. |
| metadata | dict | Associated metadata provided during indexing. |
| score | float | Similarity score (0.0 to 1.0), where higher is more relevant. |
| record_id | string | Unique identifier for the vector record. |
Configuration & Limits
- Supported Models: Over 200 models (OpenAI, Anthropic, Cohere, Llama, etc.).
- Vector Storage: Localized by default to ensure low latency and data privacy.
- Context Handling: Automatically handles chunking and overlapping for long-form text documents to prevent information loss during vectorization.