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.
If spec.sha256 starts with “pending” or equals “skip”, verification
is bypassed and Ok(true) is returned unconditionally.
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).
Sourcepub fn ensure_nli_models(&self) -> Result<(PathBuf, PathBuf), ModelManagerError>
pub fn ensure_nli_models(&self) -> Result<(PathBuf, PathBuf), ModelManagerError>
Download the NLI cross-encoder model and tokenizer.
Used for zero-shot relation classification via entailment scoring.
Sourcepub fn find_nli_model(&self) -> Option<(PathBuf, PathBuf)>
pub fn find_nli_model(&self) -> Option<(PathBuf, PathBuf)>
Find locally cached NLI model. Returns None if not downloaded yet.
Sourcepub fn find_relation_classifier(&self) -> Option<PathBuf>
pub fn find_relation_classifier(&self) -> Option<PathBuf>
Check for a locally available fine-tuned relation classifier model.
Looks for relation_classifier/model_int8.onnx (or model.onnx) and
relation_classifier/tokenizer.json in the cache directory.
Returns Some((model_path, tokenizer_path)) if found, None otherwise.
Sourcepub fn find_relex_model(&self) -> Option<(PathBuf, PathBuf)>
pub fn find_relex_model(&self) -> Option<(PathBuf, PathBuf)>
Check for locally exported gliner-relex ONNX model.
The relex model must be exported manually using:
python scripts/export_relex_onnx.py [--quantize]
Returns Some((model_path, tokenizer_path)) if found, None otherwise.
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