pub struct BgeM3Embedder { /* private fields */ }Expand description
BGE-M3 multi-function embedder via Ollama.
Produces three representations from a single Ollama model call:
- Dense vector — direct from Ollama’s
/api/embedendpoint. - Sparse lexical weights — derived from the dense vector via top-k thresholding (mimicking SPLADE-style sparse activation).
- ColBERT-style multi-vector — dense vector chunked into pseudo per-token embeddings for late interaction scoring.
§Current Limitations
Ollama’s embedding API (/api/embed) currently returns only dense vectors.
The sparse and multi-vec representations are derived from the dense output
as a pragmatic approximation. When Ollama (or another backend) exposes
native BGE-M3 sparse and per-token outputs, this implementation can be
updated to use them directly by replacing the derivation methods.
The model bge-m3 produces 1024-dimensional dense embeddings.
Implementations§
Source§impl BgeM3Embedder
impl BgeM3Embedder
Sourcepub fn try_new(config: &EmbeddingConfig) -> Result<Self, MemoryError>
pub fn try_new(config: &EmbeddingConfig) -> Result<Self, MemoryError>
Create a new BgeM3Embedder from embedding config.
Uses bge-m3 as the model name with 1024 dimensions by default.
The Ollama URL and timeout are taken from the config.
Sourcepub fn try_new_with_derive(
config: &EmbeddingConfig,
derive_config: BgeM3DeriveConfig,
) -> Result<Self, MemoryError>
pub fn try_new_with_derive( config: &EmbeddingConfig, derive_config: BgeM3DeriveConfig, ) -> Result<Self, MemoryError>
Create a new BgeM3Embedder with custom derivation parameters.
Sourcepub fn with_params(
base_url: &str,
model: &str,
dimensions: usize,
batch_size: usize,
timeout_secs: u64,
derive_config: BgeM3DeriveConfig,
) -> Result<Self, MemoryError>
pub fn with_params( base_url: &str, model: &str, dimensions: usize, batch_size: usize, timeout_secs: u64, derive_config: BgeM3DeriveConfig, ) -> Result<Self, MemoryError>
Create a BgeM3Embedder with explicit parameters (useful for testing
without an EmbeddingConfig).
Trait Implementations§
Source§impl Embedder for BgeM3Embedder
BgeM3Embedder also implements the standard Embedder trait for compatibility,
returning only the dense representation.
impl Embedder for BgeM3Embedder
BgeM3Embedder also implements the standard Embedder trait for compatibility,
returning only the dense representation.