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 and index (auto local embeddings when installed)
crabpath init --workspace ./workspace --output ./crabpath-data --embed-command 'python3 embed_cb.py'
crabpath init --workspace ./workspace --output ./crabpath-data

# 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
# Query by local embedding
crabpath query "how do i deploy" --graph ./crabpath-data/graph.json --index ./crabpath-data/index.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'

Embeddings

Included. pip install crabpath brings all-MiniLM-L6-v2 (local, 80MB, CPU). No API key.

crabpath init --workspace ./ws --output ./data
# → embeds automatically

To use your own embeddings instead, pass --embed-command.

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 init --workspace ./workspace --output ./crabpath-data
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.3.0.tar.gz (251.3 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.3.0-py3-none-any.whl (37.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for crabpath-5.3.0.tar.gz
Algorithm Hash digest
SHA256 47b74c4341a7e1836a1b00d48ab3eb6b5cc20dffa904bdc51052a9d9423acf38
MD5 524381efb6c2fa44e0df3c7e7841309b
BLAKE2b-256 169c60be4f79d46d8ad41873c0e3943cca31aa071f91482ca987c8e03db684be

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabpath-5.3.0.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.3.0-py3-none-any.whl.

File metadata

  • Download URL: crabpath-5.3.0-py3-none-any.whl
  • Upload date:
  • Size: 37.9 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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 093e2e913f82336c7ed1ba433bfffec7f49c5e1ff89d8a34637881be87f0dc86
MD5 5d061f6be2164598d2e9871655254c71
BLAKE2b-256 cc2266452088841ab6fe544cc6bb5ad1202ea4face2eedbccf967639119758a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for crabpath-5.3.0-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