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

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.24.0.tar.gz (180.9 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.24.0-py3-none-win_amd64.whl (872.7 kB view details)

Uploaded Python 3Windows x86-64

epistemic_graph-0.24.0-py3-none-manylinux_2_28_x86_64.whl (997.9 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ x86-64

epistemic_graph-0.24.0-py3-none-manylinux_2_28_aarch64.whl (915.8 kB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

epistemic_graph-0.24.0-py3-none-macosx_11_0_arm64.whl (838.3 kB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

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

File metadata

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

File hashes

Hashes for epistemic_graph-0.24.0.tar.gz
Algorithm Hash digest
SHA256 cd06df4dbf8faa1920707f893d7c31b52170d7aed14c8dd1c94940a326a5c72a
MD5 bca6131ed92a12b2777d57a93d165e5e
BLAKE2b-256 d0a7cd387ce8b708c95425f2b295ff910efb13df1612a9ebc07efb0b115582b3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for epistemic_graph-0.24.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 81769e0aa456c00f0c24a9a834980922faa7e00652bb541bcdc9b5e50c76ca9c
MD5 2117ecfe90eb6d59b7b89b997e825f87
BLAKE2b-256 650f9461a766f0a7bf95cad8967e210eba83454a6841b3adb0dc325aac043f4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for epistemic_graph-0.24.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0a60a38a68b5b53589b0e5889e39e999dc9d93a3282e5d4657f7eedb8258cbfc
MD5 ef06944824984492b25a64fec0fcbcc9
BLAKE2b-256 575345e4af7dddff1b5306869b9488759bb5db818157d7c7d5a10e4ea3f45aec

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for epistemic_graph-0.24.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 7f63280feca0c95f05c6e35f676c24674548101147a66e35b325de76eb61b3cc
MD5 4fdecae1ba32133e242a2c64f26ffa4d
BLAKE2b-256 5de86c54cb35793ed9d3bff1edc0da1bee48de802246cacf13136706ce1fa26e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for epistemic_graph-0.24.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 657c3aebdbfa814d36a24d0e508e4a6a9133d4137f9adc19bb4629ea94ef93df
MD5 e9078036cfef14671ae22232bc5e3596
BLAKE2b-256 6678a633d500c981ef25bdcf290178f10618b38e8484bfc595a7bf0a3e5c1631

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