bookclerk_plugin_ai_embedder::engine
Running a cut graph with ONNX Runtime.
ONNX Runtime is loaded once per process from the shared library beside
the plugin's executable (runtime). A Graph is one model's
session; Graph::run takes the table rows of one text's tokens and
gives the graph's output numbers.
| Item | Kind | Summary |
|---|---|---|
Graph |
struct | One model's graph, ready to run. |
EngineError |
enum | Why the runtime could not be loaded or a graph not run. |
runtime |
function | Loads ONNX Runtime from library, once per process. |
pub struct Graph {
/* private fields */
}
One model's graph, ready to run.
pub fn load(
environment: &Environment,
bytes: &[u8],
spec: &GraphSpec,
tables: &[TableSpec],
dimensions: u32,
) -> Result<Self, EngineError>
Loads a graph.
environment- The process's ONNX Runtime (runtime).bytes- The graph file, already checked against the model description.spec- The graph part of the model description.tables- The model's tables.dimensions- Numbers per vector.
EngineError::Graph when ONNX Runtime refuses the file, and
EngineError::MissingName when it lacks a named input or output.
pub fn run(&self, rows: &[&[u8]]) -> Result<Vec<f32>, EngineError>
Runs the graph on one text.
rows- One row-pack row per token of the text, in order: every table's row concatenated, as a row pack stores it.
The text's vector before normalising: the graph's output, averaged over the tokens when the model pools by mean.
EngineError::Rows for no rows or rows of the wrong length,
EngineError::Run when ONNX Runtime fails, and
EngineError::OutputShape when the output is not what the model
description promises.
Implements: Debug
pub enum EngineError {
Runtime(String),
Graph(String),
MissingName { kind: &'static str, name: String },
Rows,
Run(String),
OutputShape { expected: usize, found: usize },
}
Why the runtime could not be loaded or a graph not run.
Variants
Runtime: The ONNX Runtime shared library could not be loaded.Graph: The graph file is not a graph ONNX Runtime accepts.MissingName: The graph lacks an input or output the model description names.kind:inputoroutput.name: The name the description gives.
Rows: The rows passed do not fit the tables.Run: ONNX Runtime failed while running the graph.OutputShape: The output is not the shape the model description promises.expected: Numbers the description promises for this text.found: Numbers the graph gave.
Implements: Clone, Debug, Display, Eq, Error, From<EngineError>, PartialEq
pub fn runtime(library: &Path) -> Result<&'static Environment, EngineError>
Loads ONNX Runtime from library, once per process.
library- Path of the shared library. Later calls return the environment the first call made, whatever path they pass.
EngineError::Runtime when the library is missing or is not an ONNX
Runtime build the bindings accept; the failure is remembered.
Generated from crates/bookclerk-plugins/platform/ai-embedder at main · View as Markdown