pub struct MtmdInputChunk<'chunks> { /* private fields */ }Expand description
A single tokenized input chunk (text, image, or audio).
Instances are borrowed from an MtmdInputChunks list and live as long
as that list.
Implementations§
Source§impl<'chunks> MtmdInputChunk<'chunks>
impl<'chunks> MtmdInputChunk<'chunks>
Sourcepub fn chunk_type(&self) -> MtmdInputChunkType
pub fn chunk_type(&self) -> MtmdInputChunkType
The type of this chunk.
Sourcepub fn n_pos(&self) -> i32
pub fn n_pos(&self) -> i32
Number of temporal positions (equals n_tokens for non-M-RoPE models).
Sourcepub fn save(&self) -> Result<Vec<u8>>
pub fn save(&self) -> Result<Vec<u8>>
Serialize this chunk’s metadata to a byte buffer.
Only metadata is saved — never the image or audio payload. A chunk
restored with MtmdInputChunks::load_chunk is a placeholder: it
carries the token and position counts needed to line a cached KV state
back up with its prompt, but cannot be re-encoded. That is the intended
use, and it is why this is cheap enough to store alongside a session
file written by
state_seq_save_file.
Wraps mtmd_input_chunk_save.
§Errors
Returns MtmdError::ChunkSaveFailed if llama.cpp cannot serialize
this chunk.
Sourcepub fn to_owned_chunk(&self) -> Result<OwnedMtmdInputChunk>
pub fn to_owned_chunk(&self) -> Result<OwnedMtmdInputChunk>
Copy this chunk, payload and all, into an owned handle.
MtmdInputChunk borrows from the MtmdInputChunks list holding it,
so it dies with that list. Take a copy when a chunk has to outlive the
tokenization it came from — caching encoded media across requests, for
instance. Unlike Self::to_placeholder, the result is still usable
for encoding.
Wraps mtmd_input_chunk_copy.
§Errors
Returns MtmdError::ChunkLoadFailed if llama.cpp returns null.
Sourcepub fn to_placeholder(&self) -> Result<OwnedMtmdInputChunk>
pub fn to_placeholder(&self) -> Result<OwnedMtmdInputChunk>
Copy this chunk as a standalone placeholder — metadata only, no payload.
Same shape as a round trip through Self::save and
MtmdInputChunks::load_chunk, without the serialization. Useful for
keeping a prompt’s structure alive after the pixels have been dropped.
Wraps mtmd_input_chunk_get_placeholder.
§Errors
Returns MtmdError::ChunkLoadFailed if llama.cpp returns null.
Sourcepub fn text_tokens(&self) -> Option<&[i32]>
pub fn text_tokens(&self) -> Option<&[i32]>
Return the raw llama token IDs for a text chunk.
Returns None if this chunk is not a text chunk.
Sourcepub fn image_tokens(&self) -> Option<MtmdImageTokens<'chunks>>
pub fn image_tokens(&self) -> Option<MtmdImageTokens<'chunks>>
Return the image token metadata for an image or audio chunk.
Returns None for text chunks.
Sourcepub fn id(&self) -> Option<&str>
pub fn id(&self) -> Option<&str>
Optional ID attached to this chunk (used for KV cache tracking).
Sourcepub fn as_ptr(&self) -> *const mtmd_input_chunk
pub fn as_ptr(&self) -> *const mtmd_input_chunk
Returns the raw *const mtmd_input_chunk pointer.
§Safety
The returned pointer is valid for the lifetime of the parent
MtmdInputChunks.