This repository showcases the implementation of three Retrieval-Augmented Generation (RAG) models using LangGraph: Corrective-RAG, Self-RAG, and Adaptive-RAG. These models combine the strengths of both retrieval-based and generative models, making them highly effective for tasks that require generating responses grounded in external knowledge sources.
- LangGraph Integration: Utilizes LangGraph to structure the pipeline and logic for the RAG models.
- Retrieval Module: Incorporates a document retriever to find relevant information from a dataset.
- Generative Module: Uses a generative model (e.g., GPT-3.5-turbo) to create coherent, contextually accurate responses.
- Corrective Mechanism: Implements a corrective mechanism to refine and improve the generated responses based on retrieved documents.
- Flexible and Scalable: Designed for scalability and customization according to different use cases and datasets.
This is the structure of the graph model used in the Corrective-RAG implementation:
This is the structure of the graph model used in the Self-RAG implementation:
This is the structure of the graph model used in the Adaptive-RAG implementation:
You can view the demo of the models on LangSmith using the following link:
-
Document Ingestion:
- Load and preprocess documents from specified URLs.
- Split documents into manageable chunks and create embeddings.
python ingestion.py
-
Graph Workflow:
- Define and compile the graph workflow for the RAG models.
python graph/graph.py
-
Web Search:
- Perform web searches to retrieve additional information.
python graph/nodes/web_search.py
-
Testing:
- Run tests to ensure the correctness of the retrieval and generation chains.
pytest graph/chains/tests/test_chains.py
This project is licensed under the MIT License. See the LICENSE
file for more details.
- LangGraph for providing the graph-based framework.
- LangChain for the document retrieval and generation modules.
- TavilySearchResults for the web search integration.