Skip to main content

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 the EmbeddingService, 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:
EngramDB uses the E5 family of embedding models by default, which have excellent performance for semantic search tasks.

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:
The late interaction score is particularly effective for retrieval tasks, as it allows different parts of the query to match different parts of the document.

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:
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:
This distinction follows best practices for asymmetric semantic search.

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
You can specify which metric to use in your vector index configuration:

Dimensions

You can check the dimensions of the embeddings:
The default model produces 384-dimensional embeddings.

Supported Embedding Models

EngramDB supports multiple embedding models that you can choose from:

E5 Multilingual Large Instruct (Default)

The 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

The 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

The 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:
EngramDB will automatically determine the dimensions and other properties of the model.

Dependencies and Features

The embedding functionality is optional and protected by feature flags:
  • embeddings: Basic embedding support with mock providers
  • python: Python support for embeddings (requires PyO3)
To use model-based embeddings, you need the following Python packages:
  • torch
  • transformers
If these dependencies are not available, EngramDB will automatically fall back to mock embeddings.

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: