RAG Ollama is an Adaptive RAG Agent web app that uses LLM to answer questions about a PDF document. The app uses a graph-based approach to answer questions. The graph is built using LangGraph.
The RAG technique is used is called Adaptive RAG. Why is this called Adaptive?
- Routing: Route questions to different retrieval approaches
- Fallback: Fallback to web search if docs are not relevant to query
- Self-correction: Fix answers w/ hallucinations or don’t address question
This monorepo has a frontend and backend. The following are the technologies used in this project:-
- Python 3.10+
- Node.js 18+
- Ollama (with suitable LLM model installed, in my case I used llama3:8B)
- Tavily API Key (for web search)
- LangSmith API Key (optional, for tracing)
-
Clone the repository
-
Replace LangSmith API keys in
backend/main.py
-
Create a
.env
file inbackend
and add the following environment variables:TAVILY_API_KEY
-
cd backend
-
pip install -r requirements.txt
4.fastapi dev main,py
-
cd ../frontend
-
npm install
-
Create a clerk account, and create a clerk project.
-
Add the following keys to
.env
file infrontend
folder. -NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY
-CLERK_SECRET_KEY
-
NEXT_PUBLIC_CLERK_SIGN_IN_URL=/sign-in
-NEXT_PUBLIC_CLERK_SIGN_UP_URL=/sign-up
-
NEXT_PUBLIC_CLERK_AFTER_SIGN_IN_URL=/dashboard
-NEXT_PUBLIC_CLERK_AFTER_SIGN_UP_URL=/dashboard
-
npm run dev
-
Open http://localhost:3000 with your browser to see the result.
-
Create a account by clicking on sign-in button.
-
Upload PDF(s), type your question and click process button.
-
Depending on your specs, it may take a few minutes to process your question.