Skip to main content

Git × Mem0: A version-controlled memory system for LLMs

Project description

GitMem0

v0.4.1 | Git x Mem0: A pure-local, version-controlled memory system for LLMs.

English | 中文

GitMem0 gives AI agents persistent memory without external APIs or cloud services. It combines Git-style version tracking with Mem0's intelligent memory layer — all running on your machine.

Features

  • Pure local — no API keys, no cloud, everything stays on disk
  • Fast — daemon architecture, model loads once, queries in <0.05s
  • Multi-signal retrieval — semantic search + BM25 + entity graph + recency + importance scoring
  • Confidence decay — memories naturally fade over time (exponential decay), archived to L2 when stale
  • Memory consolidation — duplicate detection, contradiction resolution, auto-induction (events → insights), L2 compression
  • Knowledge graph — entities (person, technology, project...) and relations auto-extracted
  • Version control — every memory is immutable like a git commit, with full diff/history
  • LLM-ready context — Lost-in-the-Middle arrangement, token budget compression
  • Multilingual — uses paraphrase-multilingual-MiniLM-L12-v2, supports 50+ languages
  • LLM Judge plugin — optional LLM-assisted scoring with automatic fallback to rules

Quick Start

# Install from PyPI
pip install gitmem0

# One-click setup (config, DB, daemon, hooks — all in one command)
gitmem0 setup

# Or install from source (development)
pip install -e .
gitmem0 setup

# First call auto-starts daemon (loads model, ~30s), subsequent calls <0.1s
python -m gitmem0.client '{"action":"remember","content":"I prefer dark mode","type":"preference","importance":0.9}'
python -m gitmem0.client '{"action":"query","message":"user preferences"}'
python -m gitmem0.client '{"action":"search","query":"dark mode"}'
python -m gitmem0.client '{"action":"stats"}'

Architecture

User/LLM
    |
    v
client.py (thin, <0.1s startup)
    | TCP socket
    v
auto.py daemon (port 19840, model loaded once)
    |
    +---> extraction.py  (multi-signal importance + type inference)
    +---> retrieval.py   (two-stage: recall → rerank)
    +---> context.py     (Lost-in-the-Middle + token budget)
    +---> decay.py       (exponential decay + consolidation)
    +---> entities.py    (knowledge graph extraction)
    +---> store.py       (SQLite + FTS5 + L0 LRU cache)
    +---> embeddings.py  (sentence-transformers, 384d)

CLI

# Typer CLI (alternative to client.py)
gitmem0 setup                                                # one-click setup
python -m gitmem0.cli add "Python is great for prototyping" --type fact --importance 0.7
python -m gitmem0.cli search "Python" --top 3
python -m gitmem0.cli context "what languages does the user like"
python -m gitmem0.cli extract "I always use type hints. Never skip tests."
python -m gitmem0.cli stats
python -m gitmem0.cli decay --dry-run
python -m gitmem0.cli consolidate --threshold 0.85
python -m gitmem0.cli contradictions --dry-run
python -m gitmem0.cli auto-induct --dry-run
python -m gitmem0.cli compress --dry-run
python -m gitmem0.cli metrics
python -m gitmem0.cli export --format jsonl -o backup.jsonl
python -m gitmem0.cli migrate re-embed

Claude Code Integration

GitMem0 works as a memory backend for Claude Code via hooks:

# Setup hooks
python hooks/setup_claude_code.py

This installs UserPromptSubmit and Stop hooks that automatically query and store memories during conversations.

Memory Types

Type Example Default Importance
preference "I prefer dark mode" 0.9
instruction "Always use type hints" 0.9
insight "React is better for this UI" 0.8
fact "Python is a programming language" 0.7
event "Deployed v2.0 on Monday" 0.4

Configuration

Edit ~/.gitmem0/config.toml:

[storage]
db_path = "gitmem0.db"
active_threshold = 0.3

[decay]
lambda_rate = 0.01  # ~70 day half-life

