agentleFS
zilliztechzilliztech/memsearch/CLAUDE.md

memsearch

CLAUDE.md2.7k starsChanged 9 months agoMITView on GitHub

memsearch is a semantic memory search engine for markdown knowledge bases, built on Milvus. The plugin is a first-class component of memsearch — it's the primary real-world application that demonstrates the library in action. It gives Claude Code automatic persistent memory across sessions with zero user intervention. Architecture: 4 shell hooks + 1 skill + 1 background watcher

Trending

More talk lately.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 6 mentionsMar 2026: 0 mentionsApr 2026: 3 mentionsMay 2026: 2 mentionsJun 2026: 0 mentionsJul 2026: 1 mentionAug 2026: 5 mentionsSep 2026: 9 mentionsOct 2026: 3 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the zilliztech/memsearch repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about zilliztech/memsearch

The biggest 5 of 29 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 29

Talked about on GitHub and Hacker News (29 times).

On GitHub · 28

23 more on GitHub

On Hacker News · 1

The file

We split this CLAUDE.md into the rules it gives an agent

8 rules. About 0 are common, 1 is distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    When modifying hooks/skills, keep in mind:

    line 92
  2. Very specific:

    All hooks output JSON to stdout (additionalContext for context injection, systemMessage for visible hints, or empty {})

    line 93
  3. Very specific:

    Leave model unset in the Claude Code skills' frontmatter so users can choose a default through CLAUDE_CODE_SUBAGENT_MODEL.

    line 98
  4. Very specific:

    Hybrid search by default: Every collection has both dense vector and BM25 sparse fields.

    line 106
  5. Very specific:

    Shared prompt template: All five plugins share a single summarize.txt template (maintained in plugins/_shared/prompts/, synced via …

    line 108
  6. Very specific:

    Remote Milvus query() requires a filter: Use chunk_hash != "" as a "match all" filter when no filter is provided (Milvus Lite doesn't …

    line 109
  7. Very specific:

    Use the repository-local $release-memsearch skill for release operations.

    line 124
  8. Very specific:

    Always use uv run python -m pytest instead of uv run pytest to avoid system Python pytest conflicts.

    line 132

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

<!-- This file is for AI agents (Claude Code, Cursor, Copilot, etc.) working in this repository. It also serves as a shared project memory — recording conventions, architecture decisions, and common patterns that all contributors (human or AI) should follow. Symlinked as AGENT.md and MEMORY.md for compatibility with other tools. -->

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

Build & Test Commands

# Install in development mode
uv sync --all-extras

# Run all tests (use python -m pytest to avoid system pytest conflicts)
uv run python -m pytest

# Run a single test file
uv run python -m pytest tests/test_chunker.py

# Run a specific test
uv run python -m pytest tests/test_store.py::test_upsert_and_search -v

# Serve docs locally
uv run mkdocs serve

# Run the CLI
uv run memsearch --help

Architecture

memsearch is a semantic memory search engine for markdown knowledge bases, built on Milvus.

Data Flow

Markdown files → Scanner → Chunker → Embedder → MilvusStore
                                                      ↓
                               User query → Embedder → Hybrid Search (dense + BM25 + RRF) → Results

Core Library (src/memsearch/)

  • core.py — MemSearch class: the public Python API that orchestrates everything. Entry point for index(), search(), compact(), watch().
  • store.py — MilvusStore: Milvus wrapper handling collection creation, upsert, hybrid search (dense cosine + BM25 sparse + RRF reranking), and cleanup. The chunk_hash (composite ID of source+lines+content+model) is the VARCHAR primary key.
  • chunker.py — Splits markdown by headings into Chunk dataclasses. SHA-256 content hash enables dedup. compute_chunk_id() generates composite IDs matching OpenClaw's format.
  • embeddings/__init__.py — EmbeddingProvider protocol + lazy-loading factory (get_provider()). Providers: openai (default), google, voyage, jina, mistral, ollama, local, onnx.
  • scanner.py — Walks directories to find .md/.markdown files, returns ScannedFile list.
  • config.py — Layered TOML config: dataclass defaults → ~/.memsearch/config.toml → .memsearch.toml → CLI flags.
  • cli.py — Click CLI wrapping the Python API. All commands resolve config via resolve_config() then instantiate MemSearch.
  • watcher.py — watchdog-based file watcher with debounce, used by memsearch watch and the Claude Code plugin.
  • compact.py — LLM-powered chunk summarization (OpenAI/Anthropic/Gemini).
  • reranker.py — Optional cross-encoder reranking (ONNX or PyTorch backend). Disabled by default; enable via reranker.model config.

Claude Code Plugin (plugins/claude-code/)

The plugin is a first-class component of memsearch — it's the primary real-world application that demonstrates the library in action. It gives Claude Code automatic persistent memory across sessions with zero user intervention.

Architecture: 4 shell hooks + 1 skill + 1 background watcher

plugins/claude-code/
├── hooks/
│   ├── common.sh                # Shared setup: PATH, memsearch detection, collection name, watch PID
│   ├── session-start.sh         # SessionStart: start watch and inject recent memories
│   ├── user-prompt-submit.sh    # UserPromptSubmit: recall capability hint
│   ├── stop.sh                  # Stop: extract last turn → summarize → lazily create heading → append (async)
│   ├── session-end.sh           # SessionEnd: stop watch process
│   └── parse-transcript.sh      # Last-turn extractor: finds last user question → EOF, formats with role labels for LLM (Python 3, no jq)
├── scripts/
│   └── derive-collection.sh     # Derive per-project collection name from project path
├── transcript.py                # JSONL transcript parser for Claude Code conversation files (L3 deep drill)
└── skills/
    └── memory-recall/
        └── SKILL.md             # Skill (context: fork): search → expand → transcript in subagent

Key design: skill-based memory recall. Memory retrieval is handled by a memory-recall skill that runs in a forked subagent context (context: fork). Claude automatically invokes the skill when it judges the user's question could benefit from historical context. The subagent autonomously performs search, evaluates relevance, expands promising results, and returns a curated summary — all without polluting the main conversation context.

Three-layer progressive disclosure (all in subagent):

  1. L1 (search): Subagent runs memsearch search to find relevant chunks
  2. L2 (expand): Subagent runs memsearch expand <chunk_hash> to get full markdown sections
  3. L3 (transcript): Subagent runs memsearch transcript <jsonl> --turn <uuid> --context 3 to drill into original conversations (core CLI auto-detects the format; transcript.py remains as the plugin-local, Claude-specific parser exercised by tests/test_transcript.py)

Supporting hooks:

  • SessionStart injects cold-start context (recent daily logs) so Claude knows history exists
  • UserPromptSubmit returns a lightweight systemMessage capability hint ("[memsearch] Recall available if needed") to increase skill trigger awareness
  • Stop hook is async and non-blocking — extracts last turn only, calls claude -p --model haiku (with CLAUDECODE= to bypass nested session detection) to summarize as third-person notes, appends to daily .md

When modifying hooks/skills, keep in mind:

  • All hooks output JSON to stdout (additionalContext for context injection, systemMessage for visible hints, or empty {})
  • common.sh is sourced by every hook — changes there affect all hooks. It derives a per-project COLLECTION_NAME via derive-collection.sh and passes --collection automatically through run_memsearch() and start_watch()
  • The watch process uses a PID file (.memsearch/.watch.pid) for singleton behavior. Milvus Lite falls back to one-time index() at session start
  • stop.sh has a recursion guard (stop_hook_active) since it calls claude -p internally, and sets MEMSEARCH_NO_WATCH=1 to prevent the child process from interfering with the main session's watch
  • The memory-recall skill uses context: fork — the subagent has its own context window and does not see main conversation history
  • Leave model unset in the Claude Code skills' frontmatter so users can choose a default through CLAUDE_CODE_SUBAGENT_MODEL. See skill model selection for precedence and overrides
  • transcript.py lives in the plugin directory (not in core library) since it is entirely Claude Code JSONL-specific

Key Design Decisions

  • Markdown is the source of truth. Milvus is a derived index, rebuildable anytime from .md files.
  • Composite chunk ID as PK. hash(source:startLine:endLine:contentHash:model) — enables natural dedup without a separate cache.
  • ONNX bge-m3 as plugin default. The Claude Code plugin hooks default to onnx provider (bge-m3, CPU, no API key). The Python API still defaults to openai.
  • Hybrid search by default. Every collection has both dense vector and BM25 sparse fields. Search uses RRF to combine them. RRF scores are normalized to [0, 1] (theoretical max = num_retrievers / (k + 1)).
  • [llm] + [prompts] config. New config sections for LLM provider selection and custom prompt templates. [compact] is deprecated but still works (fallback: [llm] > [compact] > defaults). Plugins read prompts.summarize for custom session summarization prompts. Migration plan: [compact] will be removed in the next major version (1.0). During the transition, resolve_config() emits a DeprecationWarning when user config files contain [compact]. The compact CLI command resolves LLM settings as cfg.llm.* or cfg.compact.*.
  • Shared prompt template. All five plugins share a single summarize.txt template (maintained in plugins/_shared/prompts/, synced via scripts/sync-prompts.sh). Template uses {{AGENT_NAME}} placeholder.
  • Remote Milvus query() requires a filter. Use chunk_hash != "" as a "match all" filter when no filter is provided (Milvus Lite doesn't enforce this, but Milvus Server does).

Versioning & Release

Six release components — bump only the versioned components that changed:

ComponentVersion filePublish channel
memsearch (PyPI)pyproject.tomlPyPI (automated via GitHub Actions on tag push)
Claude Code pluginplugins/claude-code/.claude-plugin/plugin.jsonMarketplace (.claude-plugin/marketplace.json)
Codex plugin(none)install.sh (no version management)
DeepSeek Harness pluginplugins/dsh/package.jsonnpm (@zilliz/memsearch-dsh, trusted publishing via release-dsh.yml)
OpenClaw pluginplugins/openclaw/package.jsonClawHub (clawhub package publish)
OpenCode pluginplugins/opencode/package.jsonnpm (@zilliz/memsearch-opencode, trusted publishing via release.yml)

Use the repository-local $release-memsearch skill for release operations. See CLAUDE.local.md for machine-specific development and published-artifact E2E rules.

Project Conventions

  • Uses uv + pyproject.toml for dependency management (not pip).
  • Optional deps via extras: [google], [voyage], [ollama], [local], [onnx], [all]. The Claude Code plugin uses memsearch[onnx] for zero-config ONNX embedding.
  • Docs at docs/ use mkdocs-material. The site/ directory is build output — do not commit.
  • Always use uv run python -m pytest instead of uv run pytest to avoid system Python pytest conflicts.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.