Skip to main content

VSAR: VSA-grounded reasoning with approximate joins

Project description

VSAR: VSA-grounded Reasoning

VSAR (VSAX Reasoner) is a VSA-grounded reasoning tool that provides a unified inference substrate using hypervector algebra for deductive reasoning, approximate joins, and explainable results.

Built on top of the VSAX library for GPU-accelerated VSA operations.

Key Features

  • VSA-grounded reasoning: Leverage hypervector algebra for approximate unification
  • Predicate-partitioned storage: Efficient KB organization reduces retrieval noise
  • Top-k retrieval: Similarity-based nearest neighbor search for variable bindings
  • Deterministic generation: Reproducible results with fixed seeds
  • HDF5 persistence: Save and load knowledge bases and symbol registries
  • Comprehensive testing: 179 tests with 99% coverage

Quick Start

from vsar.kernel.vsa_backend import FHRRBackend
from vsar.symbols.registry import SymbolRegistry
from vsar.encoding.vsa_encoder import VSAEncoder
from vsar.encoding.roles import RoleVectorManager
from vsar.kb.store import KnowledgeBase
from vsar.retrieval.query import Retriever

# Create VSA system
backend = FHRRBackend(dim=512, seed=42)
registry = SymbolRegistry(backend, seed=42)
encoder = VSAEncoder(backend, registry, seed=42)
kb = KnowledgeBase(backend)
role_manager = RoleVectorManager(backend, seed=42)
retriever = Retriever(backend, registry, kb, encoder, role_manager)

# Insert facts: parent(alice, bob), parent(bob, carol)
facts = [("alice", "bob"), ("bob", "carol")]
for args in facts:
    atom_vec = encoder.encode_atom("parent", list(args))
    kb.insert("parent", atom_vec, args)

# Query: parent(alice, X)
results = retriever.retrieve("parent", 2, {"1": "alice"}, k=5)
print(results)  # [('bob', 0.85), ...]

# Query: parent(X, carol)
results = retriever.retrieve("parent", 1, {"2": "carol"}, k=5)
print(results)  # [('bob', 0.78), ...]

Installation

Using uv (recommended)

# Install uv
pip install uv

# Clone and install from source
git clone https://github.com/your-org/vsar.git
cd vsar
uv sync

# Run tests
uv run pytest

Using pip (future)

pip install vsar

Development

# Clone the repository
git clone https://github.com/your-org/vsar.git
cd vsar

# Install dependencies
uv sync

# Run tests with coverage
uv run pytest --cov=vsar --cov-fail-under=90

# Format code
uv run black .

# Lint code
uv run ruff check .

# Type check
uv run mypy src/vsar

# Run pre-commit hooks
uv run pre-commit run --all-files

# Build package
uv build

Architecture

VSAR is organized into layers:

  • Kernel Layer (vsar.kernel): VSA operations (FHRR backend via VSAX)
  • Symbol Layer (vsar.symbols): Typed symbol spaces (E, R, A, C, T, S) with basis persistence
  • Encoding Layer (vsar.encoding): Role-filler binding for atoms and queries
  • KB Layer (vsar.kb): Predicate-partitioned storage with HDF5 persistence
  • Retrieval Layer (vsar.retrieval): Unbinding, cleanup, and top-k retrieval

See docs/architecture.md for details.

Project Status

Phase 0 (Foundation) - ✅ COMPLETE

  • ✅ Kernel backend (FHRR VSA via VSAX)
  • ✅ Symbol space management (6 typed spaces)
  • ✅ Atom encoding (role-filler binding)
  • ✅ KB storage (predicate-partitioned bundles)
  • ✅ Retrieval primitive (unbind → cleanup)
  • ✅ Comprehensive tests (179 tests, 99% coverage)
  • ✅ Integration tests (end-to-end workflows)
  • ✅ HDF5 persistence (KB + basis)

Future Phases:

  • Phase 1: VSARL language, query compiler, CLI
  • Phase 2: Rule engine, forward chaining
  • Phase 3: Optimizations, indexing

Documentation

Testing

VSAR has comprehensive test coverage:

# Run all tests
uv run pytest

# Run with coverage report
uv run pytest --cov=vsar --cov-report=html

# Run specific test suites
uv run pytest tests/unit/           # Unit tests
uv run pytest tests/integration/    # Integration tests

Test statistics:

  • 179 tests (all passing)
  • 99.07% coverage
  • Unit tests: 156
  • Integration tests: 23

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vsar-0.1.0.tar.gz (20.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vsar-0.1.0-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file vsar-0.1.0.tar.gz.

File metadata

  • Download URL: vsar-0.1.0.tar.gz
  • Upload date:
  • Size: 20.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vsar-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0b300d1c814729c47b421fbc0045d0b6bef6879d46181c5601351a74b7d85a94
MD5 84c0845fc7c6785c38321fb188a70138
BLAKE2b-256 502f1e42723ca041abc18feed44e947b9e1af2f77ab8c9e9068cef6592d6aa38

See more details on using hashes here.

Provenance

The following attestation bundles were made for vsar-0.1.0.tar.gz:

Publisher: publish.yml on vasanthsarathy/vsar

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file vsar-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vsar-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 24.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for vsar-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd9fed50c3177c554a39dfc23b057891cfba2aa35d25b5b944a8241611d42a40
MD5 2210472ddfe4a5355318db9636ca051b
BLAKE2b-256 8631f6115bb8768a717391bb6c9e4325b203a88082d5c2b97f7531f07583741d

See more details on using hashes here.

Provenance

The following attestation bundles were made for vsar-0.1.0-py3-none-any.whl:

Publisher: publish.yml on vasanthsarathy/vsar

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page