feat: updated corrective RAG README

This commit is contained in:
ShubhamSaboo 2024-12-29 17:23:48 -06:00
parent f9fc5ba783
commit 4131e311f5
3 changed files with 14 additions and 59 deletions

View file

@ -1,9 +1,5 @@
# Corrective RAG Demo
This project demonstrates Corrective RAG (Retrieval Augmented Generation), an advanced approach to RAG that incorporates self-reflection / self-grading on retrieved documents - document relevance checking, query transformation, and web search fallback mechanisms to improve the quality of responses by far. Complete explanation of CRAG down below.
## Demo
# 🔄 Corrective RAG Agent
A sophisticated Retrieval-Augmented Generation (RAG) system that implements a corrective multi-stage workflow using LangGraph. This system combines document retrieval, relevance grading, query transformation, and web search to provide comprehensive and accurate responses.
## Features
@ -29,10 +25,16 @@ This project demonstrates Corrective RAG (Retrieval Augmented Generation), an ad
3. **Set Up API Keys**:
You'll need to obtain the following API keys:
- OpenAI API key (for embeddings)
- Anthropic API key (for Claude 3.5 sonnet as llm)
- Tavily API key (for web search)
- Qdrant API key and URL
- [OpenAI API key](https://platform.openai.com/api-keys) (for embeddings)
- [Anthropic API key](https://console.anthropic.com/settings/keys) (for Claude 3.5 sonnet as LLM)
- [Tavily API key](https://app.tavily.com/home) (for web search)
- Qdrant Cloud Setup
1. Visit [Qdrant Cloud](https://cloud.qdrant.io/)
2. Create an account or sign in
3. Create a new cluster
4. Get your credentials:
- Qdrant API Key: Found in API Keys section
- Qdrant URL: Your cluster URL (format: `https://xxx-xxx.aws.cloud.qdrant.io`)
4. **Run the Application**:
```bash
@ -45,7 +47,7 @@ This project demonstrates Corrective RAG (Retrieval Augmented Generation), an ad
- View the step-by-step Corrective RAG process
- Get comprehensive answers
## Technologies Used
## Tech Stack
- **LangChain**: For RAG orchestration and chains
- **LangGraph**: For workflow management
@ -54,44 +56,3 @@ This project demonstrates Corrective RAG (Retrieval Augmented Generation), an ad
- **OpenAI**: For document embeddings
- **Tavily**: For web search capabilities
- **Streamlit**: For the user interface
## CRAG Step by Step Explanation
1. Initial Retrieval
A user query is presented to the system.  
The system uses an existing retriever model to gather relevant documents from a knowledge base. This retriever could be any existing model.  
2. Evaluation of Retrieved Documents
A lightweight retrieval evaluator is used to assess the relevance of each retrieved document to the user query.  
The evaluator assigns a confidence score to each document, indicating how confident it is in the relevance of the document to the query.
 
3. Action Trigger
Based on the confidence scores, the system categorizes the retrieved documents and decides on the necessary action for each document.  
Correct: If the confidence score of a retrieved document is above a certain threshold, the document is marked as "Correct".  
Incorrect: If the confidence score of a retrieved document is below a certain threshold, the document is marked as "Incorrect".  
Ambiguous: If the confidence score falls between the thresholds for "Correct" and "Incorrect", the document is marked as "Ambiguous".  
4. Handling of Retrieved Documents
Correct Documents: These documents undergo a knowledge refinement process.  
Decomposition: The document is segmented into smaller knowledge strips, typically consisting of a few sentences each.  
Filtering: The retrieval evaluator is used again to assess the relevance of each knowledge strip. Irrelevant strips are discarded.  
Recomposition: The remaining relevant knowledge strips are recombined to form a refined representation of the essential knowledge from the document.  
Incorrect Documents: These documents are discarded, and the system resorts to web searches for additional information.  
Query Rewriting: The user query is rewritten into a form suitable for web searches, typically focusing on keywords.  
Web Search: The system uses a web search API to find web pages related to the rewritten query. Authoritative sources like Wikipedia are preferred.  
Knowledge Selection: The content of the web pages is transcribed, and the knowledge refinement process (decomposition, filtering, and recomposition) is applied to extract the most relevant information.  
Ambiguous Documents: The system combines the refined knowledge from the "Correct" documents and the external knowledge from the web searches to provide a comprehensive set of information for the generator.  
5. Generation of Response
The refined knowledge from the retrieved documents and/or web searches is presented to a generative language model.  
The language model generates a response to the user query based on this knowledge
<img width="1470" alt="Screenshot 2024-12-26 at 12 53 30PM" src="https://github.com/user-attachments/assets/b05fa33e-5c7e-4838-b112-e5b3e378e8b1" />

View file

@ -429,7 +429,7 @@ workflow.add_edge("generate", END)
app = workflow.compile()
st.title("Corrective RAG Demo")
st.title("🔄 Corrective RAG Agent")
st.text("A possible query: What are the experiment results and ablation studies in this research paper?")

View file

@ -2,12 +2,6 @@
A powerful document Q&A application that leverages Hybrid Search (RAG) and Claude's advanced language capabilities to provide comprehensive answers. Built with RAGLite for robust document processing and retrieval, and Streamlit for an intuitive chat interface, this system seamlessly combines document-specific knowledge with Claude's general intelligence to deliver accurate and contextual responses.
## Demo video:
https://github.com/user-attachments/assets/b576bf6e-4a48-4a43-9600-48bcc8f359a5
## Features
- **Hybrid Search Question Answering**