The /knowledge command provides persistent knowledge base functionality for Amazon Q CLI, allowing you to store, search, and manage contextual information that persists across chat sessions.
Note: This is a beta feature that must be enabled before use.
Enable the Knowledge Feature
The knowledge feature is experimental and disabled by default. Enable it with:
q settings chat.enableKnowledge true
Once enabled, you can use /knowledge commands within your chat session:
/knowledge add myproject /path/to/project
/knowledge show
Display all entries in your knowledge base with detailed information including creation dates, item counts, and persistence status.
Add files or directories to your knowledge base. The system will recursively index all supported files in directories.
/knowledge add "project-docs" /path/to/documentation
/knowledge add "config-files" /path/to/config.json
Supported file types:
- Text files: .txt
- Markdown: .md, .markdown
- JSON: .json
- Code files: .rs, .py, .js, .jsx, .ts, .tsx, .java, .c, .cpp, .h, .hpp, .go, .rb, .php, .swift, .kt, .kts, .cs, .sh, .bash, .zsh, .html, .htm, .xml, .css, .scss, .sass, .less, .sql, .yaml, .yml, .toml
Important: Unsupported files are indexed without text content extraction.
Remove entries from your knowledge base. You can remove by name, path, or context ID.
/knowledge remove "project-docs" # Remove by name
/knowledge remove /path/to/old/project # Remove by path
Update an existing knowledge base entry with new content from the specified path.
/knowledge update /path/to/updated/project
Remove all entries from your knowledge base. This action requires confirmation and cannot be undone.
You'll be prompted to confirm:
⚠️ This will remove ALL knowledge base entries. Are you sure? (y/N):
View the status of background indexing operations, including progress and queue information.
Cancel background operations. You can cancel a specific operation by ID or all operations if no ID is provided.
/knowledge cancel abc12345 # Cancel specific operation
/knowledge cancel all # Cancel all operations
When you add content to the knowledge base:
- File Discovery: The system recursively scans directories for supported file types
- Content Extraction: Text content is extracted from each supported file
- Chunking: Large files are split into smaller, searchable chunks
- Background Processing: Indexing happens asynchronously in the background
- Semantic Embedding: Content is processed for semantic search capabilities
The knowledge base uses semantic search, which means:
- You can search using natural language queries
- Results are ranked by relevance, not just keyword matching
- Related concepts are found even if exact words don't match
- Persistent contexts: Survive across chat sessions and CLI restarts
- Context persistence is determined automatically based on usage patterns
Organizing Your Knowledge Base
- Use descriptive names when adding contexts: "api-documentation" instead of "docs"
- Group related files in directories before adding them
- Regularly review and update outdated contexts
- Use natural language queries: "how to handle authentication errors using the knowledge tool"
- Be specific about what you're looking for: "database connection configuration"
- Try different phrasings if initial searches don't return expected results
- Prompt Q to use the tool with prompts like "find database connection configuration using your knowledge bases" or "using your knowledge tools can you find how to replace your laptop"
- Add project directories rather than individual files when possible
- Use /knowledge status to monitor indexing progress for large directories
- Consider breaking very large projects into logical sub-directories
- .mdx files are not currently supported for content extraction
- Binary files are ignored during indexing
- Very large files may be chunked, potentially splitting related content.
- Large directories may take significant time to index
- Background operations are limited by concurrent processing limits
- Search performance may vary based on knowledge base size
- Currently there’s a hard limit of 5k files per knowledge base (getting removed soon as on Jul 12th, 2025).
- No explicit storage size limits, but practical limits apply
- No automatic cleanup of old or unused contexts
- Clear operations are irreversible with no backup functionality
If your files aren't appearing in search results:
- Check file types: Ensure your files have supported extensions
- Monitor status: Use /knowledge status to check if indexing is still in progress
- Verify paths: Ensure the paths you added actually exist and are accessible
- Check for errors: Look for error messages in the CLI output
If searches aren't returning expected results:
- Wait for indexing: Use /knowledge status to ensure indexing is complete
- Try different queries: Use various phrasings and keywords
- Verify content: Use /knowledge show to confirm your content was added
- Check file types: Unsupported file types won't have searchable content
If operations are slow:
- Check queue status: Use /knowledge status to see operation queue
- Cancel if needed: Use /knowledge cancel to stop problematic operations
- Add smaller chunks: Consider adding subdirectories instead of entire large projects