pub struct HydraModel { /* private fields */ }Expand description
Hydra model wrapper
Supports multiple inference backends:
- Native safetensors (preferred) - pure Rust inference
- Heuristic fallback - rule-based when model unavailable
§Tokenizer Support
Hydra uses trait-based tokenization supporting:
- Llama 3 (128K vocab) - default for open source
- OpenAI o200k_base (200K vocab)
- OpenAI cl100k_base (100K vocab)
- Fallback byte-level tokenizer
§Vocab Mismatch Handling
The current model (v1.0) was trained with 32K vocab. When using a larger
tokenizer (e.g., Llama 3 128K), token IDs exceeding the model’s vocab size
are clamped to vocab_size - 1. This preserves functionality but may
degrade accuracy. A warning is logged when this occurs.
Implementations§
Source§impl HydraModel
impl HydraModel
Sourcepub fn fallback_only() -> Self
pub fn fallback_only() -> Self
Create model with fallback only (no neural inference)
Sourcepub fn with_tokenizer(tokenizer: BoxedTokenizer) -> Self
pub fn with_tokenizer(tokenizer: BoxedTokenizer) -> Self
Create model with a specific tokenizer
Sourcepub fn load<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self>
Load model from directory or file
Expects directory structure:
./models/hydra/
└── model.safetensorsOr a direct path to .safetensors file.
Falls back to heuristics if loading fails.
Sourcepub fn model_path(&self) -> Option<&str>
pub fn model_path(&self) -> Option<&str>
Get the model path (if loaded or attempted to load)
Sourcepub fn uses_fallback(&self) -> bool
pub fn uses_fallback(&self) -> bool
Check if fallback heuristics are enabled
Sourcepub fn tokenizer_type(&self) -> TokenizerType
pub fn tokenizer_type(&self) -> TokenizerType
Get the tokenizer type
Sourcepub fn vocab_size(&self) -> usize
pub fn vocab_size(&self) -> usize
Get vocabulary size
Sourcepub fn model_vocab_size(&self) -> usize
pub fn model_vocab_size(&self) -> usize
Get the model’s vocabulary size (may differ from tokenizer)
Sourcepub fn has_vocab_mismatch(&self) -> bool
pub fn has_vocab_mismatch(&self) -> bool
Check if there’s a tokenizer/model vocab mismatch
Sourcepub fn predict_compression(&self, content: &str) -> Result<CompressionDecision>
pub fn predict_compression(&self, content: &str) -> Result<CompressionDecision>
Predict compression algorithm for content
Sourcepub fn predict_security(&self, content: &str) -> Result<SecurityDecision>
pub fn predict_security(&self, content: &str) -> Result<SecurityDecision>
Predict security status for content
Trait Implementations§
Source§impl Clone for HydraModel
impl Clone for HydraModel
Auto Trait Implementations§
impl Freeze for HydraModel
impl !RefUnwindSafe for HydraModel
impl Send for HydraModel
impl Sync for HydraModel
impl Unpin for HydraModel
impl !UnwindSafe for HydraModel
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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