Files
Readable, reviewable, diffable, portable, and suitable for normal repository governance.
A local developer-memory skill should behave like a precision retrieval system—not a growing prompt. The system starts with a tiny routing contract, retrieves authoritative evidence through lexical and semantic channels, reranks it locally, then expands exact source sections only when the task requires more detail.
The skill should contain the operating procedure. The knowledge base should remain outside the prompt. Retrieval indexes should be rebuildable. Every answer should be traceable to exact source evidence.
Readable, reviewable, diffable, portable, and suitable for normal repository governance.
Tracks authority, scope, versions, symbols, relationships, lexical search, and session state.
Provides embedded vector retrieval without requiring a separate local service.
Scores the query against candidate passages before any evidence enters the agent context.
The system should maintain three different states. Mixing them creates stale prompts, opaque memory, and unsafe writeback.
Repository files, documentation, source code, ADRs, RFCs, tests, procedures, and reviewed notes.
Document cards, section summaries, claims, aliases, embeddings, lexical indexes, and relationships.
Small, query-specific sets of ranked excerpts with source paths, line ranges, authority, and conflicts.
Task state, selected evidence, open questions, and loaded-content hashes. Ephemeral by default.
An embedding-model change should trigger re-indexing, not a migration of canonical knowledge.
A generated summary never replaces the source passage that supports it.
The active working set can be evicted without deleting durable knowledge.
The agent should start with almost no knowledge-base content. Each expansion should be justified by the task and should reveal only the next useful layer.
High accuracy comes from combining retrieval channels, applying hard filters early, reranking with a stronger model, and using source authority as a first-class signal.
Determine whether the task is an exact lookup, procedure, troubleshooting question, architecture rationale, policy interpretation, historical decision, or cross-document synthesis.
Constrain repository, branch, component, environment, validity period, status, source type, language, and access scope before semantic recall.
Search exact identifiers, symbols, paths, SQLite FTS5/BM25, dense vectors, aliases, and explicit relationships independently.
Use reciprocal-rank fusion rather than adding incompatible lexical and vector scores.
Boost accepted decisions, current implementations, exact symbol matches, and validated procedures. Penalize deprecated, stale, or generated-only material.
Use a cross-encoder to score the query against the top candidate passages. This is the final precision gate before context injection.
Retrieve exact line ranges, parent sections, linked ADRs, tests, or procedures only for the selected candidates.
Return query interpretation, scopes, top evidence, conflicts, coverage, and available next expansions.
BM25 scores, cosine similarity, and model reranker scores live on different scales. Direct addition makes ranking unstable and hard to interpret.
Reciprocal-rank fusion combines list position rather than raw score. Introduce learned or weighted fusion only after collecting a labeled evaluation set.
RRF(document) = Σ [ weight(retriever) / (k + rank(document, retriever)) ]
initial settings:
lexical candidates: 50
semantic candidates: 50
exact/symbol candidates: 20
relationship candidates: 20
rerank fused top: 30–100
final evidence sections: 2–5
The design remains understandable because the canonical layer, control plane, semantic projection, and local model runtime have distinct duties.
| Component | Use for | Do not use as | Operational property |
|---|---|---|---|
| Repository files | Canonical knowledge, policy, code, ADRs, runbooks, examples | Fast global retrieval index | Reviewable and portable |
| SQLite + FTS5 | Metadata, authority, versions, relationships, exact and lexical retrieval, session state | Primary dense ANN engine | Embedded and transactional |
| LanceDB | Document, section, chunk, and symbol embeddings | Canonical governance record | Embedded semantic recall |
| Local embedding model | Query and corpus vectors | Final passage judgment | Offline and replaceable |
| Local reranker | Query-to-passage precision scoring | Broad first-stage recall | Higher cost, smaller candidate set |
| Session ledger | Loaded evidence, hashes, context state, evictions | Durable organizational knowledge | Ephemeral and query-specific |
Title, abstract, authority, scope, major topics, and document status. Useful for routing.
Heading path, purpose, summary, entities, and parent document. Useful for main retrieval.
Exact source text, line range, parent section, content hash, and source version. Useful for final context.
The skill explains when and how to retrieve. The CLI owns indexing, filtering, search, expansion, tracing, and evaluation. It emits structured JSON for reliable agent consumption.
repository/
├── skills/knowledge-recall/
│ ├── SKILL.md
│ ├── references/
│ └── scripts/kb.ts
├── cli/src/
│ ├── commands/
│ └── retrieval/
├── knowledge/
│ ├── sources/
│ ├── maps/
│ ├── glossary/
│ └── generated/
├── .knowledge/
│ ├── catalog.sqlite
│ ├── lance/
│ └── models/
└── evals/
├── retrieval-cases.jsonl
└── expected-evidence.jsonl
| Command | Purpose |
|---|---|
kb route | Identify candidate knowledge domains |
kb search | Run hybrid candidate retrieval |
kb open | Read exact authoritative evidence |
kb expand | Traverse parents, siblings, decisions, and tests |
kb trace | Show provenance, versions, and history |
kb context | Inspect the active session working set |
kb evaluate | Run retrieval benchmarks |
When repository or organizational context is needed, search first and ground the answer in exact evidence.
Return conflicts, missing coverage, stale sources, and abstention signals rather than smoothing them away.
Agents can propose changes. They should not directly mutate reviewed knowledge without a controlled approval path.
{
"interpretation": {
"intent": ["architecture-decision"],
"scopes": { "repository": ["core-platform-ai"] }
},
"results": [
{
"id": "section:remote-mcp-identity:local-proxy",
"title": "Local identity proxy",
"sourcePath": "knowledge/sources/mcp/identity-architecture.md",
"lineRange": [142, 191],
"whySelected": "Defines the local proxy and server validation boundary",
"authority": "accepted-architecture",
"status": "current",
"retrievalChannels": ["fts5", "vector", "relationship"],
"alreadyLoaded": false
}
],
"conflicts": [],
"coverage": 0.91,
"abstain": false
}
Repeatedly loading the same architecture sections is a hidden context tax. A session ledger converts retrieved evidence into a managed working set.
interface ContextLedgerEntry {
sessionId: string;
evidenceId: string;
contentHash: string;
loadedAt: string;
tokenCount: number;
reason: string;
relevance: number;
state: "active" | "summarized" | "evicted";
}
Persistent developer memory can carry prompt injection, stale instructions, secrets, and unsupported conclusions across sessions. Write controls are therefore part of retrieval quality—not a separate concern.
security and organizational policy
> repository-controlled instructions
> directory or component instructions
> task-specific plan
> explicit user request
> approved personal preference
> auto-generated memory
> model inference
kb propose --type correction --evidence .... The command should generate a patch, issue, or candidate record that includes the source evidence, proposed change, author, model provenance when applicable, and review status.A technically impressive vector index can still return stale, weak, or redundant evidence. Evaluation must incorporate authority, freshness, citation support, context cost, and abstention.
utility =
correct × authoritative × usable evidence
─────────────────────────────────────────
context tokens × latency
The architecture is intentionally incremental. Each phase produces a usable local skill and creates measurements for the next decision.
route, search, openThe architectural recommendation is an analysis synthesized from these primary specifications, documentation sets, and research papers. Product-specific capabilities should be revalidated before implementation because local-agent tooling changes quickly.