Enable search¶
Agents find pages in three tiers, each switched on only when the one below stops being enough:
- Navigate: read the root
index.mdof the knowledge-base folder and the folder indexes, then runrgover the knowledge-base folder. Always available. - Filter: query frontmatter with
uv run poe find(type, tag, status, folder, trust tier). Always available. - Search: hybrid search with qmd, which combines keyword search, local embeddings and reranking. Optional.
uv run poe search "<question>" runs
kb search. It uses qmd when the
knowledge base's collection exists, and otherwise falls back to a built-in
text search: it counts the case-insensitive matches of the question's words
of 3 characters or more in each page, skips the index.md files, and
prints the 20 best pages as <folder>/path:count. The fallback needs
nothing installed. The agent's query skill calls the same task, so enabling
qmd needs no change to the agent.
Set up qmd¶
- Install qmd following its README, and check that
qmdis on yourPATH. -
From the repository root, create the collection, its contexts and the embeddings:
This runs
kb search --setup, which adds a collection over the Markdown files of the knowledge-base folder (<folder>/**/*.md, where<folder>isbundlein the[tool.kb]table ofpyproject.toml), one context per folder taken fromschema/taxonomy.yaml, and computes the embeddings with local models. -
Try it:
-
After adding or changing pages, refresh the index (
kb search --reindex, which runsqmd updateandqmd embed):
The index lives outside the repository and can be rebuilt from the
knowledge-base folder at any time. The collection records the folder's
path: after you
rename the knowledge-base folder, run
qmd collection remove <collection> && uv run poe search-setup, where
<collection> is the collection name.
The collection name¶
Each knowledge base has its own collection, so several knowledge bases can
share one qmd installation. kb search computes the name:
- by default, the knowledge base's
kb_name(read frompyproject.toml, whose project name is<kb_name>-tools), orkbif it cannot be read; - or the value of the environment variable
KB_QMD_COLLECTION, when it is set in the shell or in.env.
Migrate from the kb collection (before v0.4.0)¶
Before v0.4.0 the collection was always called kb. After
updating:
qmd collection remove kb # the old collection covers the same folder, so remove it first
uv run poe search-setup # recreates it under the new name, with folder contexts and embeddings
qmd collection list # check that it is there
First check with qmd collection list that kb points at this knowledge
base's folder (always kb/ before v0.5.0): if you ran several knowledge
bases before v0.4.0, it may belong to another one. qmd collection rename kb <kb_name> is faster than
removing it, because it keeps the embeddings and the folder contexts.
Is qmd worth it?¶
Measure before you install anything. tools/retrieval-eval/questions.yaml
keeps real questions with the pages that should answer them, and
kb eval reports which tiers reach those
pages.
-
Add questions with the pages a good answer uses. Two kinds are useful:
- questions the knowledge base answers routinely: they show that the first tiers keep working;
- questions that were hard to answer (the first searches missed the pages): they show whether qmd would help.
questions: - question: Why do DNS changes take hours to show up? expected: [/systems/dns.md, /systems/ttl.md] - question: Which Concept pages cover networking? expected: [/systems/dns.md] filters: {type: Concept, tag: networking}filtersis optional; it runs the question throughkb find. -
Run the evaluation:
Each line shows, per tier, how many expected pages are in the top 10 and the rank of the first one, e.g.
1/2 @3. The last line gives the mean recall@10 of each tier. -
Decide:
- index+text reaches the pages of the hard questions too: the first two tiers are enough; improve the titles and descriptions of the pages that rank low instead of adding a tier.
- index+text misses pages that are there under other words: install qmd
as above, then run
uv run poe evalagain. The qmd column now runsqmd query; keep qmd if it reaches the pages the first tiers miss.
A CI gate such as uv run poe eval --min-recall 0.8 (in CI or in
tasks.toml) exits 1 when index+text recall@10 drops below 0.8. Set the
threshold for the set you keep: hard questions lower the mean on purpose,
so gate on a representative set, or set the threshold just below today's
recall. Pass --no-qmd where qmd is not installed consistently.