pub struct MtmdBatch<'ctx> { /* private fields */ }Expand description
Encode several media chunks in one pass.
MtmdContext::encode_chunk handles one chunk at a time; this batches
them, which is what you want for a multi-image prompt or a run of video
frames — the vision encoder runs once over the whole set instead of once per
image.
A batch belongs to the context that created it and borrows it for its lifetime. Chunks are not owned by the batch, so they must outlive it too.
Wraps mtmd_batch_init / mtmd_batch_add_chunk / mtmd_batch_encode.
Implementations§
Source§impl<'ctx> MtmdBatch<'ctx>
impl<'ctx> MtmdBatch<'ctx>
Sourcepub fn new(ctx: &'ctx MtmdContext) -> Result<Self>
pub fn new(ctx: &'ctx MtmdContext) -> Result<Self>
Sourcepub fn add_chunk(&mut self, chunk: &MtmdInputChunk<'_>) -> Result<()>
pub fn add_chunk(&mut self, chunk: &MtmdInputChunk<'_>) -> Result<()>
Add a media chunk. Text chunks are rejected.
§Errors
Returns MtmdError::BatchAddFailed — code 2 means the batch is
full and the chunk was not added (start a new batch), code 3 means it
cannot be batched with what is already there (differing image
geometry, say).
Sourcepub fn output_embd(
&self,
chunk: &MtmdInputChunk<'_>,
n_embd: usize,
) -> Option<&[f32]>
pub fn output_embd( &self, chunk: &MtmdInputChunk<'_>, n_embd: usize, ) -> Option<&[f32]>
Borrow the embeddings produced for chunk by the last Self::encode.
Returns None if the chunk was not part of this batch or encoding has
not run. The slice is owned by the batch and is invalidated by the next
encode.
§Safety of the returned length
llama.cpp reports only a pointer, so the length is derived from the chunk’s token count and the context’s embedding dimension.