Skip to main content

EmbeddingModel

Enum EmbeddingModel 

Source
#[non_exhaustive]
pub enum EmbeddingModel { BgeSmallEnV15, BgeBaseEnV15, BgeLargeEnV15, MultilingualE5Small, MultilingualE5Base, Qwen3Embedding0_6B, Qwen3Embedding4B, AllMiniLmL6V2, ParaphraseMultilingualMiniLmL12V2, TextEmbedding3Small, }
Expand description

Stable: external consumers may depend on this; breaking changes require a SemVer bump.

Supported embedding models.

This enum represents the embedding models available for text vectorization. Models are categorized as either local (run on-device via lattice-inference) or remote (require API calls).

§Example

use lattice_embed::EmbeddingModel;

let model = EmbeddingModel::default();
assert_eq!(model.dimensions(), 384);
assert!(model.is_local());

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

BgeSmallEnV15

BGE small English v1.5 (384 dimensions) - fast and efficient.

§

BgeBaseEnV15

BGE base English v1.5 (768 dimensions) - balanced quality/speed.

§

BgeLargeEnV15

BGE large English v1.5 (1024 dimensions) - highest quality local.

§

MultilingualE5Small

Multilingual E5 small (384 dimensions) - multilingual, same arch as BGE.

§

MultilingualE5Base

Multilingual E5 base (768 dimensions) - best multilingual quality/speed.

§

Qwen3Embedding0_6B

Qwen3-Embedding-0.6B (1024 dimensions) - multilingual, decoder-only, GPU-accelerated.

§

Qwen3Embedding4B

Qwen3-Embedding-4B (2560 dimensions, MRL-capable) - multilingual, decoder-only, GPU-accelerated.

§

AllMiniLmL6V2

all-MiniLM-L6-v2 (384 dimensions) - BERT-class, WordPiece tokenizer, sentence-transformers.

§

ParaphraseMultilingualMiniLmL12V2

paraphrase-multilingual-MiniLM-L12-v2 (384 dimensions) - multilingual, XLM-R base, sentence-transformers.

§

TextEmbedding3Small

OpenAI text-embedding-3-small (1536 dimensions) - remote API.

Implementations§

Source§

impl EmbeddingModel

Source

pub const fn native_dimensions(&self) -> usize

Stable: get the native (full-resolution) output dimension of this model’s embeddings.

Returns the model’s intrinsic dimension regardless of any MRL truncation. For MRL-capable models with a configured truncation, use ModelConfig::dimensions().

Source

pub const fn dimensions(&self) -> usize

Stable: get the output dimension of this model’s embeddings.

§Example
use lattice_embed::EmbeddingModel;

assert_eq!(EmbeddingModel::BgeSmallEnV15.dimensions(), 384);
assert_eq!(EmbeddingModel::BgeBaseEnV15.dimensions(), 768);
assert_eq!(EmbeddingModel::BgeLargeEnV15.dimensions(), 1024);
Source

pub const fn is_local(&self) -> bool

Stable: check if this model can run locally (via lattice-inference).

Source

pub const fn is_remote(&self) -> bool

Stable: check if this model requires a remote API.

Source

pub const fn max_input_tokens(&self) -> usize

Stable: maximum input tokens supported by this model.

Use this for chunking/truncation decisions. Values are conservative to leave room for special tokens.

Reference limits:

  • BGE models: 512 tokens
  • OpenAI text-embedding-3: 8191 tokens
  • Gemini embedding-001: 20000 tokens
Source

pub const fn query_instruction(&self) -> Option<&'static str>

Stable: query instruction prefix for asymmetric retrieval.

Some models require different text for queries vs documents (asymmetric retrieval).

  • E5 models (MultilingualE5Small, MultilingualE5Base): trained with “query: “ / “passage: “ asymmetric prefixes. Omitting the prefix degrades retrieval quality significantly — the model expects them during fine-tuning.

  • Qwen3-Embedding models: require an instruction prompt to align the decoder embedding space for retrieval tasks.

  • BGE / MiniLM models: trained with contrastive objectives on raw text; no prefix needed.

Returns Some(prefix) if the query text should be wrapped as "{prefix}{query}" before embedding. Returns None for models that don’t need instruction prompting.

Source

pub const fn document_instruction(&self) -> Option<&'static str>

Stable: document instruction prefix for asymmetric retrieval.

Some models use different prompts for documents vs queries. Returns Some(prefix) if the document text should be wrapped as "{prefix}{text}" before embedding at storage time.

Source

pub const fn model_id(&self) -> &'static str

Stable: get the model identifier (HuggingFace ID or provider/model).

Source

pub const fn supports_output_dim(&self) -> bool

Stable: whether this model supports configurable output dimensions (MRL/Matryoshka).

Source

pub const fn key_version(&self) -> &'static str

Stable: embedding key revision string for this model family.

Trait Implementations§

Source§

impl Clone for EmbeddingModel

Source§

fn clone(&self) -> EmbeddingModel

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EmbeddingModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for EmbeddingModel

Source§

fn default() -> EmbeddingModel

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for EmbeddingModel

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for EmbeddingModel

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl FromStr for EmbeddingModel

Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Stable: parse model from string (case-insensitive, flexible matching).

Accepts:

  • Display names: “bge-small-en-v1.5”
  • Short names: “bge-small”, “small”
  • HuggingFace IDs: “BAAI/bge-small-en-v1.5”
Source§

type Err = String

The associated error which can be returned from parsing.
Source§

impl Hash for EmbeddingModel

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for EmbeddingModel

Source§

fn eq(&self, other: &EmbeddingModel) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for EmbeddingModel

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Copy for EmbeddingModel

Source§

impl Eq for EmbeddingModel

Source§

impl StructuralPartialEq for EmbeddingModel

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,