pub struct ModelManager { /* private fields */ }Expand description
Manages downloading, caching, and verifying ONNX model files.
Implementations§
Source§impl ModelManager
impl ModelManager
Sourcepub fn new() -> Result<Self, ModelManagerError>
pub fn new() -> Result<Self, ModelManagerError>
Create a new ModelManager using the default cache directory
(~/.cache/ctxgraph/models/).
Sourcepub fn with_cache_dir(cache_dir: PathBuf) -> Result<Self, ModelManagerError>
pub fn with_cache_dir(cache_dir: PathBuf) -> Result<Self, ModelManagerError>
Create a ModelManager with a custom cache directory (useful for tests).
Sourcepub fn default_cache_dir() -> Result<PathBuf, ModelManagerError>
pub fn default_cache_dir() -> Result<PathBuf, ModelManagerError>
Return the default cache directory (~/.cache/ctxgraph/models/),
creating it if it does not exist.
Sourcepub fn model_path(&self, spec: &ModelSpec) -> PathBuf
pub fn model_path(&self, spec: &ModelSpec) -> PathBuf
Path where a given model would be stored locally.
Sourcepub fn is_cached(&self, spec: &ModelSpec) -> bool
pub fn is_cached(&self, spec: &ModelSpec) -> bool
Check whether the model file exists on disk and its size matches the spec.
Sourcepub fn verify(&self, spec: &ModelSpec) -> Result<bool, ModelManagerError>
pub fn verify(&self, spec: &ModelSpec) -> Result<bool, ModelManagerError>
Verify the SHA-256 hash of a cached model file.
Returns Ok(true) if the hash matches, Ok(false) if it doesn’t,
or an error if the file cannot be read.
Sourcepub fn download(&self, spec: &ModelSpec) -> Result<PathBuf, ModelManagerError>
pub fn download(&self, spec: &ModelSpec) -> Result<PathBuf, ModelManagerError>
Download a model, verify its hash, and return the local path.
Sourcepub fn get_or_download(
&self,
spec: &ModelSpec,
) -> Result<PathBuf, ModelManagerError>
pub fn get_or_download( &self, spec: &ModelSpec, ) -> Result<PathBuf, ModelManagerError>
Return the cached model path if it exists and is valid, otherwise download it.
Source§impl ModelManager
impl ModelManager
Sourcepub fn ensure_ner_models(&self) -> Result<(PathBuf, PathBuf), ModelManagerError>
pub fn ensure_ner_models(&self) -> Result<(PathBuf, PathBuf), ModelManagerError>
Download the NER model and tokenizer needed for Tier 1 extraction.
Downloads gliner_large-v2.1 INT8 model + tokenizer to the cache directory.
Sourcepub fn ensure_rel_models(&self) -> Option<(PathBuf, PathBuf)>
pub fn ensure_rel_models(&self) -> Option<(PathBuf, PathBuf)>
Download the multitask model and tokenizer needed for relation extraction.
Returns None if the model is not available (needs ONNX conversion).
Auto Trait Implementations§
impl Freeze for ModelManager
impl RefUnwindSafe for ModelManager
impl Send for ModelManager
impl Sync for ModelManager
impl Unpin for ModelManager
impl UnsafeUnpin for ModelManager
impl UnwindSafe for ModelManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more