Lecture: 5, Advanced RAG and Intelligent Routing Duration: 30 minutes Difficulty: Intermediate
| Requirement | How to Check |
|---|---|
| HR policy documents | Read from lab_07_evaluation/data/policies/ |
| Dependencies | pip install openai chromadb sentence-transformers rich python-dotenv |
| LLM access | Ollama or DeepSeek API key |
# Create the employee database (auto-runs if missing)
cd lab_04_query_router
python setup_db.py
# Run the lab
python lab_04_query_router.py
| File | Description |
|---|---|
lab_04_query_router.py |
Main router script with TODO section |
setup_db.py |
Creates the SQLite employee database |
solutions.py |
Embedding-based classification solution |
data/employees.db |
50 Italian employee records |
Two sources are available:
Replace the keyword-based classify_query() with embedding-based classification.
Watch how the router handles SQL vs. policy questions. Notice error handling when SQL generation fails.
Try ambiguous questions like βCan a new employee work remotely?β β does it route correctly?
Q1: How many employees work in Engineering?
Route: sql
SQL: SELECT COUNT(*) FROM employees WHERE department = 'Engineering'
Answer: There are 12 employees in the Engineering department.
Q4: What is the remote work policy?
Route: vector
Answer: According to the Remote Work Policy, eligible employees may
work remotely up to 3 days per week...
| Issue | Solution |
|---|---|
| Policy docs not found | Check that lab_07_evaluation/data/policies/ is in your clone |
| SQL errors | The script auto-retries with error context |
| Wrong routing | Improve the classify_query() function β see solutions.py |