RAG Strategy
Retrieval-Augmented Generation strategy for memory search and context injection.
Plan for implementing Retrieval-Augmented Generation using Qdrant vector database.
Overview
RAG will enable QUOX to:
- Reference 7000+ n8n workflow templates
- Remember conversation history
- Access infrastructure documentation
- Learn from code patterns and solutions
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Query Flow │
│ │
│ User Query ─────────────────────────────────────────────┐ │
│ │ │ │
│ ▼ │ │
│ ┌─────────────┐ ┌─────────────┐ ┌───────────┐ │ │
│ │ Embed │────▶│ Qdrant │────▶│ Results │ │ │
│ │ Query │ │ Search │ │ (Top K) │ │ │
│ └─────────────┘ └─────────────┘ └───────────┘ │ │
│ │ │ │
│ ▼ │ │
│ ┌───────────┐ │ │
│ │ Claude │◀─┘ │
│ │ Context │ │
│ └───────────┘ │
└─────────────────────────────────────────────────────────────┘
Collections
1. n8n_workflows
Purpose: Index 7000+ workflow templates for reference and inspiration.
{
"collection": "n8n_workflows",
"vector_size": 1536,
"distance": "Cosine",
"schema": {
"name": "string",
"description": "string",
"nodes": "string[]",
"triggers": "string[]",
"category": "string",
"source_url": "string"
}
}
Data sources:
- n8n official templates
- Community workflows from inspiration repos
- Custom QUOX workflows
2. infrastructure_docs
Purpose: Store host configurations, runbooks, and operational knowledge.
{
"collection": "infrastructure_docs",
"vector_size": 1536,
"distance": "Cosine",
"schema": {
"hostname": "string",
"ip_address": "string",
"role": "string",
"services": "string[]",
"config": "string",
"runbook": "string"
}
}
Data sources:
- Host inventory (50+ hosts)
- Service configurations
- Operational runbooks
- Troubleshooting guides
3. conversations
Purpose: Long-term memory of user interactions and solutions.
{
"collection": "conversations",
"vector_size": 1536,
"distance": "Cosine",
"schema": {
"session_id": "string",
"timestamp": "datetime",
"user_query": "string",
"assistant_response": "string",
"actions_taken": "string[]",
"outcome": "string"
}
}
Use cases:
- "How did I fix this before?"
- "What was the solution for prometheus01 last time?"
- Learning from successful interactions
4. code_patterns
Purpose: Reusable code snippets and patterns.
{
"collection": "code_patterns",
"vector_size": 1536,
"distance": "Cosine",
"schema": {
"name": "string",
"language": "string",
"pattern_type": "string",
"code": "string",
"use_case": "string",
"dependencies": "string[]"
}
}
Examples:
- n8n Code node patterns
- SSH command templates
- API integration patterns
- Error handling snippets
Deployment
Qdrant Container
Add to /opt/n8n/docker-compose.yml:
qdrant:
image: qdrant/qdrant:latest
container_name: qdrant
restart: unless-stopped
ports:
- "6333:6333"
- "6334:6334"
volumes:
- /opt/qdrant/storage:/qdrant/storage
environment:
- QDRANT__SERVICE__GRPC_PORT=6334
n8n RAG Workflow
Create workflow for RAG queries:
Webhook (POST /webhook/rag-query)
│
▼
Code Node (Generate Embedding)
│
▼
HTTP Request (Qdrant Search)
│
▼
Code Node (Format Results)
│
▼
Respond to Webhook
Embedding Strategy
Model Selection
Recommended: OpenAI text-embedding-3-small
- Cost: $0.00002/1K tokens
- Dimensions: 1536
- Good balance of quality and cost
Alternative: OpenAI text-embedding-3-large
- Better quality, higher cost
- Dimensions: 3072
Chunking Strategy
| Content Type | Chunk Size | Overlap |
|---|---|---|
| Workflows | Full workflow | N/A |
| Documentation | 500 tokens | 50 tokens |
| Conversations | Full exchange | N/A |
| Code patterns | Full snippet | N/A |
Query Patterns
Workflow Search
// User: "How do I send a Slack message when a GitHub issue is created?"
const query = "github issue slack notification workflow";
const results = await qdrant.search("n8n_workflows", embed(query), { limit: 5 });
// Returns relevant workflow templates
Infrastructure Lookup
// User: "What services run on prometheus01?"
const query = "prometheus01 services configuration";
const results = await qdrant.search("infrastructure_docs", embed(query), { limit: 3 });
// Returns host documentation
Conversation History
// User: "How did I fix the docker networking issue?"
const query = "docker networking fix solution";
const results = await qdrant.search("conversations", embed(query), { limit: 5 });
// Returns past interactions with solutions
Implementation Phases
Phase 1: Deploy Qdrant
- Add Qdrant to docker-compose
- Verify connectivity
- Create collections
Phase 2: Seed Data
- Import n8n workflow templates
- Index infrastructure inventory
- Add existing runbooks
Phase 3: Query Integration
- Create RAG query workflow
- Integrate with quox-chat
- Add context injection
Phase 4: Continuous Learning
- Store conversations automatically
- Index successful solutions
- Periodic re-embedding for updates
Estimated Resources
Storage
- 7000 workflows × 10KB = ~70MB vectors
- 50 hosts × 5KB = ~250KB vectors
- Conversations: ~10MB/month
- Total: ~100MB initially, growing
API Costs (OpenAI Embeddings)
- Initial indexing: ~$5-10
- Queries: ~$0.01/day typical use
- Monthly: ~$1-5
Success Metrics
- Query response time < 500ms
- Relevance score > 0.7 for top results
- Context injection improves Claude responses
- Reduced repetitive questions
Next Steps
- Add Qdrant to docker-compose
- Create collections via API
- Build embedding workflow in n8n
- Import n8n workflow templates
- Index infrastructure inventory
- Integrate with quox-chat
- Test and iterate on relevance