Skip to main content
Glama

shelfmark

License: MIT GitHub stars MCP

shelfmark: local hybrid retrieval for agent memory and codebases

Local hybrid retrieval for agent memory and codebases. One SQLite file, no services, no cloud. BM25 + dense embeddings fused with Reciprocal Rank Fusion, an optional cross-encoder reranker, and an MCP server so coding agents (Claude Code, Codex, anything MCP) can recall your notes, decisions, docs, and code instead of guessing.

A shelfmark is the code a librarian writes on a book so it can be found again. That is the whole product: before your agent answers, the librarian fetches the handful of notes and code chunks most likely to matter and puts them on the desk.

Why this exists · Quickstart · MCP server · What gets indexed · Evaluation · How it compares · Configuration

Why this exists

Agent harnesses accumulate knowledge: memory notes, ADRs, plans, standards, handoffs, and the code itself. The useful answer to most questions is already written down somewhere. shelfmark indexes all of it into one local SQLite file and answers "what did we decide about X / where did we handle Y" in a single query, with path:line citations.

shelfmark is the retrieval engine that came out of a year of running AI coding agents daily — most recently distilled from forgekit, an AI dev toolkit for coding agents. Every design choice below was forced by a real failure mode in that daily use, not picked off a paper.

Design choices that fell out of a year of measured iteration (see eval/holdout-policy.md and inline rationale comments):

  • Hybrid by default. BM25 catches identifiers and exact terms; embeddings catch paraphrase. RRF fusion beats either alone on mixed corpora.

  • Code-aware tokenization. camelCase/snake_case sub-tokens on both corpus and query sides ("create player" matches createPlayer). Measured +2.8pp code / +3.2pp overall.

  • Symbol-definition boost. Chunks whose defined symbol matches a query identifier get a rank-0 signal (+2.8pp code, zero regressions).

  • Selective reranking. Cross-encoder rerank helps code and standards, hurts memory recall (measured -10.5pp). The rerank policy is scope-aware; memory is never reranked.

  • Contextual chunk prefixes. Every chunk embeds with a type | repo | file | symbol header, not raw text.

  • Freshness without wall-clock. Optional recency prior for memory scope, deterministic (reference = max mtime among candidates), so evals stay reproducible.

Related MCP server: OmniDocs-RAG-CN

Quickstart

pip install shelfmark-rag   # or: pipx install shelfmark-rag

shelfmark-build      # first run writes a starter ~/.shelfmark/sources.yaml — edit it, then rerun
shelfmark-query "how do we handle retry timeouts"

First build downloads intfloat/multilingual-e5-small (~120MB). Everything after that runs offline.

git clone https://github.com/LucasSantana-Dev/shelfmark && cd shelfmark
python3 -m venv venv && venv/bin/pip install -e .

venv/bin/shelfmark-build
venv/bin/shelfmark-query "how do we handle retry timeouts"

MCP server (agent integration)

// e.g. Claude Code: .mcp.json or ~/.claude.json
{
  "mcpServers": {
    "shelfmark": {
      "command": "shelfmark-mcp"
    }
  }
}

(Local checkout instead of pipx install? Use "command": "/path/to/shelfmark/venv/bin/shelfmark-mcp".)

Two tools:

  • rag_query — full-corpus hybrid search (code, docs, commits, notes). Auto-scopes to the repo your agent is working in.

  • search_knowledge — cross-project search over durable knowledge only (memory/standards/plans/handoffs/adrs; configurable via RAG_KNOWLEDGE_SCOPE). Never reranked, by measurement.

examples/claude-code/ has the full loop: auto-recall on every prompt (UserPromptSubmit), incremental reindex on file writes (PostToolUse), drift reindex + weekly report at session start, and a nightly rebuild with an eval regression gate.

What gets indexed

sources.yaml declares everything (see sources.yaml.example):

kind

what

repos

