Skip to main content

Memory graph for AI agents that learns what to retrieve — and what to suppress.

Project description

CrabPath

CrabPath is a pure in-memory graph engine for retrieval routing that can learn from feedback and prioritize what to execute next, while staying independent of any model provider.

Install

pip install crabpath

Python API (pure callbacks)

from crabpath import Graph, Node, Edge, VectorIndex, split_workspace, traverse, apply_outcome

# 1) Build graph + texts from workspace
graph, texts = split_workspace("./workspace")

# 2) Caller owns embeddings
embed = lambda text: [1.0, 2.0]  # your vector model, local or remote
index = VectorIndex()
for node_id, text in texts.items():
    index.upsert(node_id, embed(text))

# 3) Caller owns LLM callbacks (optional)
def route_fn(query: str, candidate_ids: list[str]) -> list[str]:
    return candidate_ids[:3]

def score_fn(system_prompt: str, user_prompt: str) -> str:
    return '{"scores": {"node-id": 1.0}}'

# 4) Query and learn
seeds = index.search([0.1, 0.2], top_k=8)
result = traverse(graph=graph, seeds=seeds, route_fn=route_fn)
apply_outcome(graph=graph, fired_nodes=result.fired, outcome=1.0)

CLI (no providers, pure stdin/stdout)

# Build graph, texts, and optional index from a callback
crabpath init --workspace ./workspace --output ./crabpath-data --embed-command 'python3 embed_cb.py'

# Build index only
crabpath embed --texts ./crabpath-data/texts.json --output ./crabpath-data/index.json --command 'python3 embed_cb.py'

# Query by keyword
crabpath query "how do i deploy" --graph ./crabpath-data/graph.json --top 5

# Query by vector payload file
crabpath query "noop" --graph ./crabpath-data/graph.json --index ./crabpath-data/index.json --query-vector-stdin < vec.json

# Optional route callback and query scoring callback wiring
cat /tmp/query.vec | crabpath query "deploy" --graph ./crabpath-data/graph.json --index ./crabpath-data/index.json --route-command 'python3 route_cb.py' --embed-command 'python3 embed_cb.py'

Batch callbacks

Batching is available for both embedding and callback APIs using the same CLI entry point:

crabpath init --workspace ./workspace --output ./crabpath-data --embed-command 'python3 embed_batch.py'
crabpath query "deploy" --graph ./crabpath-data/graph.json --route-command 'python3 route_batch.py' --json

Internally, ThreadPoolExecutor is used to parallelize single-item fallback while preserving batch callbacks when provided.

Other pure graph commands

crabpath learn --graph graph.json --outcome 1.0 --fired-ids a,b,c
crabpath replay --graph graph.json --sessions ./sessions/*.jsonl
crabpath health --graph graph.json --json
crabpath merge --graph graph.json --json
crabpath connect --graph graph.json --json
crabpath journal --stats

What this project is

CrabPath is a library, not a hosted service. It does no network calls and persists no credentials. Callers pass in embedding and routing callbacks; CrabPath only manages graph logic, scoring plumbing, and state updates.

Paper

Technical details: https://jonathangu.com/crabpath/

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

crabpath-5.0.1.tar.gz (249.7 kB view details)

Uploaded Source

Built Distribution

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

crabpath-5.0.1-py3-none-any.whl (36.8 kB view details)

Uploaded Python 3

File details

Details for the file crabpath-5.0.1.tar.gz.

File metadata

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

File hashes

Hashes for crabpath-5.0.1.tar.gz
Algorithm Hash digest
SHA256 6878fd6a9f554b0c9d91e0c5bac94fa51fac1eec289d0f49b77ee5e9fea98b32
MD5 0d519f91a37e569c49d7e99e83751b2c
BLAKE2b-256 257746ba3b1f602ce663169be88cffcc9c37f93582497f5181d1ca122dcda74d

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabpath-5.0.1.tar.gz:

Publisher: publish.yml on jonathangu/crabpath

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

File details

Details for the file crabpath-5.0.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for crabpath-5.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f08aff537671b39fdfd6d16c070edf2f22a2250d92acc3f31699a0f1752a48d4
MD5 2b7c958ee39bcaa00d9ff0ddd65ababe
BLAKE2b-256 f02ca853a60f661ee018d4af14cda0c47683768f4e6658e6e42a7fea491e0e8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabpath-5.0.1-py3-none-any.whl:

Publisher: publish.yml on jonathangu/crabpath

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