[retrieval]
weight_semantic = 0.25
weight_bm25 = 0.15
weight_entity = 0.15
weight_recency = 0.10
weight_importance = 0.20
weight_confidence = 0.15

[embedding]
model_name = "paraphrase-multilingual-MiniLM-L12-v2"
dimension = 384

[llm]
backend = "mimo"      # mimo | openai | claude | ollama
api_key = ""          # Your API key (not needed for ollama)
base_url = ""         # Custom base URL (optional)
model = ""            # Model name (optional, uses backend default)

LLM Judge Plugin

Supported Backends

Backend Config backend Default Model API Key
Xiaomi Token Plan mimo MiMo Required (tp-xxxxx)
OpenAI openai gpt-4o-mini Required
Claude (Anthropic) claude claude-haiku-4-5-20251001 Required
Ollama (local) ollama qwen2.5:7b Not needed

Quick Setup

Add to ~/.gitmem0/config.toml:

# Example: OpenAI
[llm]
backend = "openai"
api_key = "sk-xxxxx"
model = "gpt-4o-mini"

# Example: Claude
[llm]
backend = "claude"
api_key = "sk-ant-xxxxx"

# Example: Ollama (local, no API key)
[llm]
backend = "ollama"
model = "qwen2.5:7b"

# Example: Xiaomi Token Plan
[llm]
backend = "mimo"
api_key = "tp-xxxxx"

Or set environment variables:

export GITMEM0_LLM_API_KEY="tp-xxxxx"
export GITMEM0_LLM_BASE_URL="https://token-plan-cn.xiaomimimo.com/v1"

The daemon auto-detects the config and enables LLM-assisted scoring. All methods gracefully fall back to rules if the API is unavailable.

Custom LLM Judge

Implement the LLMJudge protocol to plug in any LLM:

from gitmem0.extraction import LLMJudge, MemoryType

class MyJudge(LLMJudge):
    def score_importance(self, content, context="") -> float | None:
        # Return 0.0-1.0, or None to use rule-based default
        ...

    def should_remember(self, content) -> bool | None:
        # Return True/False, or None to use rule-based default
        ...

    def infer_type(self, content) -> MemoryType | None:
        # Return MemoryType, or None to use pattern matching
        ...

    def summarize(self, memories: list[str]) -> str | None:
        # Return summary, or None to use concatenation
        ...

# Pass to AutoMemory
from gitmem0.auto import AutoMemory
auto = AutoMemory(llm_judge=MyJudge())

Without an LLM Judge, the system falls back to rule-based scoring automatically.

Testing

pip install -e ".[dev]"
pytest

License

MIT

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

gitmem0-0.4.1.tar.gz (71.9 kB view details)

Uploaded Source

Built Distribution

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

gitmem0-0.4.1-py3-none-any.whl (63.0 kB view details)

Uploaded Python 3

File details

Details for the file gitmem0-0.4.1.tar.gz.

File metadata

  • Download URL: gitmem0-0.4.1.tar.gz
  • Upload date:
  • Size: 71.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for gitmem0-0.4.1.tar.gz
Algorithm Hash digest
SHA256 ad47e2dce925c75481d5c672141cefe4dbf14683326ccfc8bd46b179128b7fba
MD5 c0d7b927cc8cc611ec8a223849fa8add
BLAKE2b-256 025b07ef36314794f6edacf6691934cf8b67595f0e5d94281fa7fd808a125803

See more details on using hashes here.

File details

Details for the file gitmem0-0.4.1-py3-none-any.whl.

File metadata

  • Download URL: gitmem0-0.4.1-py3-none-any.whl
  • Upload date:
  • Size: 63.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for gitmem0-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1fd29ca75348ad9c06184360f5d77899b3e6aa207bdbe58b59aac51463d67667
MD5 3e7455dca010f968dfe2a448844405ed
BLAKE2b-256 789d4dce9a83f4c4ae6bd873dedb86b8c561ad023fb5d42319ec9006d9a57328

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