How quanglekim021223/graphrag works
Project Type & Purpose
• This is a full-stack healthcare chatbot system that leverages a Neo4j knowledge graph and integrates large language models (via Azure OpenAI) with Retrieval-Augmented Generation (RAG).
• It supports multiple interfaces (web via Streamlit, REST API via FastAPI, and a command-line interface) and is built around a layered architecture which separates UI, business logic, and data access.
Analyzing the File Structure
• Top-Level Directories and Files:
• Main entry point (main.py)
• Configuration files (.env.example, Dockerfile, docker-compose.yml)
• Assets with images used for documentation/UI.
• A dedicated Neo4j configuration folder (neo4j/) and data dump folder (data/healthcare.csv and backup with neo4j.dump).
• The primary source code is under the src/ directory which is further organized into:
∙ config: holding settings for the application.
∙ handlers: responsible for the core business logic like conversation handling, graph management, LLM integration, and memory management.
∙ helpers: utility and initialization functions for agents and LLMs.
∙ routers: different interfaces exposing the application’s functionality (API, CLI, UI).
Architectural Layers
• User Interface (Presentation) Layer:
• Three distinct front-ends:
▸ Streamlit-based web UI.
▸ FastAPI-powered REST API.
▸ Command-Line Interface (CLI).
• Business Logic (Service) Layer:
• Components from the src/handlers folder:
▸ Conversation Handler (manages chat and interaction history).
▸ Graph Manager (handles interactions with the Neo4j graph database).
▸ GraphRAG Handler (implements the retrieval-augmented generation logic).
▸ LLM Manager and Memory Manager (ensure context storage and LLM decisions via the ReAct Agent).
▸ Additionally, the helpers that initialize agents and LLM components should be marked as supporting functionalities.
• Data & External Services Layer:
• Neo4j Graph Database (core knowledge graph storing healthcare data and conversation histories).
• Azure OpenAI (for LLM queries and generating responses).
• LangChain and LangGraph integration frameworks (which might be used inside the business logic layer to coordinate between the knowledge graph and LLM).
Relationships & Interactions
• How each UI component (Streamlit, FastAPI, CLI) sends user queries to the business logic layer.
• The business logic module (e.g., the GraphRAG handler) consulting the Neo4j graph for retrieval and then invoking Azure OpenAI for generating responses.
• Memory Manager updating and retrieving conversation context from an internal or persistent store.
• Integration flows where configuration (from settings.py) governs communication parameters (Neo4j connection, API keys, etc.).
Key Technological Components
• Python (the programming language).
• Docker & Docker Compose (for container orchestration).
• Neo4j as the graph database.
• Azure OpenAI as the external LLM service.
• Frameworks: FastAPI for the API, Streamlit for web UI, and support for CLI operations.
• Supporting libraries like LangChain and LangGraph that abstract complex functionality for RAG.