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.25.0.tar.gz (234.7 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.25.0-py3-none-win_amd64.whl (1.2 MB view details)

Uploaded Python 3Windows x86-64

epistemic_graph-0.25.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.25.0-py3-none-manylinux_2_28_aarch64.whl (1.2 MB view details)

Uploaded Python 3manylinux: glibc 2.28+ ARM64

epistemic_graph-0.25.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.25.0.tar.gz.

File metadata

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

File hashes

Hashes for epistemic_graph-0.25.0.tar.gz
Algorithm Hash digest
SHA256 48d992e40bdfd7f9a156fbef3f132b6ff3d6904575fce392c8ad19e619974abc
MD5 4a4a08a61a372089fa9dde03c791d228
BLAKE2b-256 d62ac03ad286d1b87501be066dac7191e5b890ee7e254b03f44e83f36119ee4b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for epistemic_graph-0.25.0-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 886676530c081d3a88a3d24a1d2ae9e89d5b6ae6f775178c8f1e792893188428
MD5 8ba46c7a6fb36ef9bc97435ae5be41ef
BLAKE2b-256 65ecc708eddfef9870de5fec21495598513ce6c2cf1c21416332955f08448816

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for epistemic_graph-0.25.0-py3-none-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5619ce6edf3114dd7c1e9bbbb06a1496c3413596d9f6642b37e081573f1dbcb2
MD5 ac94b26809f92fef1f8f4b7e00707020
BLAKE2b-256 3fc9464f31056c8530022a704ceba0b5184c5c79affa58ef4e22967c0b4bd35e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for epistemic_graph-0.25.0-py3-none-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4c029e00d5cd8c68cf8abe04d254643e4444721239f4470a46d177b7f286ebba
MD5 167085df4961947171fa15ee1ed7b82e
BLAKE2b-256 9c6bf97e074d2e07b439c29f7012c19811c0ba95d8c92ff78eb52a1bdc9c028d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for epistemic_graph-0.25.0-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 8a053fc7bb2221f30d25fdb784168b09bb6cf4665b02b2830829ae255abd23a0
MD5 4f444519147e1a2224e16c932ae108ae
BLAKE2b-256 8ffca69cf121bc411d78101e8ca40c663cbbc7b13242dea0afe62f46e38bf347

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