Key Concepts
| Concept | Description |
|---|---|
| RAG | Retrieval Augmented Generation for accurate answers |
| Hybrid Search | Combines semantic and keyword search for comprehensive results |
| Source Citations | Every answer references source documents |
| Uncertainty Handling | Acknowledges when information is not in the knowledge base |
Prerequisites
- Python 3.12+
- Docker (for PostgreSQL with pgvector)
- OpenAI API key
Setup
1
Clone the repository
2
Create and activate virtual environment
3
Install dependencies
4
Set environment variables
5
Start PostgreSQL with pgvector
6
Load sample knowledge base
Run the Agent
Basic Query
Ask a question from the knowledge base:- Searching the knowledge base
- Answer synthesis with citations
- Confidence levels
Multi-Turn Conversation
Have a follow-up conversation:- Conversation memory
- Context-aware follow-ups
- Building on previous answers
Edge Cases
Handle uncertainty and ambiguity:Agent Configuration
| Parameter | Purpose |
|---|---|
model | GPT-5.2 for question answering |
knowledge | PgVector database with hybrid search |
search_knowledge | Auto-search knowledge base before answering |
read_chat_history | Access conversation history |
num_history_runs | Include 5 previous turns for context |
ReasoningTools | Plan search and synthesis approach |
How It Works
RAG Workflow
Hybrid Search
The knowledge base uses hybrid search combining:| Search Type | Description |
|---|---|
| Semantic | Vector similarity for conceptual matches |
| Keyword | BM25 for exact term matches |
| Combined | Best of both for comprehensive results |
Knowledge Base Configuration
Handling Uncertainty
| Scenario | Behavior |
|---|---|
| Not in docs | States “I don’t have information about X” |
| Ambiguous | Asks for clarification or lists options |
| Partial match | Provides what’s known, notes limitations |
| Conflicting sources | Notes discrepancy, cites both sources |
Sample Documents
The knowledge base includes sample company documents:| Document | Content | Use Case |
|---|---|---|
employee_handbook.md | PTO, benefits, policies | Policy questions |
engineering_wiki.md | Setup, coding standards | Technical questions |
onboarding_checklist.md | First week tasks | New hire questions |
product_guide.md | Platform features, API | Product questions |
Troubleshooting
Database connection refused
Database connection refused
Ensure PostgreSQL is running:
No results for query
No results for query
Ensure the knowledge base is loaded:
Low quality answers
Low quality answers
The agent relies on the knowledge base content. Add more relevant documents or improve existing document quality.