Skip to main content

StaticModel

Struct StaticModel 

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

Static embedding model for Model2Vec

Implementations§

Source§

impl StaticModel

Source

pub fn from_bytes<T, M, C>( tokenizer_bytes: T, model_bytes: M, config_bytes: C, normalize: Option<bool>, ) -> Result<Self>
where T: AsRef<[u8]>, M: AsRef<[u8]>, C: AsRef<[u8]>,

Load a Model2Vec model directly from in-memory bytes.

This path is useful for runtimes that fetch model assets as bytes rather than reading them from a local filesystem.

Source

pub fn from_pretrained<P: AsRef<Path>>( repo_or_path: P, token: Option<&str>, normalize: Option<bool>, subfolder: Option<&str>, ) -> Result<Self>

Load a Model2Vec model from a local folder or the HuggingFace Hub.

§Arguments
  • repo_or_path - HuggingFace repo ID or local path to the model folder.
  • token - Optional HuggingFace token for authenticated downloads.
  • normalize - Optional flag to normalize embeddings (default from the resolved config file).
  • subfolder - Optional subfolder within the repo or path to look for model files.
Source

pub fn from_owned( tokenizer: Tokenizer, embeddings: Vec<f32>, rows: usize, cols: usize, normalize: bool, weights: Option<Vec<f32>>, token_mapping: Option<Vec<usize>>, ) -> Result<Self>

Construct from owned data.

§Arguments
  • tokenizer - Pre-deserialized tokenizer
  • embeddings - Owned f32 embedding data
  • rows - Number of vocabulary entries
  • cols - Embedding dimension
  • normalize - Whether to L2-normalize output embeddings
  • weights - Optional per-token weights for quantized models
  • token_mapping - Optional token ID mapping for quantized models
Source

pub fn from_borrowed( tokenizer: Tokenizer, embeddings: &'static [f32], rows: usize, cols: usize, normalize: bool, weights: Option<&'static [f32]>, token_mapping: Option<&'static [usize]>, ) -> Result<Self>

Construct from static slices (zero-copy for embedded binary data).

§Arguments
  • tokenizer - Pre-deserialized tokenizer
  • embeddings - Static f32 embedding data (borrowed, no copy)
  • rows - Number of vocabulary entries
  • cols - Embedding dimension
  • normalize - Whether to L2-normalize output embeddings
  • weights - Optional static per-token weights for quantized models
  • token_mapping - Optional static token ID mapping for quantized models
Source

pub fn encode_with_args( &self, sentences: &[String], max_length: Option<usize>, batch_size: usize, ) -> Vec<Vec<f32>>

Encode texts into embeddings.

§Arguments
  • sentences - the list of sentences to encode.
  • max_length - max tokens per text.
  • batch_size - number of texts per batch.
Source

pub fn encode(&self, sentences: &[String]) -> Vec<Vec<f32>>

Default encode: max_length=512, batch_size=1024

Source

pub fn encode_single(&self, sentence: &str) -> Vec<f32>

Encode a single sentence into a vector.

Trait Implementations§

Source§

impl Clone for StaticModel

Source§

fn clone(&self) -> StaticModel

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 StaticModel

Source§

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

Formats the value using the given formatter. Read more

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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, 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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> ErasedDestructor for T
where T: 'static,