Why Context Matters
Without context, search results lack semantic grounding:How Context Works
Context is hierarchical and collection-scoped. Documents inherit context from:- Global context (applies to all collections)
- Collection root context (applies to entire collection)
- Path-specific context (applies to subdirectories)
Context Tree Example
Given this configuration:qmd://notes/work/meetings/2024-03-15.md inherits all matching contexts:
Adding Context
From Current Directory
If you’re inside a collection directory, QMD auto-detects the collection:Using Virtual Paths
Add context to any collection path usingqmd:// syntax:
Global Context
Global context applies to all collections:- System-level instructions for LLMs
- Organization or team context
- Default metadata that applies everywhere
Listing Contexts
* indicates global context.
Removing Context
Remove path context
Remove collection root context
Remove global context
Checking for Missing Context
- Collections without any context
- Top-level directories in collections that lack specific context
Context in Search Results
Context appears in all search output formats:CLI Output
JSON Output
MCP Results
When using QMD via MCP, context is included in tool results:Context Configuration File
Contexts are stored in~/.config/qmd/index.yml:
qmd context add ensures proper validation.
Context and Embeddings
Context is embedded with document chunks duringqmd embed. Each chunk’s embedding includes:
- Stored in the database alongside chunks
- Returned with search results
- Used by LLMs to understand document relevance
- Improved LLM decision-making (reranking, query expansion)
- Better document selection by agents using MCP
- User clarity about result provenance
Best Practices
Be specific and descriptive
Be specific and descriptive
Good context is concise but informative:✅
❌
❌
"Meeting transcripts from Q4 2024 executive team"❌
"Meetings"✅ "Internal API reference for authentication services"❌
"Docs"Use hierarchy effectively
Use hierarchy effectively
Start general at the collection root, then get specific in subdirectories:
Add context before embedding
Add context before embedding
Context doesn’t affect embeddings directly, but it’s best practice to define it before running
qmd embed so it’s available from the start.Use global context for system instructions
Use global context for system instructions
Global context is perfect for LLM instructions:
Check context regularly
Check context regularly
Run
qmd context check periodically to identify gaps, especially after adding new collections or directory structures.Context in LLM Workflows
When using QMD with LLMs (via MCP or CLI), context helps models:- Understand document type (meeting notes vs API docs vs journal entries)
- Assess relevance (is this internal docs or public knowledge?)
- Cite accurately (context provides provenance information)
- Filter appropriately (which collection to search based on user intent)
Related
- Collections - Organizing documents into searchable units
- Embeddings - How context relates to vector search
- MCP Server - Using QMD with LLMs
- CLI Reference - Context management commands