pub struct TextEncoder { /* private fields */ }Expand description
Deterministic text-to-hypervector encoder using HDC principles.
Produces consistent HVec10240 vectors from text input without external dependencies.
The encoding is:
- Deterministic: Same input always produces same output
- Similarity-preserving: Similar texts produce similar vectors
- WASM-compatible: No external dependencies
Implementations§
Source§impl TextEncoder
impl TextEncoder
Sourcepub const fn with_config(config: TextEncoderConfig) -> Self
pub const fn with_config(config: TextEncoderConfig) -> Self
Create an encoder with custom configuration.
Sourcepub fn new_code_aware() -> Self
pub fn new_code_aware() -> Self
Create a code-aware encoder with character trigram overlay. This is the recommended configuration for CLI memory-context integration.
Sourcepub const fn config(&self) -> &TextEncoderConfig
pub const fn config(&self) -> &TextEncoderConfig
Get the encoder configuration.
Sourcepub fn encode(&self, text: &str) -> HVec10240
pub fn encode(&self, text: &str) -> HVec10240
Encode text into a hypervector.
The encoding process:
- Tokenize (whitespace split, optional lowercase, optional code-aware)
- Generate deterministic base vector for each token
- Apply position encoding via permutation
- Bundle all position-encoded vectors
- Optionally add n-gram overlay
Sourcepub fn encode_with_ngrams(&self, text: &str, n: usize) -> HVec10240
pub fn encode_with_ngrams(&self, text: &str, n: usize) -> HVec10240
Encode text with character n-grams for typo robustness.
This is equivalent to setting ngram_size in the config.
Sourcepub fn tokenize(text: &str, code_aware: bool, lowercase: bool) -> Vec<String>
pub fn tokenize(text: &str, code_aware: bool, lowercase: bool) -> Vec<String>
Tokenize text into a vector of tokens.
This is a convenience function for reuse by other modules that need tokenization consistent with the encoder’s logic.
§Arguments
text- Input text to tokenizecode_aware- Enable code-aware splitting (on_,-,.,/,::)lowercase- Convert tokens to lowercase
Trait Implementations§
Source§impl Clone for TextEncoder
impl Clone for TextEncoder
Source§fn clone(&self) -> TextEncoder
fn clone(&self) -> TextEncoder
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for TextEncoder
impl Debug for TextEncoder
Source§impl Default for TextEncoder
impl Default for TextEncoder
Source§fn default() -> TextEncoder
fn default() -> TextEncoder
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for TextEncoder
impl RefUnwindSafe for TextEncoder
impl Send for TextEncoder
impl Sync for TextEncoder
impl Unpin for TextEncoder
impl UnsafeUnpin for TextEncoder
impl UnwindSafe for TextEncoder
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
Mutably borrows from an owned value. Read more