How tmullayanov/simple-rag works
Main Components
• API Server: Represented by FastAPI and the endpoints defined within simple_rag/web/routes. This includes endpoints like chat creation, message sending, model updates, and possibly summarization.
• Chat Management: The module in simple_rag/chats provides the chat logic and maintains user sessions.
• RAG Model (QnA): The core logic for processing questions and retrieving answers is implemented in the simple_rag/models/qna_rag directory. This includes:
• Parser (assets and CSV parsing with csv_parser.py).
• Engine and memory management.
• Query handling and state management.
• LLM Integration: The simple_rag/llm directory (particularly groq.py) handles interactions with the Groq language model.
• Summarizer: An alternate or additional model for summarization housed in simple_rag/models/summarizer.
• Configuration & Logging: Global settings and configurations (e.g., environment variables, logging via simple_rag/logger.py and web/config.py) that tie the system pieces together.
• Demo and Testing: Demo HTML files and various Jupyter notebooks (rag_1.ipynb, rag_2_advanced.ipynb, rag_qna.ipynb) demonstrate the RAG approach, while the tests directory validates system components.
Out Relationships and Data Flow
• External User Interaction: External requests (via curl or a browser) enter the system through the FastAPI endpoints.
• API Layer: Once a request is received, the FastAPI controllers (in simple_rag/web/routes) route the calls to business logic components.
• Chat Manager: A request for creating or updating a chat is handled in simple_rag/chats, which instantiates sessions and maintains per-chat model instances.
• Model Invocation and Processing:
– For QnA tasks, the engine in simple_rag/models/qna_rag processes the CSV data (using csv_parser) to build an in-memory vector for retrieving answers.
– For generating responses, the system calls functions within simple_rag/llm (via groq.py) that interact with the Groq model.
– Summarizer components (if used) in simple_rag/models/summarizer apply additional processing.
• Return of Results: Processed responses and status (e.g., chat creation success, answer retrieval) are then returned to the user.
Architectural Patterns and Design Principles
• Separation of Concerns: The project is split into distinct modules (web, chats, models, llm) that cleanly separate API handling, business logic, model processing, and integrations.
• Modularity: Each folder (e.g., models, chats, web) can be visualized as individual components with clear input and output flows.
• Extensibility: There is a clear design path for adding new models or updating current ones (as shown in the update_model endpoint).
Technologies and Frameworks
• Python (3.8+): Core language.
• FastAPI: API framework powering the web endpoints.
• Groq: The language model integration.
• CSV Parsing for QnA: In-memory vector building from static files.
• uv: For managing environment and running the server.
• Testing frameworks (implied by tests/ folder): For ensuring quality and correctness.