Highly Performant, Modular, Memory Safe and Production-ready Inference, Ingestion and Indexing built in Rust
Highly Performant, Modular, Memory Safe and Production-ready Inference, Ingestion and Indexing built in Rust
EmbedAnything is a minimalist, yet highly performant, modular, lightning-fast, lightweight, multisource, multimodal, and local embedding pipeline built in Rust. Whether you're working with text, images, audio, PDFs, websites, or other media, EmbedAnything streamlines the process of generating embeddings from various sources and seamlessly streaming (memory-efficient-indexing) them to a vector database. It supports dense, sparse, ONNX, model2vec and late-interaction embeddings, offering flexibility for a wide range of use cases.
Table of Contents
About The ProjectBuilt With Rust
Why Candle?
Getting StartedInstallation
Usage
Roadmap
Contributing
How to add custom model and chunk size
Embedding models are computationally expensive and time-consuming. By separating document preprocessing from model inference, you can significantly reduce pipeline latency and improve throughput.
Vector streaming transforms a sequential bottleneck into an efficient, concurrent workflow.
The embedding process happens separetly from the main process, so as to maintain high performance enabled by rust MPSC, and no memory leak as embeddings are directly saved to vector database. Find our blog.
➡️Faster execution.
➡️No Pytorch Dependency, thus low-memory footprint and easy to deploy on cloud.
➡️True multithreading
➡️Running embedding models locally and efficiently
➡️In-built chunking methods like semantic, late-chunking
➡️Supports range of models, Dense, Sparse, Late-interaction, ReRanker, ModernBert.
➡️Memory Management: Rust enforces memory management simultaneously, preventing memory leaks and crashes that can plague other languages
⚠️ WhichModel has been deprecated in pretrained_hf
We have collaborated with reputed enterprise like Elastic, Weaviate, SingleStore, Milvus and Analytics Vidya Datahours
You can get in touch with us for further collaborations.
Only measures embedding model inference speed, on onnx-runtime. Code
Benchmarks with other fromeworks coming soon!!
We support any hugging-face models on Candle. And We also support ONNX runtime for BERT and ColPali.
⚠️ WhichModel has been deprecated in from_pretrained_hf
…| Model | HF link |
|---|---|
| Jina | Jina Models |
| Bert | All Bert based models |
| CLIP | openai/clip-* |
| Whisper | OpenAI Whisper models |
| ColPali | starlight-ai/colpali-v1.2-merged-onnx |
| Colbert | answerdotai/answerai-colbert-small-v1, jinaai/jina-colbert-v2 and more |
| Splade | Splade Models and other Splade like models |
| Model2Vec | model2vec, minishlab/potion-base-8M |
| Qwen3-Embedding | Qwen/Qwen3-Embedding-0.6B |
| Gemma3 | google/embeddinggemma-300m and other Gemma3 embedding models |
| Reranker | Jina Reranker Models, Xenova/bge-reranker, Qwen/Qwen3-Reranker-4B |
By default, EmbedAnything uses the pooling method defined by the model. You can override it by passing a Pooling strategy to from_pretrained_hf. This is useful when a checkpoint ships without pooling config, or when you want to reproduce a specific sentence-embedding recipe.
from embed_anything import EmbeddingModel, Pooling
# Available strategies: Pooling.Mean, Pooling.Cls, Pooling.LastToken
model = EmbeddingModel.from_pretrained_hf(
model_id="sentence-transformers/all-MiniLM-L6-v2",
pooling=Pooling.Mean, # mean-pool token embeddings (matches sentence-transformers)
)
data = embed_anything.embed_query(["What is mean pooling?"], embedder=model)| Strategy | Description |
|---|---|
Pooling.Mean |
Averages token embeddings (weighted by the attention mask). |
Pooling.Cls |
Uses the [CLS] / first-token embedding. |
Pooling.LastToken |
Uses the last non-padding token (common for causal/LLM encoders). |
To load private or gated repositories (for example google/embeddinggemma-300m), pass a Hugging Face access token. If token is omitted, EmbedAnything falls back to the HF_TOKEN environment variable or your local huggingface-cli login credentials.
from embed_anything import EmbeddingModel
model = EmbeddingModel.from_pretrained_hf(
model_id="google/embeddinggemma-300m",
token="hf_your_access_token", # or set the HF_TOKEN environment variable
)Sparse embeddings are useful for keyword-based retrieval and hybrid search scenarios.
…ONNX models provide faster inference and lower memory usage. Use the ONNXModel enum for pre-configured models or provide a custom model path.
import embed_anything
from embed_anything import EmbeddingModel, WhichModel, ONNXModel, Dtype, TextEmbedConfig
# Option 2: Use a custom ONNX model from Hugging Face
model = EmbeddingModel.from_pretrained_onnx(
WhichModel.Bert
model_id="onnx_model_link",
dtype=Dtype.F16 # Use half precision for faster inference
)Use cloud models for high-quality embeddings without local model deployment.
import embed_anything
from embed_anything import EmbeddingModel, WhichModel
import os
# Set your API key
os.environ["COHERE_API_KEY"] = "your-api-key-here"
# Initialize the cloud model
model = EmbeddingModel.from_pretrained_cloud(
WhichModel.CohereVision,
model_id="embed-v4.0"
)
# Use it like any other model
data = embed_anything.embed_file("test_files/document.pdf", embedder=model)Semantic chunking preserves meaning by splitting text at semantically meaningful boundaries rather than fixed sizes.
…Late-chunking splits text into smaller units first, then combines them during embedding for better context preservation.
…pip install embed-anything
For GPUs and using special models like ColPali
pip install embed-anything-gpu
❌ If it shows cuda error while running on windowns, run the following command:
os.add_dll_directory("C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v12.6/bin")| End-to-End Retrieval and Reranking using VectorDB Adapters |
| ColPali-Onnx |
| Adapters |
| Qwen3- Embedings |
| Benchmarks |
…
# Embed a query
queries = ["What is machine learning?", "How does neural networks work?"]
query_embeddings = embed_anything.embed_query(queries, embedder=model)
# Use embeddings for similarity search
for i, query_emb in enumerate(query_embeddings):
print(f"Query: {queries[i]}")
print(f"Embedding shape: {len(query_emb.embedding)}")
# Embed all files in a directory
data = embed_anything.embed_directory(
"test_files/",
embedder=model,
config=config
)
print(f"Total chunks: {len(data)}")For custom or fine-tuned models, specify the Hugging Face model ID and path to the ONNX file:
import embed_anything
from embed_anything import EmbeddingModel, WhichModel, Dtype
# Load a custom ONNX model from Hugging Face
model = EmbeddingModel.from_pretrained_onnx(
WhichModel.Jina,
hf_model_id="jinaai/jina-embeddings-v2-small-en",
path_in_repo="model.onnx", # Path to ONNX file in the repo
dtype=Dtype.F16 # Use half precision
)
# Use the model
data = embed_anything.embed_file("test_files/document.pdf", embedder=model)Note: Using pre-configured models (via ONNXModel enum) is recommended as these models are tested and optimized. For a complete list of supported ONNX models, see ONNX Models Guide.
The answer is No. EmbedAnything provides you pyo3 bindings, so you can run any function in python without any issues. To contibute you should check out our guidelines and python folder example of adapters.
We provide both backends, candle and onnx. On top of it we also give an end-to-end pipeline, that is you can ingest different data-types and index to any vector database, and inference any model. Fastembed is just an onnx-wrapper.
One of the main reasons is that Candle doesn't require any specific ONNX format models, which means it can work seamlessly with any Hugging Face model. This flexibility has been a key factor for us. However, we also recognize that we’ve been compromising a bit on speed in favor of that flexibility.
use of undeclared identifier 'bfloat' with MetalThis happens when a Candle model runs on Metal under a Python interpreter that was built against an old macOS SDK (common with conda/Anaconda Pythons, which report macOS 11–12). Metal then defaults to a Shading Language version where bfloat doesn't exist. The published wheel is fine — you just need a Python whose SDK is macOS 14+ (e.g. a Homebrew Python), or relink your ex
No open issues yet, or sync has not completed.