gptme-rag

v0.5.1 ChromaDB-based RAG (Retrieval-Augmented Generation) for gptme agents packages/gptme-rag View on GitHub

gptme-rag

Local semantic search over your files for AI agents: index directories into ChromaDB with local (sentence-transformers) or API embeddings, then query them from the CLI, from gptme's built-in rag tool, or from any MCP client.

Status: beta. Upstreamed from the now-archived gptme/gptme-rag and developed here. The gptme-rag package on PyPI is an old release from that repo — install from this repository for current features.

Why / when to use it

Use gptme-rag when an agent needs to find relevant passages in a large body of local text (docs, notes, code, a workspace's knowledge base) by meaning rather than exact words. It is the vector-search complement to gptme-wisdom (BM25/SQLite, good for exact terms over reference books). For structural code navigation see gptme-codegraph.

How it fits with gptme:

Install

# Lesson-matching library only (regex; no torch, ChromaDB or embeddings)
uv pip install "gptme-rag @ git+https://github.com/gptme/gptme-contrib#subdirectory=packages/gptme-rag"

# CLI / dense retrieval (local embeddings pull in sentence-transformers/torch)
uv tool install "gptme-rag[full] @ git+https://github.com/gptme/gptme-contrib#subdirectory=packages/gptme-rag"

# With the MCP server and lexical (TF-IDF) extras
uv tool install "gptme-rag[mcp,lexical] @ git+https://github.com/gptme/gptme-contrib#subdirectory=packages/gptme-rag"

Extras: full (CLI and dense retrieval), mcp (MCP server, includes full), lexical (scikit-learn TF-IDF library plus tiktoken), test / dev (include full). Existing plain installs used to include the dense stack: select full explicitly when upgrading a CLI or Indexer consumer. The base installation supports the lesson-matching Python API, not the gptme-rag console command. It uses the matcher's built-in YAML subset parser when PyYAML is absent; install PyYAML for unrestricted YAML frontmatter. The shared Claude Code hook also needs tomli on Python 3.10 to read configured lesson directories.

Quickstart

gptme-rag index ~/notes ~/projects/docs          # build/update the index
gptme-rag search "how do we rotate credentials"  # semantic search
gptme-rag status                                 # what's in the default index

The default index lives in ~/.cache/gptme/rag; pass --persist-dir to index, search, watch, clean, gc-orphans and mcp to use another one. Re-indexing is incremental (per-file change detection).

Commands

Command Description
index PATHS... [-p GLOB] Index files (default glob **/*.*). Options: --embedding-function, --device cpu|cuda, --chunk-size, --chunk-overlap, --file-limit (per directory, default 100000), --force-recreate
search QUERY [PATHS...] Search and assemble context. Options: -n/--n-results, --max-tokens, --format summary|full, --expand none|adjacent|file, -f/--filter GLOB (repeatable), --score, --explain, --weights JSON, --json, --raw
watch DIR Index DIR and keep the index updated as files change (--ignore-patterns)
status Document/chunk counts and source breakdown for the default index
clean [--force] Delete the index directory
gc-orphans [--apply] List (or delete) leftover Chroma segment directories not referenced by the index
mcp Run an MCP stdio server (needs the mcp extra)
benchmark indexing|search-benchmark|watch-perf DIR Performance benchmarks

Global flag: -v/--verbose.

Embeddings

--embedding-function accepts auto (default — reuse whatever model an existing collection was built with), modernbert, minilm, mpnet, openrouter or default.

Switching models on an existing index requires --force-recreate.

MCP server

gptme-rag mcp --persist-dir ~/.cache/gptme/rag
# e.g. register with Claude Code:
claude mcp add gptme-rag -- gptme-rag mcp

Tools: rag_query(query, top_k=5) (max 50), rag_index_status(), rag_index_refresh(directory, pattern="**/*.*"). Each accepts an optional persist_dir.

Python API

Beyond the CLI, the package exposes building blocks for agents that assemble their own retrieval:

Lesson match-term compatibility

Both top-level and nested match fields accept keyword/pattern lists or a single string. A scalar keywords: "foo, bar" is shorthand for two keywords. A scalar patterns value is one regex, including any commas: patterns: "x{1,3}y" remains intact.

Migration: older versions split top-level scalar patterns on commas (and did the same in the no-PyYAML fallback). Replace patterns: "foo, bar" with an explicit list, patterns: ["foo", "bar"], to keep matching either expression independently. Do not split commas that belong to a regex quantifier or literal. Lists work at both frontmatter levels and with either parser backend.

Numeric and date match terms retain their source spelling (3.10, 2026-08-05). With PyYAML, boolean/null values are excluded; quote literal terms such as "on", "true", or "null". The lightweight fallback is a YAML subset, not a complete YAML type resolver; quoting these terms makes intent explicit across backends.

Development

uv run pytest packages/gptme-rag/ -v -m "not slow"   # skip tests that load embedding models
uv run pytest packages/gptme-rag/ -v                 # everything

License

MIT