Skip to main content

Spectral Memory Graph Processor — persistent, hallucination-free AI reasoning

Project description

SMGP — Spectral Memory Graph Processor

Python 3.10+ SystemVerilog License: Apache 2.0 CI Tests Tests RTL Sim PyPI PyPI - Downloads Code style: ruff

Persistent, hallucination-free AI reasoning through spectral graph theory, hyperdimensional computing, and dedicated hardware acceleration.

SMGP combines spectral graph theory, topological data analysis (TDA), hyperdimensional computing (HDC), and category-theoretic graph rewriting to achieve persistent memory, sublinear context processing, and verifiable reasoning. The framework ships with a complete Python software stack and an open-source hardware accelerator design (SMGPU) in SystemVerilog, enabling transparent offloading of compute-intensive kernels to an FPGA.

GitHub · Documentation · Issues


Installation

pip install smgp

With optional extras:

# Topological analysis (requires gudhi)
pip install "smgp[topology]"

# REST API + JWT auth
pip install "smgp[integration,auth]"

# HuggingFace / ONNX
pip install "smgp[huggingface,onnx]"

# Vector database sync (Qdrant)
pip install "smgp[vectordb]"

# Everything
pip install "smgp[all]"

Quick Start

from smgp.core.graph import SpectralMemoryGraph

# Build a knowledge graph with 10,000-dimensional HD addressing
graph = SpectralMemoryGraph(hd_dim=10000, seed=42)
graph.add_node("Socrates", label="person", properties={"era": "ancient Greece"})
graph.add_node("Plato",    label="person", properties={"era": "ancient Greece"})
graph.add_edge("Socrates", "Plato", "taught")

# Verify claims against the graph
from smgp.reasoning.verifier import ClaimVerifier
verifier = ClaimVerifier(graph)
result = verifier.verify("Socrates taught Plato")
print(result["verified"], result["reasoning"])

Spectral Analysis

from smgp.core.spectral import SpectralMethods

spectral = SpectralMethods(graph, num_eigenvalues=8)
L        = spectral.compute_laplacian()
evals, evecs = spectral.compute_eigen()
signal   = spectral.graph_fourier_transform(node_signal, evecs)

Hyperdimensional Memory

from smgp.core.hyperdim import HyperdimensionalMemory

hd = HyperdimensionalMemory(dim=10000, seed=42)
v1, v2 = hd.random_vectors(2)
bound  = hd.bind(v1, v2)
print(hd.similarity(hd.unbind(bound, v2), v1))  # ≈ 1.0

Hardware-Accelerated (FPGA)

from hardware.sw.smgp_hal.executor import HWExecutor
from hardware.sw.smgp_hal.hw_session import HWSession

session  = HWSession(device="/dev/smgpu0", fallback=True)
executor = HWExecutor(session=session)

# Drop executor into any core class — pure Python fallback when executor=None
graph    = SpectralMemoryGraph(hd_dim=10000, seed=42, executor=executor)
spectral = SpectralMethods(graph)          # inherits executor from graph
hd       = HyperdimensionalMemory(dim=10000, executor=executor)

Or via config:

from smgp.config import SMGPConfig, create_executor_from_config

cfg      = SMGPConfig.from_dict({"hd_dim": 10000,
           "hardware": {"enabled": True, "device": "/dev/smgpu0"}})
executor = create_executor_from_config(cfg)
graph    = SpectralMemoryGraph(hd_dim=cfg.hd_dim, executor=executor)

Features

