Local-first conversation cache, RAG, and routing to reduce cloud LLM spend.
Project description
RecallPy is a Python library and CLI that helps you cut cloud LLM costs by caching conversations, retrieving relevant context via RAG, and routing queries to local models when appropriate. It integrates natively with Cursor, Claude Code, and any OpenAI-compatible client.
Key features
- RAG memory — every conversation is chunked, embedded, and stored in SQLite for semantic retrieval
- Local draft answering — uses a cheap local model (Ollama) to answer common questions
- Intelligent routing — auto-escalates to cloud models when local confidence is low
- OpenAI-compatible proxy — drop-in caching + compression for existing clients
- IDE-native MCP tools —
handle_query,ingest_turn,escalate_packfor Cursor / Claude Code - Token savings tracking — see exactly how many cloud tokens you avoided
Quick start
python3.12 -m pip install recall-py
recall-py onboard
recall-py doctor
Library usage
import sqlite3
from recall_py.engine import handle_query, ingest_turn
from recall_py.ollama_client import OllamaClient
from recall_py.settings import AppSettings
settings = AppSettings.load()
conn = sqlite3.connect(settings.resolved_db_path())
ollama = OllamaClient(settings.ollama)
result = await handle_query(
conn, settings, ollama,
query="How does the routing policy work?",
thread_id=None,
)
# result.context_pack.citations has the relevant context
await ingest_turn(
conn, settings, ollama,
thread_id=result["thread_id"],
role="assistant",
content="The routing policy...",
title="my-session",
workspace_fingerprint=result["workspace_fingerprint"],
provider="my-app",
)
CLI
| Command | Purpose |
|---|---|
recall-py onboard |
First-time setup: config, DB, Ollama, MCP snippet |
recall-py serve |
HTTP API (health + optional proxy) |
recall-py mcp-stdio |
MCP server for IDE integration |
recall-py doctor |
Check DB, migrations, Ollama |
recall-py metrics |
Token savings overview |
recall-py index |
Index workspace docs into RAG memory |
Documentation
Full documentation is available at rehanpunjwani.github.io/TokenGuard.
Installation options
See the Getting Started guide for pipx, uv, and source installs.
Requirements
- Python 3.12+
- Ollama with
nomic-embed-textandllama3.2(configurable)
Architecture
RecallPy stores every user and assistant message in SQLite, chunks them, and embeds each chunk via Ollama. On each query, it retrieves the most semantically relevant chunks and optionally drafts a local answer. When the local draft is too uncertain, it signals escalation — you paste the context pack into your cloud model instead. All token operations are tracked for savings reporting.
Docker
bash scripts/docker-up.sh
Starts RecallPy + Ollama with a single command. See docker-compose.yml.
Contributing
See CONTRIBUTING.md for guidelines and the Development guide for technical setup.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file recall_py-0.1.1.tar.gz.
File metadata
- Download URL: recall_py-0.1.1.tar.gz
- Upload date:
- Size: 33.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ac9a92377e3fa2193afde887193ddb977a23e396a922580d7518d563e4f288e
|
|
| MD5 |
2876e6be5eaab830b8f0bca88fd4623f
|
|
| BLAKE2b-256 |
bbad13c3d7309685a4d93d8cb15f8d5430035e7780bf64e6580c4e1430632837
|
File details
Details for the file recall_py-0.1.1-py3-none-any.whl.
File metadata
- Download URL: recall_py-0.1.1-py3-none-any.whl
- Upload date:
- Size: 38.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.24 {"installer":{"name":"uv","version":"0.11.24","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9f879d99451886feec1446b4b83acae05d42b96e6567be534588c097d7d555f3
|
|
| MD5 |
df50bf5b37e3b82beed4acb5beef89d9
|
|
| BLAKE2b-256 |
ef512c43efd83243048d6a2ae493137754dfe126f3e87b36e3543519c6ae0f85
|