Skip to main content

Rust-based epistemic graph engine for agent-utilities

Project description

epistemic-graph

Unified Rust-Native Compute Engine for AI Agent Infrastructure
Consolidates graph operations, quantitative finance, data science, AST analysis, and OWL reasoning into a single high-performance binary.

Version Language License


Architecture

The epistemic-graph crate is the singular computation engine for the agent-utilities ecosystem. All high-performance operations route through this crate, exposed to Python via PyO3 FFI or accessed remotely via the Tokio UDS/TCP server.

┌──────────────────────────────────────────────────────────┐
│                    epistemic-graph                        │
│                                                          │
│  ┌─────────┐  ┌──────────┐  ┌─────────┐  ┌───────────┐  │
│  │  Graph   │  │ Finance  │  │  Data   │  │ Reasoning │  │
│  │  Core    │  │ Engine   │  │ Science │  │  Engine   │  │
│  │(petgraph)│  │          │  │         │  │ (Datalog) │  │
│  └─────────┘  └──────────┘  └─────────┘  └───────────┘  │
│  ┌─────────┐  ┌──────────┐  ┌─────────┐                 │
│  │   AST   │  │ Semantic │  │  Algo   │                 │
│  │ Parser  │  │  Store   │  │ Library │                 │
│  └─────────┘  └──────────┘  └─────────┘                 │
│                                                          │
│  ╔════════════════════════════════════════════════════╗   │
│  ║  Tokio Server (UDS/TCP + HMAC-SHA256 auth)        ║   │
│  ╚════════════════════════════════════════════════════╝   │
│                         ↕ PyO3 FFI                       │
│  ╔════════════════════════════════════════════════════╗   │
│  ║  Python: EpistemicGraph class                     ║   │
│  ╚════════════════════════════════════════════════════╝   │
└──────────────────────────────────────────────────────────┘

Features

Core Graph Engine (CONCEPT:KG-2.2)

  • petgraph-backed: Native-compiled Rust graph structures
  • Temporal Knowledge Graph (TKG): Ebbinghaus Forgetting Curve and fact decay natively integrated
  • Topological Sort: Sub-millisecond DAG resolving
  • DFS Cycle Detection: Returns precise cycle paths
  • Shortest Path: Efficient unweighted BFS traversal
  • Blast Radius: Transitive impact analysis to configurable depth
  • PageRank & PPR: Centrality computation
  • Community Detection: Louvain-style graph clustering
  • VF2 Subgraph Isomorphism: Pattern matching queries
  • Reactive State Ledger: Transaction log with replay for backend persistence

Finance Engine (CONCEPT:QF-1.0)

  • Portfolio Optimization: Mean-variance (MVO), min-variance, risk-parity, efficient frontier
  • Risk Metrics: VaR (historical + Monte Carlo), CVaR, Sortino, Calmar, max drawdown
  • Regime Detection: Hidden Markov Model (Baum-Welch + Viterbi)
  • Signal Generation: Rolling Z-score, EWMA, momentum, alpha combination, information coefficient
  • Execution Algorithms: TWAP/VWAP scheduling, market impact estimation, LOB matching
  • Pairs Trading: Spread signal generation and regime-aware position sizing

Data Science Engine (CONCEPT:DS-1.0)

  • OLS Regression: Gradient descent with configurable learning rate and epochs
  • K-Means Clustering: Parallel centroid computation
  • PCA: Eigenvalue decomposition via power iteration
  • Dataset Statistics: Mean, std, min, max, correlation matrix
  • Estimators: ridge / lasso / elasticnet / decisiontree / randomforest / gradientboosting / adaboost / svr (replaces sklearn on the hot path)
  • Training loss / optimizer kernels (CONCEPT:KG-2.22): softmax / log_softmax, cross_entropy (+grad), dpo_loss (Bradley-Terry, +grads), grpo_surrogate (PPO clip, +grad), kl_divergence (Schulman k3), adam_step / sgd_step — the pure-Rust performance path for the in-house training substrate, mirroring data-science-mcp trainers/objectives.py. client.datascience.{...}.

Reasoning Engine (CONCEPT:KG-2.23)

  • Transitive/Symmetric Inference: Compiled Datalog closures
  • Domain/Range Rules: OWL-style type inference
  • Property Chain Composition: Multi-hop rule chaining

AST Parser

  • Multi-Language: Python, Rust, TypeScript, JavaScript, Go (via tree-sitter)
  • Full Granularity: Functions, classes, methods, imports stored as Symbol nodes
  • Repository Ingestion: Directory walker with automatic graph population

Cargo Feature Flags

