Context Collections Management
Guide to organizing, managing, and switching between context collections in Terraphim for optimal AI-assisted development.
What are Context Collections?
Context collections are named sets of documents, vibe-rules, and configuration organized for specific development contexts. Think of them as workspaces or profiles that include:
- Documents: Reference materials, architecture docs, API documentation
- Vibe-Rules: Coding standards, patterns, and best practices
- Configuration: LLM settings, haystack configurations, relevance functions
- Knowledge Graph: Pre-built semantic relationships between concepts
Collections enable quick context switching without losing accumulated knowledge.
Collection Types
1. Domain Collections
Organized by technical domain or area of expertise.
Examples:
web-backend: API design, database patterns, authenticationcli-tools: Argument parsing, POSIX conventions, error messageswasm: Memory management, JS interop, size optimizationembedded: Hardware constraints, real-time, power managementdata-science: Algorithm notebooks, ML patterns, visualization
2. Project Collections
Project-specific knowledge and conventions.
Examples:
project-alpha: Alpha project architecture, API contracts, team conventionsclient-beta: Client-specific patterns, business rules, integration docsinternal-tools: Company-wide standards, authentication patterns, logging
3. Language Collections
Language-specific patterns and idioms.
Examples:
rust-advanced: Async patterns, unsafe code, FFI, macrospython-data: NumPy patterns, Pandas idioms, ML pipelinestypescript-react: Component patterns, hooks, state management
4. Learning Collections
Educational materials and tutorials.
Examples:
rust-beginner: Ownership basics, borrowing, lifetimestokio-tutorial: Async fundamentals, runtime, channelskubernetes-ops: Deployment patterns, monitoring, debugging
Directory Structure
docs/
├── context-collections/
│ ├── web-backend/
│ │ ├── collection.json # Collection metadata
│ │ ├── architecture/
│ │ │ ├── api-design.md
│ │ │ ├── auth-patterns.md
│ │ │ └── database-access.md
│ │ ├── vibe-rules/
│ │ │ ├── rest-api-conventions.md
│ │ │ ├── error-responses.md
│ │ │ └── rate-limiting.md
│ │ └── references/
│ │ ├── http-status-codes.md
│ │ └── jwt-claims.md
│ │
│ ├── cli-tools/
│ │ ├── collection.json
│ │ ├── patterns/
│ │ │ ├── argument-parsing.md
│ │ │ ├── subcommands.md
│ │ │ └── configuration.md
│ │ └── vibe-rules/
│ │ ├── error-messages.md
│ │ ├── output-formatting.md
│ │ └── exit-codes.md
│ │
│ └── wasm/
│ ├── collection.json
│ ├── architecture/
│ │ ├── memory-management.md
│ │ └── js-interop.md
│ └── vibe-rules/
│ ├── wasm-bindgen-patterns.md
│ └── performance-tips.mdCollection Metadata
Each collection has a collection.json file:
Creating Collections
Method 1: Directory-Based (Simple)
# Create collection directory
# Add documents
# Create collection metadata
Method 2: Symlink-Based (Reuse Existing)
# Create collection directory
# Symlink existing vibe-rules
# Create collection metadata
Method 3: CLI Tool (Planned)
# Create collection from template
# Add documents
# Import vibe-rules
Switching Collections
Using Role Configuration
Create a role per collection:
Switch between collections by changing the selected role:
# Via API
# Via TUI
# Via desktop UI
# Settings → Roles → Select "Web Backend Engineer"Dynamic Collection Loading
Load collections on-demand without restarting:
// Via Terraphim service API
let service = new;
// Load new collection
service.load_collection.await?;
// Switch active collection
service.activate_collection.await?;
// Knowledge graph rebuilds automaticallyCollection Management
Listing Collections
# List available collections
# Get collection metadata
|
# Via API
Exporting Collections
Export collection as shareable archive:
# Create collection archive
# Include dependencies
# Share with team
Importing Collections
Import collection from archive:
# Extract collection
# Verify collection
# Rebuild knowledge graph
Versioning Collections
Use git to version collections:
# Tag collection version
# View collection history
# Rollback to previous version
# Create branch for experimental changes
Collection Composition
Hierarchical Collections
Collections can inherit from parent collections:
Resolution order:
- Project-specific collection
- Parent collection (web-backend)
- Global vibe-rules
- Language-specific vibe-rules
Collection Mixing
Combine multiple collections:
Collection Overlays
Temporary modifications without changing base collection:
Token Management
Estimating Collection Size
# Count tokens in collection
|
# Estimate with metadata
Optimizing Collection Size
Strategies:
- Selective Loading: Only load relevant subcollections
- Document Pruning: Remove obsolete or rarely-used docs
- Snippet Extraction: Store only relevant snippets, not full docs
- Lazy Loading: Load documents on-demand, not upfront
Example:
Token Budget Per Context
Configure per-collection token budgets:
Best Practices
1. Keep Collections Focused
Good:
web-backend/
├── api-design.md
├── auth-patterns.md
└── database-access.mdBad:
web-backend/
├── api-design.md
├── mobile-ui-patterns.md # Wrong domain
├── ml-algorithms.md # Wrong domain
└── database-access.md2. Use Consistent Structure
All collections should follow same structure:
collection-name/
├── collection.json
├── architecture/
├── patterns/
├── vibe-rules/
└── references/3. Document Dependencies
4. Tag Aggressively
More tags = better search and discovery.
5. Include Examples
Every pattern should have working examples:
6. Version Control Everything
# Track all changes
# Tag stable versions
7. Measure Usage
Track which collections are most useful:
# Search frequency per collection
# Most referenced documents
Integration with Development Tools
VS Code
Create collection-specific workspaces:
// .vscode/web-backend.code-workspace
Claude Desktop
Collection-specific MCP configurations:
Git Hooks
Auto-rebuild knowledge graph on collection changes:
#!/bin/bash
# .git/hooks/post-commit
# Check if any collection changed
if | ; then
Troubleshooting
Collection Not Loading
# Verify collection exists
# Check collection.json is valid
|
# Verify role configuration
| Search Returns Wrong Results
# Check active collection
|
# Verify haystack configuration
|
# Rebuild knowledge graph
Token Budget Exceeded
# Check collection size
# Reduce collection:
# 1. Remove rarely-used documents
# 2. Enable lazy loading
# 3. Use document summaries instead of full textFuture Enhancements
Planned features:
- Collection Marketplace: Share collections with community
- Auto-Generated Collections: ML-based collection creation from codebases
- Collection Analytics: Track which documents help most
- Smart Merging: Automatically merge overlapping collections
- Collection Testing: Verify collection quality with test queries
- Cloud Sync: Sync collections across devices
Examples
Web Backend Collection
See: docs/context-collections/web-backend/
Includes:
- REST API design patterns
- Authentication/authorization
- Database access patterns
- Error handling conventions
- Rate limiting strategies
CLI Tools Collection
See: docs/context-collections/cli-tools/
Includes:
- Argument parsing patterns
- Subcommand structure
- Error message formatting
- Configuration file handling
- POSIX conventions
WASM Collection
See: docs/context-collections/wasm/
Includes:
- Memory management patterns
- JS interop with wasm-bindgen
- Performance optimization
- Size optimization
- Error handling across boundaries
See Also
- Conare Comparison - Context engineering comparison
- Vibe Rules - Coding rules and patterns
- Context Library - Reference documentation
- MCP File Context - File-based context tools