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[embeddings]

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'

Local Embeddings (no API key)

pip install crabpath[embeddings]
crabpath init --workspace ./ws --output ./data

Uses all-MiniLM-L6-v2 (80MB, CPU). No API key needed.

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.2.0.tar.gz (251.5 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.2.0-py3-none-any.whl (38.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for crabpath-5.2.0.tar.gz
Algorithm Hash digest
SHA256 7de48821b545f58ea16c441bfd83139621805c2f94b60275f6cd6efd77634a31
MD5 afaef10d383cdbb3537e6bce8e0bfe59
BLAKE2b-256 382e0a7f0b5ba0d19813592560c3299b5a4e155391f6d22b30cd87dbb1488b22

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: crabpath-5.2.0-py3-none-any.whl
  • Upload date:
  • Size: 38.0 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 767ea48cc1872d57eec9a057900e7a801b8dc949511554346e545efc5f0b569e
MD5 db861a25a081524dc2ec108af702149f
BLAKE2b-256 b7b595c5d6e8ab49a6cc4dd02385739835809b26d04db022e1a6cd2bf9304654

See more details on using hashes here.

Provenance

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