How farzad-r/advanced-qa-and-rag-series works
Project Type and Purpose
• Type: Full-stack conversational AI application (no browser-based frontend; uses a Python-based UI via Gradio).
• Purpose: End-to-end chatbot that can perform Q&A and RAG over unstructured documents and SQL tables, automatically selecting the appropriate tool.
File Structure (AgentGraph-Intelligent-Q&A-and-RAG-System)
• Top-level directories:
• notebooks/ – exploration, prototyping, teaching material
• configs/ – YAML config files (project_config.yml, tools_config.yml)
• data/ – sample databases (Chinook.db), unstructured docs for RAG
• memory/ – CSV files storing conversational memory
• src/
– agent_graph/ – core orchestration classes and tool definitions
– chatbot/ – backend logic for Gradio UI and session management
– prepare_vector_db.py – ingestion script to build vector DB from docs
– app.py – entry point that spins up the Gradio interface
– utils/ – shared utilities (UI settings, common helpers)
• Configuration & deployment artifacts: requirements.txt, .env template in env_example
README for Insights
• Core frameworks: OpenAI (or AzureOpenAI), LangChain, LangGraph, LangSmith (monitoring), Gradio
• Features: multi-tool agent, SQL agents for structured data, RAG on vector store, automatic tool selection, web search fallback
• Data flows: ingestion → vector store, DB queries via SQL agent, tool chain orchestration
Out Main Components
a. Frontend / UI
• Gradio application (src/app.py)
• Chat interface, memory display, tool selection controls
b. Application / Backend
• Chatbot backend (src/chatbot/chatbot_backend.py)
• Agent orchestrator (src/agent_graph/agent_backend.py) using LangGraph
• Tool modules (e.g., tool_chinook_sqlagent.py, tool_lookup_policy_rag.py, tool_stories_rag.py, tool_tavily_search.py)
• Config loader (src/agent_graph/load_tools_config.py, src/chatbot/load_config.py)
• Vector-DB preparation (src/prepare_vector_db.py)
c. Data Storage
• Vector store (ChromaDB) populated from unstructured_docs
• SQL database (Chinook.db, travel.db, etc.)
• Memory CSV logs
d. External Services
• OpenAI / AzureOpenAI API calls for LLM completions and embeddings
• Optional web-search API (as configured in tools_config.yml)
e. Monitoring & Logging
• LangSmith for agent performance tracking
• Local CSV/per-session logs
Relationships & Data Flows
• User → Gradio UI → Chatbot Backend
• Chatbot Backend → Agent Orchestrator → Config Loader + Memory Retriever
• Orchestrator → selects appropriate Tool(s):
• SQL Agent → interacts with SQL DB
• RAG Tool → queries VectorDB → embeddings via OpenAI → similarity search
• Web Search Tool → calls external search API
• Tools → return structured data (text, table, JSON) → Agent → composes LLM prompt → LLM API
• LLM Response → Agent → Chatbot Backend → UI
• Monitoring: each LLM call and agent step logged to LangSmith
Architectural Patterns
• Modular “Tool” plugin architecture (separation of tool definitions from orchestrator)
• Single entrypoint (app.py) adhering to “adapter” pattern bridging UI and agent core
• Config-driven behavior (YAML files define tools, databases, limits)
• Layered approach:
Presentation (Gradio UI)
Application (chatbot, orchestrator)
Domain (tools, data ingestion)
Infrastructure (databases, external APIs)
Checklist
[ ] Frontend (Gradio) clearly separated from backend
[ ] Config files feeding into orchestrator and ingestion
[ ] Monitoring component (LangSmith) linked to orchestrator
[ ] Offline ingestion path (prepare_vector_db) displayed as a side process