Skip to main content

VisionEmbeddingModel

Struct VisionEmbeddingModel 

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

A loaded Qwen3.5 vision-language checkpoint, ready to pool image (and image+text) embeddings.

See docs/model.md for the general model-loading design; this type follows the same “load once, reuse” shape as NativeEmbeddingService’s wrapped models.

Implementations§

Source§

impl VisionEmbeddingModel

Source

pub fn new( weights: F16ModelWeights, config: Qwen35Config, vision_weights: Qwen35VisionWeights, tokenizer: BpeTokenizer, ) -> Self

Compose a model from already-loaded components (no I/O).

Use this when the checkpoint spans multiple safetensors shards (not supported by Self::from_directory) or when components are shared across other in-process model instances.

Source

pub fn from_directory(dir: &Path) -> Result<Self>

Load a Qwen3.5 vision-language checkpoint directory: config.json, tokenizer.json, the model.visual.* vision-encoder tensors, and a single-shard decoder checkpoint. The directory must carry a model.safetensors.index.json (or quantize_index.json) manifest naming exactly one decoder shard file — the vision-tensor loader requires one of those manifests and runs before decoder-shard resolution, so a plain model.safetensors alone (with no manifest) is not sufficient. The canonical Qwen3.5-0.8B HF layout (a one-shard index) satisfies this.

§Errors

Returns EmbedError::ModelInitialization if config.json is missing or invalid, if the checkpoint has no vision_config, if neither manifest is present, if the decoder weights are sharded across more than one file, or if any component tensor fails to load.

Source

pub fn embed_image( &self, image_bytes: &[u8], prompt: &str, pooling: PoolingStrategy, ) -> Result<Vec<f32>>

Pool an image (plus an optional text prompt) into a single L2-normalized [dimensions()] embedding vector.

Same scaffold and pooling contract as lattice_inference::vision::embed_image_from_bytes_f16 (see that function’s docs for the exact prompt-assembly layout).

§Errors

Returns EmbedError::InvalidInput if image_bytes cannot be decoded, its dimensions are not compatible with the checkpoint’s patch/merge geometry, or the assembled request otherwise fails validation (the error message names the offending field). Returns EmbedError::InferenceFailed for every other underlying failure — e.g. the prompt plus image tokens exceeding the checkpoint’s context window.

Source

pub fn embed_text( &self, prompt: &str, pooling: PoolingStrategy, ) -> Result<Vec<f32>>

Pool a text-only prompt through the same decoder + pooling path as Self::embed_image, landing in the same vector space.

§Errors

Returns EmbedError::InvalidInput if the prompt is empty or tokenizes to an out-of-vocabulary id. Returns EmbedError::InferenceFailed for every other underlying failure — e.g. the prompt exceeding the checkpoint’s context window.

Source

pub fn dimensions(&self) -> usize

Output embedding dimension (the checkpoint’s decoder hidden size).

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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