Skip to main content

Persistent cross-project memory for Cursor and Claude Code — stores problem/solution pairs with semantic search

Project description

longmem

Cross-project memory for AI coding assistants.
Stop solving the same problems twice.

PyPI Python 3.11+ License: MIT Tests Coverage Open Issues Closed Issues


Your AI solves the same bug in a different project six months later. Writes the same boilerplate. Explains the same pattern. You already knew the answer.

longmem gives your AI a persistent memory that works across every project and every session. Before reasoning from scratch, it searches what you've already solved. After something works, it saves it. The longer you use it, the less you repeat yourself.

You describe a problem
        │
        ▼
  search_similar()   ──── match found (≥85%) ────▶  cached solution + edge cases
        │
    no match
        │
        ▼
  AI reasons from scratch
        │
   "it works"
        │
        ▼
  confirm_solution()  ──── saved for every future project

Why longmem

longmem others
Cost Free — local Ollama embeddings Requires API calls per session
Privacy Nothing leaves your machine Sends observations to external APIs
Process Starts on demand, no daemon Background worker + open port required
IDE support Cursor + Claude Code Primarily one IDE
Search Hybrid: semantic + keyword (FTS5) Vector-only or keyword-only
Teams Export / import / shared DB path / S3 Single-user
License MIT AGPL / proprietary

Quickstart

1. Install

pipx install longmem

2. Setup — checks Ollama, pulls the embedding model, writes your IDE config

longmem init

3. Activate in each project — copies the rules file that tells the AI how to use memory

cd your-project
longmem install

4. Restart your IDE. Memory tools are now active on every chat.

Need Ollama? Install from ollama.com, then ollama pull nomic-embed-text. Or use OpenAI — see Configuration.


How it works

longmem is an MCP server. Your IDE starts it on demand. Two rules drive the workflow:

Rule 1 — search first. Before the AI reasons about any bug or question, it calls search_similar. If a match is found (cosine similarity ≥ 85%), the cached solution is returned with any edge-case notes. Below the threshold, the AI solves normally.

Rule 2 — save on success. When you confirm something works, the AI calls confirm_solution. One parameter — just the solution text. Problem metadata is auto-filled from the earlier search.

The rules file (longmem.mdc for Cursor, CLAUDE.md for Claude Code) wires this up automatically. No manual prompting.

AI forgot to save? Run longmem review — an interactive CLI to save any solution in 30 seconds.


CLI

Command What it does
longmem init One-time setup: Ollama check, model pull, writes IDE config
longmem install Copy rules into the current project
longmem status Config, Ollama reachability, entry count, DB size
longmem export [file] Dump all entries to JSON — backup or share
longmem import <file> Load a JSON export — onboard teammates or migrate machines
longmem review Manually save a solution when the AI forgot

longmem with no arguments starts the MCP server (used by your IDE).


Configuration

Config lives at ~/.longmem/config.toml. All fields are optional — defaults work with a local Ollama instance.

Switch to OpenAI embeddings

embedder       = "openai"
openai_model   = "text-embedding-3-small"
openai_api_key = "sk-..."   # or set OPENAI_API_KEY

Install the extra: pip install 'longmem[openai]'

Team shared database

Point every team member's config at the same path:

# NFS / shared drive
db_path = "/mnt/shared/longmem/db"

Or use cloud storage:

# S3 (uses AWS env vars)
db_uri = "s3://my-bucket/longmem"

# LanceDB Cloud
db_uri = "db://my-org/my-db"
lancedb_api_key = "ldb_..."   # or set LANCEDB_API_KEY

No shared mount? Use longmem export / longmem import to distribute a snapshot.

Tuning

similarity_threshold = 0.85   # minimum score to surface a cached result (default 0.85)
duplicate_threshold  = 0.95   # minimum score to block a save as a near-duplicate (default 0.95)

MCP tools

The server exposes 11 tools. The two you interact with most:

  • search_similar — semantic + keyword hybrid search. Returns ranked matches with similarity scores, edge cases, and a keyword_match flag when the hit came from exact text rather than vector similarity.
  • confirm_solution — saves a solution with one parameter. Problem metadata auto-filled from the preceding search.

Full list: save_solution, correct_solution, enrich_solution, add_edge_case, search_by_project, delete_solution, rebuild_index, list_recent, stats.

Call rebuild_index once you reach 256+ entries to compact the database and build the ANN index for faster search.


Category reference

Categories pre-filter before vector search — keeps retrieval fast at any scale.

Category Use for
ci_cd GitHub Actions, Jenkins, GitLab CI, build failures
containers Docker, Kubernetes, Helm, OOM kills
infrastructure Terraform, Pulumi, CDK, IaC drift
cloud AWS/GCP/Azure SDK, IAM, quota errors
networking DNS, TLS, load balancers, timeouts, proxies
observability Logging, metrics, tracing, Prometheus, Grafana
auth_security OAuth, JWT, RBAC, secrets, CVEs
data_pipeline Airflow, Prefect, Dagster, ETL, data quality
ml_training GPU/CUDA, distributed training, OOM
model_serving vLLM, Triton, inference latency, batching
experiment_tracking MLflow, W&B, DVC, reproducibility
llm_rag Chunking, embedding, retrieval, reranking
llm_api Rate limits, token cost, prompt engineering
vector_db Pinecone, Weaviate, Qdrant, LanceDB
agents LangChain, LlamaIndex, tool-calling, agent memory
database SQL/NoSQL, migrations, slow queries
api REST, GraphQL, gRPC, versioning
async_concurrency Race conditions, event loops, deadlocks
dependencies Version conflicts, packaging, lock files
performance Profiling, memory leaks, caching
testing Flaky tests, mocks, integration vs unit
architecture Design patterns, service boundaries, refactoring
other When nothing above fits

Contributing

git clone https://github.com/mariia-eremina/longmem
cd longmem
uv sync --group dev
uv run pytest

Pull requests welcome — bug fixes, features, docs, tests.


License

MIT — see LICENSE.

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

longmem-0.1.1.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

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

longmem-0.1.1-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file longmem-0.1.1.tar.gz.

File metadata

  • Download URL: longmem-0.1.1.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.5

File hashes

Hashes for longmem-0.1.1.tar.gz
Algorithm Hash digest
SHA256 757d333f7791223e2af900689532bdf851005fef4955b8650448fed0d67e9243
MD5 3566cfbbe3d4a07d9478259ced7798c8
BLAKE2b-256 eff87a44965549fd0d92f72d9e3ce79f29cff8bd4ab9c577f0b7a0f22de0b640

See more details on using hashes here.

File details

Details for the file longmem-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: longmem-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.5

File hashes

Hashes for longmem-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e8d4898ecc757d96a9d9159dc050ccfa22209c56626683255387e0ca5758e6c7
MD5 c78438d29da754119061eb3d10ca2b98
BLAKE2b-256 d76322a34381d59870db144f76e90c187d768207183c26fd96da58769a209f30

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