Expand description
Embed trait and TextEmbedder accumulator.
Embed decouples your domain types from the embedding API. Rather than
returning a Vec<String> (which forces allocation at the call site),
your type pushes strings into a TextEmbedder. This lets the
EmbeddingsBuilder collect texts from many
documents into a single flat buffer before chunking into API requests.
A single document can push multiple strings — you get one
Embedding back per push. This is how one struct
can produce several vectors (e.g. embed title and body separately).
§Example
use irig::embeddings::{Embed, TextEmbedder, EmbedError};
struct Article { title: String, body: String }
impl Embed for Article {
fn embed(&self, e: &mut TextEmbedder) -> Result<(), EmbedError> {
e.embed(self.title.clone());
e.embed(self.body.clone());
Ok(())
}
}Structs§
- Embed
Error - Text
Embedder - Accumulates strings to be embedded. Passed into
Embed::embed.
Traits§
- Embed
- Implemented by types that can be converted to text for embedding.
Functions§
- to_
texts - Extract all texts an object would embed without running the model.