Skip to main content
Glama
longmem

longmem

by marerem

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 marerem/longmem MCP server


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()
  ┌─────────────────────────────────────────────────────┐
  │  1. pre-filter by category (ci_cd / auth / db / …)  │
  │  2. semantic search  (Ollama or OpenAI embeddings)   │
  │  3. keyword search   (SQLite FTS5 exact match)       │
  │  4. merge + rank results                             │
  └─────────────────────────────────────────────────────┘
        │                          │
   score ≥ 85%               score < 85%
        │                          │
        ▼                          ▼
  cached solution           AI reasons from scratch
  + edge cases                      │
  + team knowledge               "it works"
  (any project)                     │
                                    ▼
                          confirm_solution()
                          saved once — surfaces
                          from 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


Related MCP server: MCP Memory Server

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.

Cold start — getting value from day one

longmem is most useful once it has entries. The fastest way to seed it:

Option 1 — review as you go. After every solved problem this week, run longmem review and describe what you fixed. Ten entries is enough to feel the difference.

Option 2 — team import. If a teammate already has entries, they export and you import:

# teammate
longmem export team_knowledge.json

# you
longmem import team_knowledge.json

Option 3 — shared DB. Set db_path (or db_uri for S3/cloud) to the same location for the whole team. Every save is instantly available to everyone.


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.

Team knowledge base

Save facts that are true across your whole stack under project="shared" so they surface from any repo:

save_solution(
  problem="why oauth2-proxy uses port 4181 not default 4180",
  solution="General: 4180 is the oauth2-proxy default. 4181 means something else already occupies 4180.\n\nThis team's setup: Sinfonia always runs on 4180. Every other project uses 4181+ by convention.",
  project="shared",
  category="networking",
  tags=["oauth2-proxy", "ports", "nginx"]
)

search_similar searches all projects — a shared entry surfaces automatically from any repo without needing search_by_project.

Three-layer solution format — write solutions so they work for anyone who finds them:

Layer

Scope

How to save

1. General pattern

Universal — any team

always include in solution text

2. Team-wide fact

Your whole stack

project="shared"

3. Project detail

One repo only

project="<repo>" + enrich_solution

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

Contributions are very welcome — this project grows with the community that uses it.

Whether it's a bug fix, a new feature, better docs, or just sharing your use case — all of it helps. If you're unsure whether an idea fits, open an issue first and we'll figure it out together.

Getting started:

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

Good first contributions:

  • New category suggestions

  • Edge cases you hit in real projects

  • IDE integrations (JetBrains, VS Code, Neovim, etc.)

  • Better error messages

  • Seed datasets — export your own entries and share them as a starter pack

Ways to contribute without code:

  • Star the repo if you find it useful

  • Share it with your team

  • Open an issue if something is confusing — unclear UX is a bug


License

MIT — see LICENSE.

mcp-name: io.github.marerem/longmem

Available Tools

11 tools
add_edge_caseA

Record a context where a cached solution didn't work as-is.

Call this when search_similar returned a match but it needed modification to work in the current project. The edge case is appended to the entry so future suggestions include the caveat.

Inputs: entry_id (required), edge_case (required). Returns: result

confirm_solutionA

Auto-save a confirmed solution using context from the last search_similar call.

Call this after solving a problem instead of save_solution — you only need to provide the solution text. Problem description, category, tags, and language are taken automatically from the last search_similar call.

If save_solution was already called manually this session, this is a no-op (no duplicate will be created).

Inputs: solution (required), project. Returns: result

correct_solutionA

Fix a specific piece of text in an already-saved solution.

Call this when the user corrects a name, term, or detail that was saved incorrectly — for example 'it's not called Paperless-NGX, it's Papertagging'. Replaces all occurrences of find with replace in the solution text.

Use enrich_solution to add new context. Use correct_solution to fix wrong text.

Inputs: entry_id (required), find (required), replace (required). Returns: result

delete_solutionA

Permanently delete a saved entry.

Use this to remove entries that were saved incorrectly, contain wrong information that can't be fixed with correct_solution, or are no longer relevant. This cannot be undone.

Inputs: entry_id (required). Returns: result

enrich_solutionA

Append new context to an already-saved solution.

Call this when a conversation reveals additional details AFTER a solution was already saved — for example, a follow-up clarification that makes the solution more reusable across projects.

This is NOT for failures (use add_edge_case for those). This is for enrichment: new facts, patterns, or context that improve the answer.

Inputs: entry_id (required), context (required). Returns: result

list_recentA

List the most recently saved memory entries.

Use this to audit what has been saved — for example, to find a recently saved entry whose id is not in context. Results are ordered newest-first.

Inputs: limit. Returns: result

rebuild_indexA

Rebuild the vector search index for faster similarity search.

LanceDB falls back to brute-force scan when the table has fewer than 256 rows. Once you have 256+ entries, call this once to build an ANN index — subsequent searches will be significantly faster.

Safe to call at any time; existing data is not modified.

Inputs: no named parameters. Returns: result

save_solutionA

Save a problem/solution pair to the cross-project memory.

Call this after successfully solving a problem so future sessions — in any project — can find and reuse the solution. Returns the entry ID which can be passed to add_edge_case later.

Inputs: problem (required), solution (required), category (required), project, +2 more. Returns: result

search_by_projectA

List saved entries for a specific project.

Use this at the start of a new conversation when you need to find a project-specific entry to correct or enrich but no entry_id is in context. Returns entry ids, problems, and solutions so you can pick the right one and pass its id to correct_solution or enrich_solution.

Inputs: project (required), query, limit. Returns: result

search_similarA

Search the cross-project memory for solutions similar to the current problem.

Call this FIRST before reasoning about a problem from scratch. If similarity ≥ threshold a cached solution is returned — check edge_cases to see if any known limitations apply to the current context. If no match is found, solve normally and then call confirm_solution.

Inputs: problem (required), category, tags, language, +1 more. Returns: result

statsA

Return database statistics: total entries, breakdown by category, and date range.

Useful for understanding the size and composition of the memory store, and for deciding when to call rebuild_index (threshold: 256+ entries).

Inputs: no named parameters. Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.4/5.0

    Scored across 11 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: edge cases, confirmation, correction, deletion, enrichment, listing, indexing, saving, project search, similarity search, and statistics. There is no ambiguity between them.

    Naming Consistency5/5

    All tools use snake_case with a verb_noun pattern (e.g., add_edge_case, confirm_solution). The exception 'stats' is a common shorthand and still fits the pattern as a noun. Overall highly consistent.

    Tool Count5/5

    With 11 tools, the set is well-scoped for a memory management system. It covers all necessary operations without being bloated or insufficient.

    Completeness4/5

    The surface covers saving, retrieving, updating, deleting, and searching solutions, plus edge cases and enrichment. Minor gaps exist, such as no direct 'get solution by ID' tool, but this can be worked around via search methods.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      C
      maintenance
      Provides persistent memory and a codebase knowledge graph for AI coding assistants, enabling shared context across multiple tools like Claude, Cursor, and ChatGPT, with significant token reduction.
      5
      26 npm
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Provides long-term memory for AI coding agents, enabling them to remember, search, and organize information across sessions and platforms like Claude Code, ChatGPT, and Cursor.
      8
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Persistent memory + intelligent context for Claude Code. Save and reuse solutions, decisions, and patterns across projects.
      43
      7
      MIT