Guides and resources for AI engineers: an agents course, five handbooks, a hands-on second-brain project and a vetted reading list.
JavaScript agent-skillsai-agentsai-engineeringclaudeclaude-codeclaude-skillsknowledge-graphknowledge-managementllmmcpobsidianpersonal-knowledge-basepkmsecond-brain
docs: retrieval
undefined-uiae9097e81352
diff --git a/README.md b/README.mdindex b645d2f..606d695 100644--- a/README.md+++ b/README.md@@ -116,7 +116,7 @@ you can see exactly what is coming and open a pull request against any of it.| [Structuring](docs/04-structuring/README.md) | page types, linking rules, schema, contradictions | **written** || [Graphs](docs/05-graphs/README.md) | what the graph is for, typed links, GraphRAG, metrics | **written** || [Agents](docs/06-agents/README.md) | roles, schedules, hooks, guardrails | **written** |-| [Retrieval](docs/07-retrieval/README.md) | query patterns, search, context budget | in progress |+| [Retrieval](docs/07-retrieval/README.md) | query patterns, search, context budget | **written** || [Outputs](docs/08-outputs/README.md) | writing, reports, publishing, learning | in progress || [Maintenance](docs/09-maintenance/README.md) | linting, review cadence, git, privacy, scaling | in progress || [Troubleshooting](docs/10-troubleshooting/README.md) | the failures everyone hits, with fixes | in progress |diff --git a/docs/07-retrieval/README.md b/docs/07-retrieval/README.mdindex ab1e4e5..20b8416 100644--- a/docs/07-retrieval/README.md+++ b/docs/07-retrieval/README.md@@ -2,15 +2,21 @@How to actually ask your vault things and get answers worth trusting.-## Planned+Everything before this was construction. This is the part you do every day, and+it is where a second brain either earns the setup or quietly becomes an archive+you stopped opening.-Being written. Outlines for each are in the [roadmap](../ROADMAP.md), and pull requests are welcome.+The single rule underneath the whole section: an answer that blends your notes+with the model's general knowledge is worse than no answer, because you cannot+tell which half is which.-- Asking the vault-- Query patterns-- Search tools-- Adding RAG when you need it-- Context budget+## Pages++- [Asking the vault](asking-questions.md)+- [Query patterns](query-patterns.md)+- [Search tools](search-tools.md)+- [Adding RAG when you need it](rag-on-top.md)+- [Context budget](context-budget.md)---diff --git a/docs/07-retrieval/asking-questions.md b/docs/07-retrieval/asking-questions.mdnew file mode 100644index 0000000..3725de4--- /dev/null+++ b/docs/07-retrieval/asking-questions.md@@ -0,0 +1,63 @@+# Asking the vault++You built the vault so answers would come from what you actually read. An agent+that quietly falls back on its own knowledge destroys that, and it does so+invisibly: the answer is fluent, plausible, and unverifiable.++## The rule++Every claim in an answer comes from a page, and names the page.++```+Answer from my vault only. Cite the page for each claim. If the vault does not+cover part of the question, say which part rather than filling it in.+```++That instruction belongs in `CLAUDE.md`, not typed each time. A rule you have to+remember is a rule that lapses on the day it matters.++## Start from the index++The agent should read `index.md` first, then open the pages that look relevant,+then follow links outward from those.++The alternative, a full-text sweep, is slower, spends context on near-misses, and+misses pages whose wording differs from your question. The index exists to make+this cheap; see [index.md and log.md](../04-structuring/index-and-log.md).++## Outside knowledge, labelled++Sometimes the model knows something useful that the vault does not contain. That+is fine as long as it is marked:++```+Cite vault pages for anything from my notes. Anything you know that my vault+does not contain, put under a separate heading marked outside the vault.+```++Separated, it is useful context. Blended, it makes the whole answer unreliable,+because you no longer know which parts you can trace.++## Empty is a valid answer++If the vault has nothing on a topic, the right response is one sentence saying+so.++An agent padding an empty result with general knowledge is the failure mode to+watch for, because it feels like a good answer. Notice when an answer contains no+page references at all; that is the signal.++## Answers should end with what is missing++```+Read: [[page]], [[page]], [[page]]+Not covered: whether this holds for the streaming case+```++Two lines, and they do more than they look. They tell you how much of the vault+the answer rests on, and the gap line is often the more useful half, because it+is a precise statement of what to go read next.++## Next++[Query patterns](query-patterns.md)diff --git a/docs/07-retrieval/context-budget.md b/docs/07-retrieval/context-budget.mdnew file mode 100644index 0000000..754d47f--- /dev/null+++ b/docs/07-retrieval/context-budget.md@@ -0,0 +1,66 @@+# Context budget++Every page the agent reads costs context, and quality degrades well before the+window is full. Reading more is not reading better.++## Progressive disclosure++The pattern that works:++1. **Index first.** What exists, one line each.+2. **Open the pages that matter.** Usually three to eight.+3. **Follow links one hop at a time,** stopping when new pages stop adding.++Each step is cheap and informs the next. The alternative, loading everything+plausibly related up front, spends most of the budget on pages that turn out+irrelevant, and pushes the useful ones into the middle of a long context where+attention is weakest.++## Why not paste the whole vault++Long-context models can hold a lot, and it is tempting to skip retrieval+entirely.++Two reasons not to. Attention is uneven across a long context, and material in+the middle is used less reliably than material at the edges, which is the finding+in "Lost in the Middle" and the reason position matters at all. And an answer+built from everything cannot be checked: you have no idea which pages it actually+used.++An answer citing five pages you can open beats a fluent answer built from four+hundred you cannot.++## Summary layers++Past a few hundred pages, add one level of index between the master index and+the pages: a short page per topic area, listing what is in that area and what+each page covers.++The agent reads the master index, opens the one topic index that matters, then+opens pages. Three cheap reads instead of one expensive one.++Do not let summary layers accumulate. Two levels is enough; three means you are+building a hierarchy nobody maintains, and summaries of summaries drift from+what is underneath them.++## Measuring what was read++```+List the pages you read to answer that, in the order you opened them.+```++Worth running occasionally. It exposes two problems: an agent reading thirty+pages when six would do, and an agent answering from three when the vault has+twenty relevant ones. Both are fixable by adjusting the instructions, and neither+is visible from the answer alone.++## Subagents for wide reads++When a question genuinely needs a lot of material, send a+[subagent](../06-agents/subagents.md). It reads in its own context and returns a+summary, so the main session pays for the answer rather than for the sources.++## Next++[Outputs](../08-outputs/README.md), where the vault starts producing rather than+answering.diff --git a/docs/07-retrieval/query-patterns.md b/docs/07-retrieval/query-patterns.mdnew file mode 100644index 0000000..f0bc600--- /dev/null+++ b/docs/07-retrieval/query-patterns.md@@ -0,0 +1,85 @@+# Query patterns++Some questions a vault answers far better than a search engine or a general+model. These are the ones worth building the habit around.++## What do I know about X++The basic one, and the reason most people build a vault.++```+What do I know about agent harnesses? Read the concept pages and the sources+behind them. Say where my sources disagree.+```++The second sentence is what makes it better than reading a page yourself. A+consolidated view across everything you read, with the disagreements surfaced,+is not something any single page contains.++## What connects X and Y++The question a search index cannot answer at all.++```+What connects retrieval quality and context length in my vault? Show the path+through pages, not just the endpoints.+```++Asking for the path matters. The intermediate pages are the reasoning, and they+are checkable in a way a bare conclusion is not.++## What have I changed my mind about++Only possible because of the [supersession+rules](../04-structuring/contradictions-and-supersession.md).++```+Find pages where a later source superseded an earlier claim. What did I believe,+what changed it, and when?+```++Run this quarterly. It is the closest thing to watching your own thinking from+outside, and it usually surfaces at least one belief you updated without+noticing.++## What is missing++```+Look at my concept pages on prediction markets. What questions do they raise+that no source in my vault answers?+```++This turns the vault into a reading list generated from your own gaps rather+than from what an algorithm thinks you would click.++## What did I say about this before++Especially useful with [chat exports](../03-ingestion/chat-exports.md) ingested.++```+Have I worked on this problem before? What did I conclude and what did I get+wrong?+```++## What contradicts this++```+I am about to argue that X. What in my vault argues against it?+```++The most valuable query in the set and the least used, because nobody+volunteers to be contradicted. A vault that only confirms you is a vault you+built badly.++## Questions to ask elsewhere++Anything about the present state of the world. Your vault knows what your+sources said on the day you saved them, and nothing since.++Anything general the model already knows. Asking your vault to explain a+well-documented concept from scratch gets you a worse version of what a plain+answer would give.++## Next++[Search tools](search-tools.md)diff --git a/docs/07-retrieval/rag-on-top.md b/docs/07-retrieval/rag-on-top.mdnew file mode 100644index 0000000..329e44d--- /dev/null+++ b/docs/07-retrieval/rag-on-top.md@@ -0,0 +1,72 @@+# Adding RAG when you need it++This guide argues against a vector database for a personal vault. That argument+has a threshold, and it is worth naming rather than treating as doctrine.++## When it starts to pay++Three conditions, roughly together:++**Scale past a few thousand pages,** where reading the index plus following+links stops fitting the context budget.++**Questions phrased in wording your pages do not use.** If you regularly fail to+find things you know are there, that is a recall problem, which is what+embeddings solve.++**A corpus you did not curate.** A vault that absorbed ten thousand documents+without a human deciding what mattered has no reliable structure to navigate,+so similarity is what is left.++Most personal vaults never hit all three. Mine has not, and I would not add the+maintenance for two out of three.++## What to embed++Not raw sources. Embed the wiki pages.++They are already semantic units, written by something that understood them, one+idea each. That is what chunking tries to approximate and rarely achieves.+Re-chunking them into fixed-size windows destroys the structure you paid for.++Embed the page title, aliases and body together. Titles carry a lot of signal+in a curated vault, because you chose them.++## Hybrid, not replacement++The useful arrangement keeps the graph in charge:++1. Embeddings find entry-point pages, including ones whose wording differs.+2. The graph expands from those entry points through links.+3. The agent reads the expanded set and answers with citations.++Embeddings supply recall, the graph supplies structure and the reason two pages+are related. Using similarity for the whole pipeline throws away the links,+which is the part of your vault that took work.++## Keeping the index fresh++This is the maintenance nobody accounts for. Every ingest changes pages, and a+stale embedding index returns pages whose content has moved on.++Re-embed changed pages as part of the ingest run, not on a separate schedule. An+index that lags by a week is quietly wrong in a way that produces plausible bad+answers.++If that sounds like more upkeep than it is worth, that is the correct reading for+most vaults, and it is the honest reason this section is short.++## Simpler things to try first++Before adding infrastructure, check whether the problem is actually recall.++Missing aliases are the most common cause of "I cannot find it". So is a bad+index. So is an ingest that stopped linking properly two months ago and left a+growing pile of orphans, which no retrieval method can reach.++Run `scripts/link_check.py` and read your index before concluding you need+vectors.++## Next++[Context budget](context-budget.md)diff --git a/docs/07-retrieval/search-tools.md b/docs/07-retrieval/search-tools.mdnew file mode 100644index 0000000..9f64c0f--- /dev/null+++ b/docs/07-retrieval/search-tools.md@@ -0,0 +1,65 @@+# Search tools++Retrieval in a plain-text vault is mostly grep. That sounds primitive and is+almost always enough.++## ripgrep++```bash+rg -i "graph rag" ~/brain --type md -l+rg -i "supersed" ~/brain -C 2+```++Instant on tens of thousands of files. The agent uses it by default when working+on the filesystem, and for "where did I mention this" it beats every fancier+option on both speed and predictability.++Its limit is exact wording. It cannot find the page about a concept you+described differently, which is what the graph and the index are for.++## Obsidian search++Fine for interactive use. Operators worth knowing: `path:`, `file:`, `tag:` and+`line:` for terms co-occurring on the same line, which cuts most false positives.++## Dataview++Queries over frontmatter, which is where structural questions get answered:++````+```dataview+TABLE updated, tags FROM "wiki/concepts"+WHERE contains(tags, "unverified")+SORT updated ASC+```+````++Anything phrased as "which pages have property P" is a Dataview query, and+answering those by asking the agent to read files is slower and less reliable.++## Combining them++The pattern that works: Dataview or ripgrep to get a candidate set, the graph to+expand from it, the agent to read and synthesise.++```+Find every page tagged unverified, follow their links, and tell me which claims+depend on unverified sources.+```++Mechanical filtering first, judgement second. Asking the agent to do the+filtering by reading everything wastes context on pages a query would have+excluded in milliseconds.++## When search gets slow++It will not, at personal scale. Ripgrep over ten thousand markdown files is+still instant, and if search feels slow the cause is usually the agent reading+too many files, not the search itself.++That is a context problem, not a search problem. See [context+budget](context-budget.md).++## Next++[Adding RAG when you need it](rag-on-top.md)diff --git a/docs/README.md b/docs/README.mdindex 511b3da..cfa2cf6 100644--- a/docs/README.md+++ b/docs/README.md@@ -12,7 +12,7 @@ Setup is written in full. The rest is being written section by section; see the| [Structuring](04-structuring/README.md) | page types, linking rules, schema, contradictions | **written** || [Graphs](05-graphs/README.md) | what the graph is for, typed links, GraphRAG, metrics | **written** || [Agents](06-agents/README.md) | roles, schedules, hooks, guardrails | **written** |-| [Retrieval](07-retrieval/README.md) | query patterns, search, context budget | in progress |+| [Retrieval](07-retrieval/README.md) | query patterns, search, context budget | **written** || [Outputs](08-outputs/README.md) | writing, reports, publishing, learning | in progress || [Maintenance](09-maintenance/README.md) | linting, review cadence, git, privacy, scaling | in progress || [Troubleshooting](10-troubleshooting/README.md) | the failures everyone hits, with fixes | in progress |diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex 2bf64ec..78abc93 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -246,31 +246,31 @@ Turning a one-off setup into a system that maintains itself.- Dry-run mode- Reviewing agent output in git diffs-## Retrieval (outline)+## Retrieval (done)How to actually ask your vault things and get answers worth trusting.-- [ ] **Asking the vault**+- [x] **Asking the vault**- Question shapes that work- Anchoring answers to pages and sources- Requiring citations from your own vault- What to do when the answer is not in there-- [ ] **Query patterns**+- [x] **Query patterns**- What do I know about X- What connects X and Y- What have I changed my mind about- What is missing from my understanding of X-- [ ] **Search tools**+- [x] **Search tools**- ripgrep as the default- Dataview queries- Full-text index options- When search is slow enough to matter-- [ ] **Adding RAG when you need it**+- [x] **Adding RAG when you need it**- The size threshold where it starts to pay- Chunking a wiki that is already chunked- Keeping the index fresh- Hybrid: graph for structure, vectors for recall-- [ ] **Context budget**+- [x] **Context budget**- Why you should not paste the whole vault- Progressive disclosure: index first, pages second- Summary layers