bookclerk_plugin_ai_embedder::model
A model directory: what is in it, and the model loaded from it.
inspect is cheap: it reads model.json and looks at file sizes, so
the plugin can list its models without loading one. load reads and
verifies every file against the SHA-256 the description lists, then
builds the tokenizer, the row packs and the graph.
| Item | Kind | Summary |
|---|---|---|
Listing |
struct | What inspect found in a model directory. |
Embedding |
struct | One text's vector and whether a pack was missing for it. |
LoadedModel |
struct | A model in memory. |
ModelError |
enum | Why a model directory could not be listed, loaded or run. |
inspect |
function | Looks at a model directory without loading the model. |
load |
function | Loads the model a listing describes. |
pub struct Listing {
/* private fields */
}
What inspect found in a model directory.
pub fn revision(&self) -> &str
Revision of the model with the language packs present.
pub fn info(&self) -> AiModel
The model as the plugin lists it to the host.
Implements: Clone, Debug, Eq, PartialEq
pub struct Embedding {
pub vector: Vec<f32>,
pub fallback: bool,
}
One text's vector and whether a pack was missing for it.
Fields
vector: The vector, scaled to length one.fallback: True when a token of the text had no row in the loaded packs and was spelled with smaller pieces.
Implements: Clone, Debug, PartialEq
pub struct LoadedModel {
/* private fields */
}
A model in memory.
pub fn revision(&self) -> &str
Revision of the listing the model was loaded from.
pub fn dimensions(&self) -> u32
Numbers per vector.
pub fn embed(&self, text: &str, role: Role) -> Result<Embedding, ModelError>
Embeds one text.
text- The text.role- Document or query.
When the tokenizer or the graph fails, or the output is not finite.
Implements: Debug
pub enum ModelError {
Io { file: String, reason: String },
Pack(PackError),
Name { directory: String, model: String },
Incomplete(String),
Text(TextError),
Engine(EngineError),
BaseRow(u32),
NotFinite,
}
Why a model directory could not be listed, loaded or run.
Variants
Io: A file could not be read.file: File name inside the model directory.reason: The operating system's reason.
Pack: A file is not what the layout or the model description says.Name: The directory's name is not the model id its description gives.directory: The directory's name.model:model_idof itsmodel.json.
Incomplete: A file every text needs is missing or has another length.Text: The tokenizer could not be set up or failed on a text.Engine: ONNX Runtime could not load or run the graph.BaseRow: The base rows lack a token every text needs.NotFinite: The graph gave a number that is not finite.
Implements: Clone, Debug, Display, Eq, Error, From<EngineError>, From<PackError>, From<TextError>, PartialEq
pub fn inspect(dir: &Path) -> Result<Listing, ModelError>
Looks at a model directory without loading the model.
dir-models/<model id>in the plugin's data directory.
The description and the language packs present on disk.
When model.json is missing or invalid, the directory is named
differently from the model, or the graph, the tokenizer or the base rows
are missing or have another length than listed.
pub fn load(
listing: &Listing,
environment: &Environment,
) -> Result<LoadedModel, ModelError>
Loads the model a listing describes.
listing- Whatinspectfound.environment- The process's ONNX Runtime.
When a file changed since the listing or fails its SHA-256, the tokenizer or the graph cannot be set up, or the base rows lack a token every text needs.
Generated from crates/bookclerk-plugins/platform/ai-embedder at main · View as Markdown