Embeddings in EngramDB
EngramDB includes native support for generating vector embeddings from text. This feature makes it easy to create semantic memory nodes without needing to implement external embedding generation logic.Getting Started with Embeddings
Basic Usage
The embedding functionality in EngramDB is centered around theEmbeddingService, which provides methods to convert text into vector embeddings:
Python Usage
Embeddings are also available in the Python API:Embedding Services
EngramDB provides multiple ways to generate embeddings:Default Service
The default embedding service will attempt to use model-based embeddings if available, and fall back to deterministic mock embeddings if not:Model-Based Embeddings
You can explicitly request model-based embeddings, specifying the model to use:Mock Embeddings
For testing or when ML dependencies aren’t available, you can use mock embeddings:Multi-Vector Embeddings
EngramDB now supports multi-vector embeddings, inspired by models like ColBERT and ColPali:What are Multi-Vector Embeddings?
Unlike traditional embeddings that represent an entire document as a single vector, multi-vector embeddings represent a document as a collection of vectors. This approach:- Captures different aspects of the document in separate vectors
- Enables more nuanced similarity comparisons
- Improves precision in semantic search
Using Multi-Vector Embeddings
Similarity Metrics for Multi-Vectors
When using multi-vector embeddings, EngramDB supports specialized similarity functions:Creating Memory Nodes from Text
Using the Database API
The simplest way to create memory nodes from text is to use the Database API:Using the MemoryNode API
You can also create a memory node directly from text:Semantic Search
Once you have memories created from text, you can perform semantic searches:Configuration and Options
Document vs. Query Embeddings
EngramDB distinguishes between document and query embeddings:Vector Similarity Metrics
EngramDB supports different similarity metrics:- Cosine Similarity: Measures the cosine of the angle between vectors (default)
- Dot Product: Simple dot product of two vectors
- Euclidean Distance: Measures the straight-line distance in the vector space
Dimensions
You can check the dimensions of the embeddings:Supported Embedding Models
EngramDB supports multiple embedding models that you can choose from:E5 Multilingual Large Instruct (Default)
intfloat/multilingual-e5-large-instruct model provides:
- High-quality semantic embeddings (1024 dimensions)
- Support for 100+ languages
- Instruction-based embedding generation
- Excellent performance on retrieval tasks
GTE Modern BERT Base
Alibaba-NLP/gte-modernbert-base model provides:
- Modern semantics updated with recent data (768 dimensions)
- Strong performance on semantic search and similarity tasks
- Efficient inference with a base-sized model
Jina Embeddings V3
jinaai/jina-embeddings-v3 model provides:
- State-of-the-art performance on various NLP tasks (768 dimensions)
- Good cross-lingual capabilities
- Well-optimized for retrieval tasks
Custom Models
You can also specify a custom model by providing the model name:Dependencies and Features
The embedding functionality is optional and protected by feature flags:embeddings: Basic embedding support with mock providerspython: Python support for embeddings (requires PyO3)
torchtransformers
Best Practices
- Choose the right embedding type: Use single-vector embeddings for simple cases and multi-vector embeddings for more complex documents
- Select appropriate dimensions: Larger dimensions (768-1536) capture more semantic nuance but use more memory
- Consider your use case: For search, use smaller multi-vectors; for classification, single vectors often work well
- Normalize your vectors: Especially important when using cosine similarity
- Distinguish between document and query embeddings: This asymmetric approach often improves search results
- Use domain-specific models when possible for better semantic understanding in your field
Examples
For complete examples of using embeddings with EngramDB, see:- Rust: examples/rust/text_embeddings.rs
- Python: examples/python/text_embeddings.py
- Multi-Vector: examples/rust/multi_vector_example.rs

