Skip to main content

BgeM3Embedder

Struct BgeM3Embedder 

Source
pub struct BgeM3Embedder { /* private fields */ }
Expand description

BGE-M3 multi-function embedder via Ollama.

Produces three representations from a single Ollama model call:

  1. Dense vector — direct from Ollama’s /api/embed endpoint.
  2. Sparse weights — derived from the BGE-M3 dense vector via explicit top-k thresholding because Ollama does not expose native sparse output.
  3. 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. They are not SPLADE outputs. When Ollama (or another backend) exposes native BGE-M3 sparse and per-token outputs, this implementation can use those representations directly without changing the retrieval interface.

The model bge-m3 produces 1024-dimensional dense embeddings.

Implementations§

Source§

impl BgeM3Embedder

Source

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.

Source

pub fn try_new_with_derive( config: &EmbeddingConfig, derive_config: BgeM3DeriveConfig, ) -> Result<Self, MemoryError>

Create a new BgeM3Embedder with custom derivation parameters.

Source

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.

Source§

fn embed<'a>(&'a self, text: &'a str) -> EmbedFuture<'a>

Embed a single text. Returns a vector of f32.
Source§

fn embed_batch<'a>(&'a self, texts: Vec<String>) -> EmbedBatchFuture<'a>

Embed multiple texts in a batch. Read more
Source§

fn model_name(&self) -> &str

The model name this embedder uses.
Source§

fn dimensions(&self) -> usize

Expected embedding dimensions.
Source§

fn embed_multi_optional<'a>( &'a self, text: &'a str, ) -> OptionalMultiEmbedFuture<'a>

Optionally produce dense and sparse representations in one model call. Read more
Source§

fn embed_batch_multi_optional<'a>( &'a self, texts: Vec<String>, ) -> OptionalMultiEmbedBatchFuture<'a>

Optionally produce batched dense and sparse representations.
Source§

impl MultiFunctionEmbedder for BgeM3Embedder

Source§

fn embed_multi<'a>(&'a self, text: &'a str) -> MultiEmbedFuture<'a>

Embed a single text, returning dense, sparse, and multi-vec representations.
Source§

fn embed_batch_multi<'a>( &'a self, texts: Vec<String>, ) -> MultiEmbedBatchFuture<'a>

Embed multiple texts in a batch, returning all three representations per text. Read more
Source§

fn model_name(&self) -> &str

The model name this embedder uses.
Source§

fn dimensions(&self) -> usize

Expected dense embedding dimensions.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more