Feature Description Dependencies
ast Tree-sitter AST parser tree-sitter, language grammars
finance Quantitative finance engine (pure Rust)
datascience ML primitives (pure Rust)
reasoning OWL/Datalog reasoning (pure Rust)
compute All compute features finance + datascience + reasoning
server Tokio UDS/TCP server tokio, hmac, rmp-serde
full Everything compute + server + ast
all Alias for full (same as full)

Build examples

# Library only (default, no server)
cargo build

# With compute modules
cargo build --features compute

# Full build including server binary
cargo build --features full

# Run all tests
cargo test --lib --features compute

Quickstart

1. Installation

uv pip install -e .
# or
pip install -e .

2. Python Usage

import epistemic_graph

# Initialize
g = epistemic_graph.EpistemicGraph()

# Graph operations
g.add_node("AgentA", '{"type": "coordinator"}')
g.add_node("AgentB", '{"type": "worker"}')
g.add_edge("AgentA", "AgentB", '{"weight": 1.5}')

print("Order:", g.topological_sort())
print("Cycle:", g.find_cycle())

# Finance — portfolio optimization
weights = g.optimize_portfolio([0.1, 0.15, 0.08], [[0.04, 0.01, 0.005], ...], 0.02)

# Finance — risk metrics
metrics = g.risk_metrics([0.01, -0.02, 0.03, -0.005, 0.02])

# Data Science — regression
coeffs = g.linear_regression([[1.0, 2.0], [3.0, 4.0]], [3.0, 7.0])

# Reasoning — transitive inference
inferred = g.infer_transitive(["part_of", "depends_on"], ["related_concept"])

Development & Test

Run Unit Tests

# Rust tests (29 compute + graph tests)
cargo test --lib --features compute

# Python tests
uv run pytest

Format and Lint

pre-commit run --all-files

Documentation


Environment Variables

Variable Description
GRAPH_SERVICE_AUTH_SECRET HMAC-SHA256 secret for inter-process authentication
GRAPH_SERVICE_SOCKET Path to Unix Domain Socket for UDS communication
XDG_RUNTIME_DIR Directory for UDS socket placement

License

This project is licensed under the MIT License — see the LICENSE file for details.

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

epistemic_graph-0.26.0.tar.gz (241.6 kB view details)

Uploaded Source

Built Distributions

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

epistemic_graph-0.26.0-py3-none-win_amd64.whl (1.2 MB view details)

Uploaded Python 3Windows x86-64

epistemic_graph-0.26.0-py3-none-manylinux_2_28_x86_64.whl (1.3 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

epistemic_graph-0.26.0-py3-none-manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

epistemic_graph-0.26.0-py3-none-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file epistemic_graph-0.26.0.tar.gz.

File metadata

  • Download URL: epistemic_graph-0.26.0.tar.gz
  • Upload date:
  • Size: 241.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for epistemic_graph-0.26.0.tar.gz
Algorithm Hash digest
SHA256 44cdabc820aae8ce4775454bcf54b1945b46406ae3696d1ea240393c2e4dc002
MD5 3d748e7ff6ba8246403238d36d6f39b4
BLAKE2b-256 730e3deb3116f34982c5493b179d327beae5d25b8d3db9ac851b6bcc7feb8bfe

See more details on using hashes here.

File details

Details for the file epistemic_graph-0.26.0-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for epistemic_graph-0.26.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 9f6aff79879c869d8676861ce6ad6a4f03c5efd9596980f08fbc66a377ffc17c
MD5 d514f7983d5793ffd0b9a052ab2dbe1e
BLAKE2b-256 70902701064dbe0312acd3e0177342d52f06883b70c845f09fc3c96b5f868771

See more details on using hashes here.

File details

Details for the file epistemic_graph-0.26.0-py3-none-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for epistemic_graph-0.26.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dead59b0138b88ada11bddc575ec3a7b49c7b07c2d581aff58b7d3dcde376d41
MD5 be773be03063f1fcc023b5bf741d1d24
BLAKE2b-256 a6346df8697e3689a7609203f936337d08fb0f8248f790ec9302404b141b0d40

See more details on using hashes here.

File details

Details for the file epistemic_graph-0.26.0-py3-none-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for epistemic_graph-0.26.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 cad7d698d8a2aa34ea59600e5f24a6116eaa548e3848ca124f28edb4beadd4dd
MD5 a003a08a0be740b216c915d5c1484fd9
BLAKE2b-256 7ec564a5c6a3b5dadfe82ebf08c5c892797c27a8336503af6fa18d4d03016943

See more details on using hashes here.

File details

Details for the file epistemic_graph-0.26.0-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for epistemic_graph-0.26.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7fcd9c4c71ea5ff6607e27fa13742fce44fb107e329a4ac7dfa06f94828fa0e2
MD5 7bb175112c99735ac4c99bbb84e1f6ba
BLAKE2b-256 679f254c422417c2e13b28bdd974b4396c68526865086841e073266e01d3b143

See more details on using hashes here.

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