source code (py/ts/js/sh, symbol-aware chunking), docs/**, README, CHANGELOG, docs/specs/**, roadmap, last 180d of commit messages

sources

arbitrary markdown globs, each under a free type label you filter on at query time

code_globs

loose scripts outside any repo

Incremental reindex (indexer.py --incremental <files>) keeps writes cheap; session_chunker.py can additionally index agent session transcripts.

Evaluation

The eval harness is the part most RAG setups skip. eval/run.py scores Hit@1/3/5 + MRR per scope against a JSONL dataset; eval/check.sh gates any change at >5pp regression vs a frozen baseline; eval/holdout-policy.md documents the train/holdout discipline (the holdout set is never used for tuning — numbers quoted from it are honest).

This repo ships a public, reproducible dataset (eval/dataset-public.jsonl) whose queries target this repository's own code and docs:

venv/bin/python indexer.py                 # index this repo (sources.yaml.example works as-is)
venv/bin/python eval/run.py --dataset eval/dataset-public.jsonl --label mine

Benchmark results and methodology: BENCHMARK.md.

To evaluate on YOUR corpus, write ~50 {"query", "expect_path_contains", "expect_scope"} lines, freeze a fifth of them as holdout, and wire eval/check.sh into your nightly rebuild. That regression gate is what keeps retrieval quality from silently rotting as the corpus grows.

How it compares

No cross-tool benchmark exists yet (see Methodology & honest limitations — we'd genuinely like to see one run). Qualitative trade-offs, no fabricated numbers:

Option

When to pick shelfmark instead

Why

mem0 (managed, cloud-first memory layer)

You want full local data ownership and cross-repo search

One SQLite file, zero setup, MCP native. mem0 adds a hosted service you may not need

Letta / MemGPT (stateful agent framework)

You want a retriever, not a framework

Standalone tool that plugs into any MCP client; Letta expects you to adopt its agent runtime

Zep (hosted conversation memory)

You want permanent, local, cross-repo recall, not just chat threads

Single machine, no hosted dependency; Zep targets conversation history, not code/docs

Cursor / Continue / Cody built-in indexing

You want search outside one editor, or from a non-IDE agent

Runs anywhere MCP runs; editor-built-in indexes don't leave the editor

DIY LangChain + Chroma/Weaviate

You want hybrid retrieval and an eval gate without wiring it yourself

Reranking, RRF fusion, and eval/check.sh regression gates ship in the box

Claude Code's built-in project memory

You want hybrid (lexical + semantic) search across repos, not one workspace

File-based single-workspace memory has no ranking and no cross-repo scope

Chroma / Weaviate raw, or Pinecone (no framework)

You want zero infrastructure to stand up

One SQLite file vs. a vector DB service + embedding pipeline + glue code

grep / ripgrep

You need paraphrase recall, not just exact substrings

Lexical-only; shelfmark fuses BM25 with embeddings so "retry timeout" also matches "backoff on failure"

Pick a hosted vector DB when you need multi-tenant scale across millions of documents — that's a different problem than agent recall over your own repos.

Want to measure and improve retrieval ranking quality on your own pipeline, independent of any specific agent? hitgate provides label-free regression testing for hybrid retrievers. shelfmark and hitgate share a common hybrid-retrieval foundation (BM25 + embeddings + RRF) but serve complementary use cases: shelfmark for zero-setup agent memory with MCP integration, hitgate for ranking evaluation and quality gates on any retriever you already have.

Configuration

All optional — see .env.example for the full list. Highlights:

var

default

effect

RAG_HOME

~/.shelfmark

data dir (index, sources.yaml)

RAG_MODEL / RAG_DIM

e5-small / 384

embedding model

RAG_BM25_WEIGHT

1.5

>1 favors lexical match

RAG_RERANK_AUTO

on

rerank weak/ambiguous queries

RAG_CODE_RERANK

off

bge-reranker-v2-m3 for code scopes (+4.9pp, ~2.2GB)

RAG_QLOG

off

local query telemetry (powers report.py)

Contributing

Issues and PRs welcome — especially a real cross-tool benchmark (see How it compares), support for more embedding models, or non-Claude MCP client examples. If shelfmark saves your agent a guess, a star helps others find it.

License

MIT

Available Tools

2 tools
rag_queryA

Hybrid semantic + BM25 search over the user's configured corpus: notes, docs, repo docs + README + CHANGELOG, recent git commits, session transcripts, and source code (TS/JS/Python/Shell) from the configured repos. Returns top-K chunks with path:line + symbol + repo citations. Auto-scopes to the current repo when cwd is inside one — pass scope_repos=['all'] to disable. Use instead of grep for fuzzy or cross-file recall.

ParametersJSON Schema
NameRequiredDescriptionDefault
cwdNoworking dir to drive auto-scoping (defaults to server cwd)
topNo
queryYes
scope_reposNoconfigured repo names, or pass ['all'] to disable cwd auto-scoping
scope_typesNosource types: the labels from sources.yaml plus built-ins changelog, repo-docs, repo-readme, spec, roadmap, code, workstation-code, commit, session

TDQS

A4.1/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the burden. It discloses hybrid search, auto-scoping based on cwd, and result format (path:line + symbol + repo citations). It implies a read-only operation but does not explicitly state it, nor does it mention side effects or permissions. Still, the provided behavior detail goes beyond a minimal description.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two concise sentences that are front-loaded with the core action and followed by scoping/usage details. Every phrase adds value, with no redundant fluff. Well-structured for an LLM to quickly grasp.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (5 params, no output schema, no annotations), the description covers the search scope, result format, scoping behavior, and an alternative use case. It is complete enough for an agent to invoke the tool correctly, though it omits explicit read-only confirmation and any potential rate limits.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 60%, and the description adds meaningful semantics for scope_repos (auto-scoping and disabling with ['all']) and references scope_types from sources.yaml. It also explains cwd drives auto-scoping. However, query and top are left to the schema without additional context, so it does not fully compensate for all parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it performs hybrid semantic + BM25 search over a specific corpus (notes, docs, repo docs, commits, transcripts, code) and returns top-K chunks with citations. It uses a specific verb ('search') and resource ('configured corpus'), but does not explicitly contrast with sibling search_knowledge. However, it differentiates from grep, giving some distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It explicitly says 'Use instead of grep for fuzzy or cross-file recall,' providing an alternative use case. It also explains auto-scoping behavior and how to disable it with scope_repos=['all']. However, it does not mention when to prefer search_knowledge, leaving a minor gap.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

search_knowledgeA

Semantic search over the knowledge layer — durable notes and decisions: memory notes, ADRs, plans, session handoffs, and standards (NOT source code or git commits). Cross-project by design (searches all repos, no cwd auto-scoping). Use for 'what did we decide / is there a note about X / did we hit this before'. For source-code or git-commit recall, use rag_query instead.

ParametersJSON Schema
NameRequiredDescriptionDefault
topNo
queryYes

TDQS

A4.3/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full behavioral burden. It discloses cross-project behavior (no cwd auto-scoping), the semantic nature of the search, and the exclusion of source code/git commits. This gives the agent important expectations about scope and limitations, though it does not mention result format or potential side effects (which are likely none).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is compact, front-loaded with the primary purpose, and every clause adds value — defining content types, scope, usage, and alternative in three sentences.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

The description covers what the tool searches, what it excludes, cross-project behavior, and when to use it versus the sibling. The only missing piece is the output/return format, but given the tool's simplicity and no output schema, the description is still quite complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema has 0% description coverage, so the description must explain the parameters. It only implicitly addresses 'query' through examples ('is there a note about X') and completely omits 'top', leaving its meaning and constraints undocumented. This is a significant gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Semantic search over the knowledge layer' and enumerates specific content types (memory notes, ADRs, plans, etc.), explicitly excluding source code/git commits. It also distinguishes from the sibling tool rag_query, making the tool's purpose unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It provides explicit when-to-use examples ('what did we decide / is there a note about X / did we hit this before') and an explicit alternative ('For source-code or git-commit recall, use rag_query instead'), clearly guiding selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. 2 tool updatesv1.0.0
    • First observedrag_query
    • First observedsearch_knowledge

TDQS

A4.1/5.0
Disambiguation5/5

The two tools have clearly distinct scopes: rag_query searches broadly across code, docs, and commits, while search_knowledge targets only durable knowledge artifacts. Their descriptions explicitly state when to use each, eliminating ambiguity.

Naming Consistency4/5

Both names use lowercase snake_case and are descriptive, but the pattern differs: 'rag_query' places the technology prefix before the verb, while 'search_knowledge' follows a verb-noun structure. This minor inconsistency doesn't cause confusion, but a unified pattern like 'search_all' and 'search_knowledge' would be cleaner.

Tool Count3/5

With only two tools, the server feels minimally scoped, but for a focused search/retrieval service this is arguably sufficient. The two tools complement each other well without redundancy, though a few more specialized search options could justify a higher score.

Completeness4/5

The two tools cover broad and knowledge-specific search, including source code, commits, notes, and decisions. Minor gaps exist such as lacking a tool to retrieve a specific document by ID or list available sources, but core retrieval needs are met.

Maintenance

ActivityMaintained
ResponsivenessNo issues

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Enables AI agents to index and search local files, websites, GitHub repos, and packages using hybrid retrieval with reranking, all through IDE chat.
    4
    Apache 2.0
  • A
    license
    Not graded
    quality
    B
    maintenance
    Enables AI agents to index and search local files, websites, GitHub repos, and packages with hybrid AI-powered retrieval, all locally through IDE chat.
    Apache 2.0
  • A
    license
    Not graded
    quality
    C
    maintenance
    Enables AI agents to search and ask questions about a local codebase with citations, using BM25 and optional embeddings, all offline.
    7
    1
    MIT

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/LucasSantana-Dev/shelfmark'

If you have feedback or need assistance with the MCP directory API, please join our Discord server