Category Component Description
Core SpectralMemoryGraph Typed property graph with HD vector addressing
Core SpectralMethods Laplacian, GFT, Chebyshev convolution, wavelets
Core HyperdimensionalMemory 10,000-dim bipolar vectors, bind/bundle/similarity
Core TopologicalAnalyzer Persistent homology, Betti numbers, barcode
Core GraphRewriter Category-theoretic DPO graph rewriting
Memory MemoryStore Key-value persistence backend
Memory AssociativeMemory O(1) content-addressable HD recall
Memory MemoryLifecycle Persistence-based forgetting & eviction
Attention SpectralAttention O(N log N) multiscale spectral attention
Attention StreamingSpectralAttention Incremental online attention
Reasoning ClaimVerifier Path-based fact verification with proof subgraphs
Reasoning NeuroSymbolicPlanner Goal decomposition + symbolic constraint solving
Integration HuggingFace SMGPForCausalLM drop-in adapter
Integration LangChain SMGPMemory, SMGPVerifierTool
Integration REST API FastAPI server with JWT auth + rate limiting
Integration Vector DB Qdrant / Pinecone / Weaviate bidirectional sync
Integration ONNX/vLLM Export-ready attention wrapper
Hardware SMGPU RTL Open SystemVerilog 2017 FPGA accelerator
Hardware Python HAL HWExecutor — transparent FPGA offload
Hardware Bitstream make xclbin target for Alveo U280
CLI smgp version, graph-stats, verify, server

Configuration

from smgp.config import SMGPConfig

cfg = SMGPConfig(
    hd_dim=10000,
    hidden_dim=256,
    num_heads=8,
    num_scales=3,
    max_eigenvalues=64,
    memory_capacity=100000,
    pruning_threshold=0.1,
    seed=42,
)

# Load from file
cfg = SMGPConfig.from_yaml("config.yaml")
cfg = SMGPConfig.from_dict({"hd_dim": 5000, "hardware": {"enabled": False}})

Testing

pip install "smgp[dev,topology]"
python -m pytest tests/ tests_enhanced/ -v
Suite Tests Notes
tests/ 112 Core, spectral, HD, reasoning, integration, hardware wiring
tests_enhanced/ 123 CLI, distributed, event log, ONNX, streaming, vector DB, Hypothesis
Total 235 230 passed / 5 skipped (torch-dependent, no PyTorch required)

Hardware Acceleration

SMGPU is a domain-specific accelerator targeting Xilinx Alveo U280 (250 MHz, 8 GB HBM2).

All 6 RTL testbenches verified with Verilator 5.048:

Testbench Status
tb_spectral_engine ✅ PASS
tb_hd_engine ✅ PASS
tb_topology_engine ✅ PASS
tb_graph_rewrite ✅ PASS
tb_associative_memory ✅ PASS
tb_system_end_to_end ✅ PASS

Build targets:

cd hardware/fpga/build
make synth        # Vivado synthesis
make impl         # Place & route
make xclbin       # Generate Alveo U280 .xclbin
make bit_script   # Generate .bit bitstream

Links

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

smgp-1.0.0.tar.gz (217.0 kB view details)

Uploaded Source

Built Distribution

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

smgp-1.0.0-py3-none-any.whl (97.5 kB view details)

Uploaded Python 3

File details

Details for the file smgp-1.0.0.tar.gz.

File metadata

  • Download URL: smgp-1.0.0.tar.gz
  • Upload date:
  • Size: 217.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for smgp-1.0.0.tar.gz
Algorithm Hash digest
SHA256 cf6d530def5a85a9618d01fe4c0079b75c57923b9d8f462420c8e386021136ee
MD5 f507fa51245ca94672d84226a486f0f4
BLAKE2b-256 5b6076e12452fb0796db2c742df4afb559dfe79832ac613c5b4ceb208f091ec8

See more details on using hashes here.

Provenance

The following attestation bundles were made for smgp-1.0.0.tar.gz:

Publisher: publish.yml on rotsl/smgp

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

File details

Details for the file smgp-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: smgp-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 97.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for smgp-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 70d794ad1e0839625c8423f4da3f5c5c2c4eb61646cb6e346f8d1ef977131a93
MD5 afb14ac62da38d6b2330b709bf418f7e
BLAKE2b-256 45aaf6f3b9ad2f77fd7a8c589098f6b0baa3980df5968f20026c7e707e13df1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for smgp-1.0.0-py3-none-any.whl:

Publisher: publish.yml on rotsl/smgp

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