Knowledge Base Management
Maintain a structured markdown knowledge base for project documentation, code references, and learnings.
Tool split:
- Write operations (add, edit, delete files): direct file system tools
- Read/search operations: qmd MCP tools (
qmd_search,qmd_vector_search,qmd_deep_search,qmd_get,qmd_multi_get,qmd_status) - After any write: run
qmd updatein the terminal to re-index so future searches reflect the change
Knowledge Base Structure
~/git/knowledge-base/
├── index.md # Central index with references to all content
└── repos/ # Repository-specific documentation
├── <repo-name>/ # One directory per repository
│ ├── overview.md # Repository overview
│ ├── architecture.md # Code structure and architecture
│ ├── testing.md # How to run tests
│ └── ... # Additional repo-specific docs
└── ...
Operation Modes
Add Content
When the user asks to add content to the knowledge base:
-
Determine target location
- If repo-specific:
~/git/knowledge-base/repos/<repo-name>/ - If general knowledge:
~/git/knowledge-base/ - Ask user only if ambiguous
- If repo-specific:
-
Identify appropriate file using qmd
- Use
qmd_search(orqmd_deep_searchfor semantic matching) to find existing files covering the same topic - If a matching file is found, use
qmd_getto read its full content - Create a new file only when no existing file matches the topic
- Default to
overview.mdfor general repo information
- Use
-
Intelligent merge (CRITICAL)
- DO NOT simply append - this creates duplication
- Read the destination file via
qmd_getbefore editing - Check if similar content already exists
- If content exists:
- Update/enhance existing content with new information
- Merge bullet points without duplication
- Replace outdated information
- If content is new:
- Find the most logical section to insert it
- Add to appropriate heading or create new heading
- Maintain existing document structure
-
Write the file using file system tools (create or edit)
-
Maintain structure
- Use clear markdown headings
- Group related information together
- Keep consistent formatting
- Use bullet points for lists
- Use code blocks for commands/code snippets
-
Update index.md
- Add reference to new file if created
- Keep index organized by category
- Use descriptive link text
-
Verify and confirm
- Show user what was added/updated
- Report location of changes
Delete Content
When the user asks to delete content from the knowledge base:
-
Locate content using qmd
- Use
qmd_searchfor keyword matches orqmd_deep_searchfor semantic search - Call
qmd_geton the returned document(s) to read the full context - Confirm with user if multiple matches found
- Use
-
Remove precisely using file system tools
- Delete the specific content, not entire files unless requested
- Remove associated headings if section becomes empty
- Clean up orphaned references
-
Update index.md
- Remove references to deleted files
- Update references if content was moved/consolidated
-
Re-index by running
qmd update -
Report changes
- Show what was deleted
- Confirm completion
Search Content
When the user asks to search the knowledge base, use qmd MCP tools exclusively:
| Use case | Tool |
|---|---|
| Exact keyword / phrase | qmd_search |
| Semantic / natural language | qmd_vector_search |
| Best quality, hybrid | qmd_deep_search |
| Retrieve a specific file | qmd_get <path> |
| Retrieve multiple files | qmd_multi_get <glob> |
| Check index health | qmd_status |
Show the user the document paths, scores, and relevant snippets returned by qmd. For deep
dives, follow up with qmd_get on the most relevant results.
Maintain Knowledge Base
When the user asks to maintain or clean up the knowledge base:
-
Check index health with
qmd_status- Review collection info and any warnings
-
Scan entire structure
- Use
qmd_multi_get "**/*.md"to read all files in the knowledge base - Use
qmd_get index.mdto understand documented structure - Identify files not referenced in index
- Use
-
Check for duplication
- Use
qmd_deep_searchwith topic keywords to surface similar content across files - Flag sections that appear in multiple places
- Consolidate duplicates using file system tools:
- Keep the most comprehensive version
- Delete redundant content
- Add cross-references if needed
- Use
-
Verify organization
- Ensure repo-specific content is in
repos/<repo-name>/ - Move misplaced files to correct locations
- Verify file naming follows conventions:
overview.md- general repo informationarchitecture.md- code structuretesting.md- test instructionssetup.md- environment setuptroubleshooting.md- common issuescommands.md- useful commands
- Ensure repo-specific content is in
-
Check index.md completeness
- Ensure all files are referenced
- Remove broken links
- Add missing files
- Organize by logical categories:
- General Knowledge
- Repository Documentation
- Troubleshooting
- References
-
Improve formatting
- Ensure consistent heading levels
- Fix markdown linting issues
- Standardize code block formatting
- Normalize bullet point styles
-
Re-index by running
qmd update -
Generate report
- Summary of changes made
- List of duplicates consolidated
- Files moved or renamed
- Items added to index
- Recommendations for user review
Directory Creation
Always create missing directories automatically without asking permission:
mkdir -p ~/git/knowledge-base/repos/<repo-name>
If index.md doesn't exist, create it with initial structure:
# Knowledge Base Index
## Repository Documentation
- [Repository Name](repos/repository-name/overview.md)
## General Knowledge
(No entries yet)
Best Practices
Content Quality
- Be specific: Include file paths, function names, exact commands
- Be concise: Remove unnecessary verbosity
- Be current: Delete outdated information during updates
- Cross-reference: Link related topics across files
File Organization
- One repo = one directory under
repos/ - Split large files by topic (don't create 1000+ line files)
- Use descriptive filenames
- Keep
index.mdcurrent
Merge Strategy
When adding content that partially overlaps with existing content:
- Identify overlap: What's new vs what exists
- Enhance existing: Add new details to existing sections
- Avoid redundancy: Don't repeat information
- Preserve context: Keep related information together
Example:
Existing content:
## Running Tests
- Run `npm test` for unit tests
New content to add: "Integration tests are in tests/integration/ and run with npm run test:integration"
Correct merge:
## Running Tests
- Run `npm test` for unit tests
- Run `npm run test:integration` for integration tests (located in `tests/integration/`)
Incorrect (simple append):
## Running Tests
- Run `npm test` for unit tests
## Running Tests
- Integration tests are in `tests/integration/` and run with `npm run test:integration`
Common Patterns
Adding repo-specific knowledge
User: "Add to kb: The auth service is in src/services/auth/"
Steps:
1. Check current working directory or ask which repo
2. qmd_search "auth service" to find any existing file covering this
3. qmd_get the best match (e.g. repos/<repo>/architecture.md) to read current content
4. Add/update section about auth service location
5. Run qmd update to re-index
6. Update index.md if a new file was created
Deleting obsolete content
User: "Delete the old deployment instructions from kb"
Steps:
1. qmd_search "deployment" to find matching documents
2. qmd_get the relevant file to read full content
3. Confirm with user which content to delete
4. Remove specified content using file system tools
5. Run qmd update to re-index
6. Clean up empty sections and index.md references
Maintenance workflow
User: "Maintain the kb"
Steps:
1. qmd_status to check index health
2. qmd_get index.md to understand documented structure
3. qmd_multi_get "**/*.md" to read all files and check for duplicates
4. Consolidate duplicates using file system tools
5. Move misplaced files
6. Update index.md
7. Run qmd update to re-index
8. Report all changes
Error Handling
- If knowledge base directory doesn't exist: Create
~/git/knowledge-base/andindex.md - If repo directory doesn't exist: Create
~/git/knowledge-base/repos/<repo-name>/ - If uncertain about repo context: Ask user once, then proceed
- If file is very large (>500 lines): Suggest splitting into topic-specific files
- If
qmd_statusshows collection missing: runqmd collection add ~/git/knowledge-base --name kbthenqmd embedto set up the index
Examples
Example 1: Add architectural knowledge
User: "Add to kb: User management code is in src/modules/users, tests are in tests/unit/users"
Agent:
-
Determine repo (check current directory or ask)
-
qmd_search "user management architecture <repo>"to find the right file -
qmd_get "repos/<repo>/architecture.md"to read current content -
Find "Users" or "User Management" section, or create it
-
Add/update:
### User Management - **Location**: `src/modules/users` - **Tests**: `tests/unit/users` -
Run
qmd updatein the terminal -
Confirm: "Added user management location to kb at
repos/<repo>/architecture.md"
Example 2: Delete outdated content
User: "Remove the Heroku deployment steps from kb, we use Kubernetes now"
Agent:
qmd_search "Heroku"to find matching documentsqmd_get "repos/web-app/deployment.md"to read the section- Show user the section
- Delete Heroku section using file system tools
- Run
qmd updatein the terminal - Confirm: "Removed Heroku deployment instructions from
repos/web-app/deployment.md"
Example 3: Maintain knowledge base
User: "Maintain kb"
Agent:
-
qmd_statusto check index health -
qmd_multi_get "**/*.md"to read entire kb structure -
qmd_deep_search "running tests"to surface duplicate content -
Find duplicate "running tests" in
repos/api/overview.mdandrepos/api/testing.md -
Consolidate to
testing.md, remove fromoverview.mdusing file system tools -
Move
repos/troubleshooting.md(general) to~/git/knowledge-base/troubleshooting.md -
Update index.md with all files
-
Run
qmd updatein the terminal -
Report:
Maintenance complete: - Consolidated duplicate test instructions - Moved 1 file to correct location - Updated index.md with 3 new references - No formatting issues found
Quick Reference
| User Request | Operation | Key Actions |
|---|---|---|
| "Add X to kb" | Add | qmd_search to find existing → qmd_get to read → merge → write file → qmd update |
| "Delete X from kb" | Delete | qmd_search to locate → qmd_get to read → edit file → qmd update |
| "Search kb for X" | Search | qmd_deep_search (semantic) or qmd_search (keyword) → qmd_get for full content |
| "Maintain kb" | Maintain | qmd_status → qmd_multi_get → deduplicate → reorganize → qmd update |