Using Retrieval-Augmented Generation (RAG)
Enhance your agents with knowledge from external sources using RAG. This allows your agents to answer questions and complete tasks based on your own documents and data.
Overview
Section titled “Overview”RAG (Retrieval-Augmented Generation) allows your agents to access and reference specific information from your documents, databases, and knowledge sources. When a user asks a question, the agent can search through your uploaded content to provide accurate, contextual responses based on your actual data.
Prerequisites
Section titled “Prerequisites”Before using RAG, ensure you have:
- Database and OpenAI API configured - RAG requires a database for storing embeddings and an OpenAI API key for generating embeddings
- Agent with searchKnowledgeBase tool enabled - This is the critical step most users miss
Enable the searchKnowledgeBase Tool
Section titled “Enable the searchKnowledgeBase Tool”IMPORTANT: You must enable the searchKnowledgeBase tool for your agent to access the knowledge base.
Via Admin UI (Recommended)
Section titled “Via Admin UI (Recommended)”- Navigate to the Admin Console → Agents
- Select or create your agent
- Go to the Tools section
- Enable the
searchKnowledgeBasetool - Configure RAG sources in the Knowledge Base section
- Save your changes
Via Configuration File
Section titled “Via Configuration File”Alternatively, manually edit your agent’s config.json:
Without enabling this tool, your agent cannot access the knowledge base, even if RAG sources are configured.
Setting Up Knowledge Sources
Section titled “Setting Up Knowledge Sources”Creating Resource Groups
Section titled “Creating Resource Groups”Resource groups are collections of related documents that you can selectively enable for different agents:
- Navigate to the Admin Console → Knowledge Base
- Click “Create Resource Group”
- Fill in the details:
- Name:
company-policies - Description:
Employee handbook and company policies
- Name:
- Save the resource group
Uploading Documents
Section titled “Uploading Documents”Upload documents to your resource groups through the Admin Console:
- Go to your Resource Group
- Click “Upload Documents”
- Select your files (drag & drop or file picker)
- Wait for processing to complete
Supported file types:
- PDF documents (.pdf)
- Text files (.txt)
- Markdown files (.md, .mdx)
- Word documents (.docx)
- CSV files (.csv)
- JSON files (.json)
Processing Pipeline
Section titled “Processing Pipeline”When you upload documents:
- Text Extraction: Content is extracted from files
- Chunking: Documents are split into manageable chunks
- Embedding Generation: Each chunk is converted to vector embeddings using OpenAI’s
text-embedding-3-small - Storage: Embeddings and metadata are stored in your database
- Indexing: Content becomes searchable by your agents
Configuring Agents for RAG
Section titled “Configuring Agents for RAG”Option 1: Enable All Knowledge Sources
Section titled “Option 1: Enable All Knowledge Sources”Allow your agent to access all available knowledge:
Option 2: Selective Knowledge Access
Section titled “Option 2: Selective Knowledge Access”Limit your agent to specific resource groups:
Real-World Examples
Section titled “Real-World Examples”HR Assistant with Company Policies
Section titled “HR Assistant with Company Policies”Technical Support Agent
Section titled “Technical Support Agent”How RAG Search Works
Section titled “How RAG Search Works”Automatic Search Behavior
Section titled “Automatic Search Behavior”The searchKnowledgeBase tool is designed to be used automatically by your agent when:
- Users ask questions that might reference specific information
- The agent needs context to provide accurate answers
- Users mention documents, policies, or specific topics
- The agent is unsure about factual information
Search Process
Section titled “Search Process”- Query Analysis: User’s question is analyzed and reformulated as a search query
- Embedding Generation: Query is converted to a vector embedding
- Similarity Search: System finds the most relevant content chunks using cosine similarity
- Relevance Filtering: Only content with similarity > 0.5 is returned
- Agent Integration: Retrieved content is provided to the agent for response generation
Search Results
Section titled “Search Results”Each search returns up to 4 most relevant content chunks with:
Best Practices
Section titled “Best Practices”1. Document Organization
Section titled “1. Document Organization”Structure your knowledge base logically:
2. Agent Prompt Engineering
Section titled “2. Agent Prompt Engineering”Include RAG usage instructions in your agent prompts:
3. Content Quality
Section titled “3. Content Quality”Ensure high-quality source material:
- Clear Structure: Use headings, bullet points, and clear formatting
- Current Information: Keep documents up-to-date
- Comprehensive Coverage: Include all relevant topics
- Consistent Terminology: Use consistent language across documents
4. Testing RAG Performance
Section titled “4. Testing RAG Performance”Test your knowledge base regularly:
- Ask specific questions about content you know exists
- Test edge cases and ambiguous queries
- Verify accuracy of retrieved information
- Check source attribution in agent responses
5. Monitoring and Optimization
Section titled “5. Monitoring and Optimization”Monitor RAG performance:
- Search Success Rate: How often relevant content is found
- Response Accuracy: Quality of agent answers
- User Satisfaction: Feedback on knowledge-based responses
- Content Gaps: Topics where no relevant content is found
Troubleshooting
Section titled “Troubleshooting”Agent Not Using Knowledge Base
Section titled “Agent Not Using Knowledge Base”Check these common issues:
- Tool Not Enabled: Ensure
searchKnowledgeBaseis intoolsEnabledarray - No RAG Access: Verify
ragAllEnabled: trueor specific sources inragEnabled - Empty Knowledge Base: Confirm documents are uploaded and processed
- Permissions: Check agent has access to the resource groups
Poor Search Results
Section titled “Poor Search Results”Improve search quality:
- Content Quality: Ensure documents are well-structured and readable
- Query Refinement: Test different ways of asking questions
- Chunk Size: Consider document chunking strategy
- Similarity Threshold: Adjust if needed (default is 0.5)
Performance Issues
Section titled “Performance Issues”Optimize for speed:
- Selective Access: Use specific
ragEnabledinstead ofragAllEnabled - Content Volume: Monitor total content size
- Database Performance: Ensure proper indexing
- Embedding Cache: Embeddings are cached for efficiency
Advanced Configuration
Section titled “Advanced Configuration”Custom Search Behavior
Section titled “Custom Search Behavior”For advanced use cases, you can extend the search functionality by modifying the searchKnowledgeBase tool or creating custom tools that integrate with the embedding system.
Integration with External Systems
Section titled “Integration with External Systems”RAG can be combined with external APIs and services to provide comprehensive information access:
Multi-Language Support
Section titled “Multi-Language Support”The embedding system supports multiple languages. Upload documents in different languages and the search will work across language boundaries to some extent.
Summary
Section titled “Summary”RAG transforms your agents from general AI assistants into knowledgeable experts on your specific domain. By properly configuring the searchKnowledgeBase tool and organizing your knowledge sources, you can create agents that provide accurate, contextual responses based on your actual data and documentation.
Remember: Always enable the searchKnowledgeBase tool in your agent configuration - this is the key that unlocks your knowledge base for your agents.