What Embedding Providers Are Supported by ai-memory?
ai-memory supports six embedding providers—OpenAI, Voyage, Google Gemini, OpenAI-compatible servers, local in-process embedders, and synthetic test embedders—abstracted behind the Embedder trait and instantiated via the factory in factory.rs.
The akitaonrails/ai-memory repository implements a pluggable vector generation layer that decouples embedding logic from storage. By defining a unified Embedder trait and providing concrete implementations for multiple backends, ai-memory allows developers to switch between cloud APIs and local processing without changing application code.
Supported ai-memory Embedding Providers
OpenAI Embeddings
The OpenAI provider delivers production-grade embeddings via OpenAI’s /v1/embeddings endpoint. Implemented as OpenAiEmbedder in crates/ai-memory-llm/src/embedding.rs (lines 63-66), this provider defaults to the text-embedding-3-small model. It requires a valid API key and supports configurable model selection through the EmbedderConfig struct.
Voyage AI Embeddings
Voyage provides commercial embeddings optimized for retrieval tasks. The VoyageEmbedder struct (lines 350-353 in embedding.rs) implements the Embedder trait for Voyage AI’s API, handling authentication and batch processing according to Voyage’s embedding specifications.
Google Gemini Embeddings
The Google provider interfaces with Gemini’s embedContent RPC. Located in crates/ai-memory-llm/src/google.rs, the GoogleEmbedder implementation manages the specific request format required by Google’s Gemini Embeddings API, including content encoding and dimensionality handling.
OpenAI-Compatible Embeddings
For self-hosted or local models that implement the OpenAI wire format—such as Ollama, vLLM, or LM Studio—ai-memory provides OpenAiCompatEmbedder (lines 283-291 in embedding.rs). This provider accepts a custom base URL while maintaining the standard OpenAI request/response structure, enabling compatibility with the broader ecosystem of OpenAI-compatible servers.
Local Embeddings
The Local provider offers pure in-process embedding generation without network dependencies. Defined in crates/ai-memory-llm/src/local.rs as LocalEmbedder (lines 122-128), this implementation generates synthetic vectors for testing scenarios or environments where external API access is restricted. The constant LOCAL_DIM in local.rs specifies the default dimensionality for local embeddings.
Synthetic Embeddings (Test-Only)
For deterministic testing, ai-memory includes a Synthetic provider that generates repeatable "bag-of-words" vectors. The SyntheticEmbedder is only compiled for test targets, guaranteeing identical embedding outputs across test runs to ensure predictable assertions.
How the Embedding Factory Works
The factory pattern in crates/ai-memory-llm/src/factory.rs centralizes provider instantiation and configuration. The EmbedderChoice enum enumerates all available providers, while the build_embedder function (lines 209-236) performs the mapping from configuration to concrete implementation, returning an Arc<dyn Embedder> for thread-safe shared ownership.
The factory also exposes default_embedding_dim (lines 259-278), which returns the typical vector dimensionality for each provider-model combination, eliminating manual dimension configuration for standard models.
Configuration and Code Examples
Configuring OpenAI Embeddings
use ai_memory_llm::{EmbedderConfig, EmbedderChoice, build_embedder};
/// Build an OpenAI embedder (uses the default model & dim).
let cfg = EmbedderConfig {
provider: EmbedderChoice::OpenAi,
api_key: std::env::var("OPENAI_API_KEY").unwrap(),
model: "text-embedding-3-small".into(),
dim: None, // let the factory pick the right dim
};
let embedder = build_embedder(cfg).await?;
/// Generate an embedding for a piece of text.
let vec = embedder.embed_text("Hello, world!").await?;
println!("Embedding has {} dimensions", vec.len());
Using Local Embeddings
use ai_memory_llm::{EmbedderConfig, EmbedderChoice, build_embedder};
/// Use a local (in‑process) embedder – no network traffic.
let cfg = EmbedderConfig {
provider: EmbedderChoice::Local,
api_key: "".into(), // ignored
model: "local-model".into(),
dim: Some(ai_memory_llm::local::LOCAL_DIM),
};
let embedder = build_embedder(cfg).await?;
let vec = embedder.embed_query("search term").await?;
Summary
- ai-memory supports six embedding providers: OpenAI, Voyage, Google Gemini, OpenAI-compatible, Local, and Synthetic (test-only).
- All providers implement the
Embeddertrait defined incrates/ai-memory-llm/src/embedding.rs. - The factory in
crates/ai-memory-llm/src/factory.rshandles instantiation viabuild_embedderand dimension defaults viadefault_embedding_dim. - Use
EmbedderChoice::OpenAiCompatto connect self-hosted models like Ollama or vLLM. - Local and Synthetic providers enable fully offline testing without external API dependencies.
Frequently Asked Questions
Which embedding providers does ai-memory support?
ai-memory supports six providers: OpenAI (via text-embedding-3-small and other models), Voyage AI, Google Gemini, OpenAI-compatible servers (for Ollama, vLLM, LM Studio), an in-process Local embedder, and a deterministic Synthetic embedder for testing. Each implements the Embedder trait in crates/ai-memory-llm/src/embedding.rs.
How do I configure a local embedding provider without external API calls?
Set EmbedderChoice::Local in your EmbedderConfig and specify dim: Some(ai_memory_llm::local::LOCAL_DIM). The LocalEmbedder in crates/ai-memory-llm/src/local.rs generates vectors in-process without network requests, making it ideal for offline development or CI environments.
What is the default OpenAI embedding model in ai-memory?
The default model is text-embedding-3-small. When configuring EmbedderChoice::OpenAi with dim: None, the factory in factory.rs automatically selects the appropriate dimensionality for this model via the default_embedding_dim function.
Can I use self-hosted models like Ollama with ai-memory?
Yes. Select EmbedderChoice::OpenAiCompat to use the OpenAiCompatEmbedder (lines 283-291 in embedding.rs). This provider accepts a custom base URL and communicates with any server implementing the OpenAI embeddings API format, including Ollama, vLLM, and LM Studio.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →