Encoders API¶
VSAX encoders convert structured data into hypervector representations.
Base Classes¶
vsax.encoders.AbstractEncoder
¶
Bases: ABC
Abstract base class for encoding structured data into hypervectors.
All encoders must implement the encode() method. Encoders can optionally
implement fit() for learned encodings and decode() for reconstruction.
Attributes:
| Name | Type | Description |
|---|---|---|
model |
The VSAModel instance defining the VSA algebra. |
|
memory |
The VSAMemory instance for accessing basis hypervectors. |
Example
class MyEncoder(AbstractEncoder): ... def encode(self, data): ... # Custom encoding logic ... return self.memory["basis"] encoder = MyEncoder(model, memory) hv = encoder.encode(some_data)
Source code in vsax/encoders/base.py
Functions¶
__init__(model, memory)
¶
encode(*args, **kwargs)
abstractmethod
¶
Encode data into a hypervector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Any
|
Positional arguments (encoder-specific). |
()
|
**kwargs
|
Any
|
Keyword arguments (encoder-specific). |
{}
|
Returns:
| Type | Description |
|---|---|
AbstractHypervector
|
The encoded hypervector. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
This is an abstract method. |
Note
Different encoders may have different signatures. See specific encoder documentation for details.
Source code in vsax/encoders/base.py
fit(data)
¶
Optionally fit encoder parameters to data.
This method is optional and can be used for learned encodings. By default, it does nothing.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Any
|
The training data. |
required |
Core Encoders¶
- ScalarEncoder - Numeric values
- SequenceEncoder - Ordered sequences
- SetEncoder - Unordered collections
- DictEncoder - Key-value pairs
- GraphEncoder - Graph structures