Skip to content

VSAModel

The immutable container that defines a complete VSA algebra.

vsax.core.model.VSAModel dataclass

Immutable container defining a complete VSA algebra.

VSAModel combines a representation type, operation set, and sampling function to define a complete VSA system. It does not perform operations itself, but serves as a configuration object used by VSAMemory and encoders.

Attributes:

Name Type Description
dim int

Dimensionality of all hypervectors in this model.

rep_cls type[AbstractHypervector]

The hypervector representation class (e.g., ComplexHypervector).

opset AbstractOpSet

The operation set instance defining bind/bundle/inverse operations.

sampler Callable[[int, int, PRNGKey], ndarray]

Function to sample random vectors with signature (dim: int, n: int, key: PRNGKey) -> jnp.ndarray.

Example

from vsax.representations import ComplexHypervector from vsax.ops import FHRROperations from vsax.sampling import sample_complex_random model = VSAModel( ... dim=512, ... rep_cls=ComplexHypervector, ... opset=FHRROperations(), ... sampler=sample_complex_random ... )

Source code in vsax/core/model.py
@dataclass(frozen=True)
class VSAModel:
    """Immutable container defining a complete VSA algebra.

    VSAModel combines a representation type, operation set, and sampling function
    to define a complete VSA system. It does not perform operations itself, but
    serves as a configuration object used by VSAMemory and encoders.

    Attributes:
        dim: Dimensionality of all hypervectors in this model.
        rep_cls: The hypervector representation class (e.g., ComplexHypervector).
        opset: The operation set instance defining bind/bundle/inverse operations.
        sampler: Function to sample random vectors with signature
                 (dim: int, n: int, key: PRNGKey) -> jnp.ndarray.

    Example:
        >>> from vsax.representations import ComplexHypervector
        >>> from vsax.ops import FHRROperations
        >>> from vsax.sampling import sample_complex_random
        >>> model = VSAModel(
        ...     dim=512,
        ...     rep_cls=ComplexHypervector,
        ...     opset=FHRROperations(),
        ...     sampler=sample_complex_random
        ... )
    """

    dim: int
    rep_cls: type[AbstractHypervector]
    opset: AbstractOpSet
    sampler: Callable[[int, int, jax.random.PRNGKey], jnp.ndarray]

    def __post_init__(self) -> None:
        """Validate model parameters.

        Raises:
            ValueError: If dim is not positive.
        """
        if self.dim <= 0:
            raise ValueError(f"dim must be positive, got {self.dim}")

Functions

__post_init__()

Validate model parameters.

Raises:

Type Description
ValueError

If dim is not positive.

Source code in vsax/core/model.py
def __post_init__(self) -> None:
    """Validate model parameters.

    Raises:
        ValueError: If dim is not positive.
    """
    if self.dim <= 0:
        raise ValueError(f"dim must be positive, got {self.dim}")