What Are Embeddings?
An embedding is a dense vector representation of text. Similar concepts have vectors that are close together in high-dimensional space.- Score near 1.0 = very similar meaning
- Score near 0.0 = unrelated
Embedding Backends
OpenGround supports two embedding backends with different trade-offs:FastEmbed
Default - Lightweight, ONNX-based
- Smaller install size
- CPU-optimized by default
- Optional GPU support (experimental)
- Fastest for CPU inference
Sentence-Transformers
Full-featured - PyTorch-based
- Larger install size
- Automatic GPU/MPS detection
- Better GPU performance
- More model options
Backend Selection
Fromconfig.py:62, the default backend:
FastEmbed Backend
FastEmbed uses ONNX Runtime for inference (fromembeddings.py:93-116):
ONNX (Open Neural Network Exchange) is an optimized runtime for neural networks. FastEmbed converts PyTorch models to ONNX for faster CPU inference.
Installation Options
GPU Compatibility Check
OpenGround automatically detects GPU availability (fromembeddings.py:44-90):
Sentence-Transformers Backend
Sentence-Transformers uses PyTorch with automatic hardware acceleration (fromembeddings.py:14-25):
Installation
Embedding Models
Fromconfig.py:58-60, the default model:
Why BGE-Small-EN-v1.5?
- Multilingual: Good English performance
- Compact: 384 dimensions (vs 768 for larger models)
- Fast: Smaller vectors = faster search
- Quality: Strong performance on MTEB benchmarks
Changing Models
1
Choose a Model
Browse models on Hugging Face:Look for:
- Dimensions: 384-768 (smaller = faster)
- Language: Match your docs (multilingual, en, etc.)
- Size: Smaller models = faster inference
2
Update Configuration
3
Delete Existing Embeddings
4
Re-embed Documentation
Model Compatibility Validation
OpenGround stores embedding metadata in the LanceDB schema (fromingest.py:159-177):
ingest.py:111-142):
This prevents mixing embeddings from different models, which would break search quality.
Embedding Generation
Fromembeddings.py:207-234, the main generation function:
Batch Processing
Both backends process embeddings in batches for efficiency (fromconfig.py:65):
embeddings.py:119-160 (sentence-transformers example):
FastEmbed Passage Embedding
FastEmbed distinguishes between passage (document) and query embeddings (fromembeddings.py:163-204):
Some models are trained differently for documents vs. queries. FastEmbed uses
passage_embed() for document chunks and would use query_embed() for search queries (though OpenGround currently uses passage_embed for both).Embedding Dimensions
Fromconfig.py:60:
- Storage Size
- Search Speed
- Quality
Each vector =
dimensions × 4 bytes (float32)Rule of thumb: Stick with the model’s native dimensions. Don’t try to change dimensions independently from the model.
Configuration Examples
Optimal CPU Performance
GPU Performance (NVIDIA)
Apple Silicon (M1/M2/M3)
Chunking Strategy
Before embedding, documents are split into chunks (fromconfig.py:66-67):
ingest.py:52-76, using LangChain’s text splitter:
Why 800 Characters?
- Context window: Most embedding models handle 512 tokens well
- 800 chars ≈ 200 tokens: Safe margin for tokenization
- Not too small: Preserves context
- Not too large: Enables precise retrieval
Why 200 Character Overlap?
- Information spanning boundaries isn’t lost
- Better retrieval for queries matching boundary content
- 25% overlap provides good coverage without excessive duplication
Adjusting Chunking
Model Caching
Both backends use@lru_cache to load models once (from embeddings.py:14 and 93):
- Downloaded from Hugging Face (first run)
- Cached locally in
~/.cache/huggingface/ - Loaded into memory once per process
- Reused for all embedding operations
Performance Comparison
- FastEmbed CPU
- FastEmbed GPU
- Sentence-Transformers GPU
- Sentence-Transformers MPS
Best for: Most users, CPU-only machines
- ~500 chunks/sec (CPU)
- Lightweight install
- Low memory usage
- No GPU setup hassle
Performance varies by hardware. These are approximate estimates for the default model.
Next Steps
Search
Learn how embeddings power hybrid search
Configuration
Full configuration reference for embeddings
Architecture
See where embeddings fit in the architecture
Update Documentation
Efficiently update docs with incremental re-embedding