-
Notifications
You must be signed in to change notification settings - Fork 196
Expand file tree
/
Copy pathquery_flow_diagram.txt
More file actions
154 lines (137 loc) · 9.26 KB
/
query_flow_diagram.txt
File metadata and controls
154 lines (137 loc) · 9.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
RAG SYSTEM QUERY FLOW DIAGRAM
================================
```
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ FRONTEND │ │ FASTAPI │ │ RAG SYSTEM │
│ (script.js) │ │ (app.py) │ │ (rag_system.py) │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
│ 1. POST /api/query │ │
│ {query, session_id} │ │
├──────────────────────▶│ │
│ │ 2. rag_system.query() │
│ ├──────────────────────▶│
│ │ │
│ │ ▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ SESSION MANAGER │ │ AI GENERATOR │ │ TOOL MANAGER │
│(session_mgr.py) │ │ (ai_generator.py)│ │(search_tools.py)│
└─────────────────┘ └──────────────────┘ └─────────────────┘
▲ ▲ │
│ 3. get_history() │ 4. generate_response() │
│ │ + tools │
└───────────────────────┼───────────────────────┘
│
▼
┌─────────────────────────────────────────────────────────────────┐
│ CLAUDE SONNET 4 │
│ System: "You are an AI assistant with course search tool..." │
│ Tools: [CourseSearchTool] │
│ Query: "Answer this question about course materials: ..." │
└─────────────────────────────────────────────────────────────────┘
│
│ 5. Tool Decision
▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ COURSE SEARCH │ │ VECTOR STORE │ │ CHROMADB │
│ TOOL │ │ (vector_store.py)│ │ │
│(search_tools.py)│ │ │ │ │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
│ 6. execute(query, │ │
│ course_name, │ │
│ lesson_number) │ │
├──────────────────────▶│ 7. search() │
│ ├──────────────────────▶│
│ │ │
│ │ │
│ │ ┌─────────────────────┤
│ │ │ course_catalog │
│ │ │ - Course resolution │
│ │ │ │
│ │ │ course_content │
│ │ │ - Semantic search │
│ │ └─────────────────────┤
│ │ │
│ │ 8. SearchResults │
│ 9. Formatted results │◀──────────────────────┤
│◀──────────────────────┤ │
│ │ │
│ 10. Tool results back to Claude
▼
┌─────────────────────────────────────────────────────────────────┐
│ CLAUDE SONNET 4 │
│ Synthesizes tool results into final answer │
└─────────────────────────────────────────────────────────────────┘
│
│ 11. Final response
▼
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ RAG SYSTEM │ │ FASTAPI │ │ FRONTEND │
│ │ │ │ │ │
└─────────────────┘ └──────────────────┘ └─────────────────┘
│ │ │
│ 12. (response, │ │
│ sources) │ │
├──────────────────────▶│ 13. QueryResponse │
│ │ {answer, sources, │
│ │ session_id} │
│ ├──────────────────────▶│
│ │ │
│ │ │ 14. Update UI
│ │ │ - Add message
│ │ │ - Show sources
│ │ │ - Store session
FLOW SUMMARY:
1. User query → FastAPI endpoint
2. RAG system gets conversation history
3. AI Generator calls Claude with tools
4. Claude decides to use CourseSearchTool
5. Tool searches ChromaDB collections
6. Results formatted and returned to Claude
7. Claude synthesizes final answer
8. Response flows back through layers
9. Frontend displays answer with sources
```
KEY ARCHITECTURE POINTS:
========================
**Dual ChromaDB Collections**:
- `course_catalog` for name resolution
- `course_content` for semantic search
**Tool-Based Search**:
- Claude decides when to search vs. use general knowledge
**Session Continuity**:
- Conversation history maintained across queries
**Error Handling**:
- Each layer handles failures gracefully
**Source Tracking**:
- Search results include course/lesson context for UI
DETAILED COMPONENT BREAKDOWN:
============================
Frontend (script.js):
- Handles user input and displays responses
- Manages session state and loading animations
- Renders sources and markdown content
FastAPI (app.py):
- Provides REST API endpoints
- Handles request/response serialization
- Manages CORS and static file serving
RAG System (rag_system.py):
- Main orchestrator coordinating all components
- Manages session creation and conversation history
- Routes queries through AI generator with tools
AI Generator (ai_generator.py):
- Interfaces with Claude Sonnet 4 API
- Handles tool calling workflow
- Manages conversation context and system prompts
Search Tools (search_tools.py):
- Implements CourseSearchTool for semantic search
- Formats search results with course/lesson context
- Tracks sources for UI display
Vector Store (vector_store.py):
- ChromaDB wrapper with dual collection strategy
- Provides course name resolution and content search
- Uses sentence-transformers for embeddings
Session Manager (session_manager.py):
- Maintains conversation history per session
- Provides context for follow-up questions