How nirdiamant/controllable-rag-agent works
Main Components
• Data Ingestion & Preprocessing Module:
• PDF Loader/Processor: This component loads PDF documents, splits them into chapters, and pre-processes the text.
• Text Preprocessing and Cleaning: Functions that clean and process the raw text.
• Summarization Pipeline: Uses large language models to generate chapter summaries.
• Vector Store Creation & Management:
• “Book Quotes” Vector Store: Stored in book_quotes_vectorstore (using FAISS and a pickle index).
• “Chapter Summaries” Vector Store: Stored in chapter_summaries_vector_store.
• “Chunks” Vector Store: Stored in chunks_vector_store.
• These containers are the backend for fast retrieval and are represented by FAISS-based indices.
• Question Processing & Reasoning Engine:
• Question Anonymization: Prepares the question by replacing named entities.
• High-Level Planning Module: Generates a plan to answer the anonymized query.
• Task Execution Modules: Decide whether to retrieve or generate responses based on context. This includes retrieving relevant information from the vector stores.
• Chain-of-Thought Reasoning Component: Uses an LLM (integrated via LangChain) to synthesize the final answer using incremental reasoning.
• Re-planning and Verification: Verifies content to avoid hallucinations and refines the plan when needed.
• Visualization & User Interaction:
• Notebooks (full_graph_visualization.ipynb and sophisticated_rag_agent_harry_potter.ipynb): Used for step-by-step walkthroughs and demonstrations.
• Supporting Components and Tools:
• Helper Functions & Pipeline Logic: Contained in files like functions_for_pipeline.py and helper_functions.py.
• Evaluation Metrics Module: Integrates Ragas metrics (answer correctness, faithfulness, relevancy, etc.) for performance assessment.
• Docker & Environment Management: Dockerfile, docker-compose.yml, and environment variable settings indicate containerization and deployment practices.
Relationships and Interactions
• Data flows from the ingestion pipeline into the vector store creation modules.
• The reasoning engine interacts with the vector stores to retrieve context based on a processed and anonymized user question.
• The output from the reasoning module passes to the verification stage before the final answer is generated.
• There is an iterative feedback loop between task execution, retrieval, and re-planning processes.
• For visualization, processed data and final outputs are passed to the Streamlit UI for real-time display.
• Docker and environmental configurations manage and encapsulate the complete system for both development and production.
Architectural Patterns & Technologies
• The design leverages modular separation of concerns (ingestion, processing, retrieval, reasoning, visualization).
• Utilizes a deterministic graph structure for multi-step reasoning.
• Multiple vector stores (implemented via FAISS) are used as the backbone for retrieval.
• Incorporates third-party libraries and APIs (LangChain for LLM interactions, Streamlit for UI, and Ragas for metrics).
• Dockerization ensures portability and easy deployment.