Skip to content

Commit 6231ab2

Browse files
authored
Merge pull request #482 from mayooear/feat/langgraph-rag-agent
docs: update readme with detailed instructions
2 parents 92b8bb6 + 8e83169 commit 6231ab2

File tree

1 file changed

+50
-27
lines changed

1 file changed

+50
-27
lines changed

README.md

Lines changed: 50 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# AI PDF Chatbot & Agent Powered by LangChain and LangGraph
22

3-
This monorepo is a customizable template example of an AI agent chatbot that ingests PDF documents, stores embeddings in a vector database (Supabase), and then answers user queries using OpenAI (or another LLM provider) utilising LangChain and LangGraph as orchestration frameworks.
3+
This monorepo is a customizable template example of an AI chatbot agent that "ingests" PDF documents, stores embeddings in a vector database (Supabase), and then answers user queries using OpenAI (or another LLM provider) utilising LangChain and LangGraph as orchestration frameworks.
44

55
This template is also an accompanying example to the book [Learning LangChain (O'Reilly)](https://tinyurl.com/learning-langchain): Building AI and LLM applications with LangChain and LangGraph.
66

@@ -40,6 +40,7 @@ This template is also an accompanying example to the book [Learning LangChain (O
4040

4141
## Architecture Overview
4242

43+
```ascii
4344
┌─────────────────────┐ 1. Upload PDFs ┌───────────────────────────┐
4445
│Frontend (Next.js) │ ────────────────────> │Backend (LangGraph) │
4546
│ - React UI w/ chat │ │ - Ingestion Graph │
@@ -53,6 +54,7 @@ This template is also an accompanying example to the book [Learning LangChain (O
5354
│ - Display sources │ <────────────────────┤ + Chat model (OpenAI) │
5455
└─────────────────────┘ 4. Streamed answers └───────────────────────────┘
5556
57+
```
5658
- **Supabase** is used as the vector store to store and retrieve relevant documents at query time.
5759
- **OpenAI** (or other LLM providers) is used for language modeling.
5860
- **LangGraph** orchestrates the "graph" steps for ingestion, routing, and generating responses.
@@ -87,8 +89,9 @@ The system consists of:
8789
```bash
8890
git clone https://github.com/mayooear/ai-pdf-chatbot-langchain.git
8991
cd ai-pdf-chatbot-langchain
92+
```
9093

91-
2. Install dependencies (from the monorepo root):
94+
2. Install dependencies (from the monorepo root):
9295

9396
yarn install
9497

@@ -153,34 +156,52 @@ This monorepo uses Turborepo to manage both backend and frontend projects. You c
153156

154157
1. Navigate to backend:
155158

156-
`cd backend`
159+
```bash
160+
cd backend
161+
```
157162

158-
2. Install dependencies (already done if you ran yarn install at the root).
159-
3. Start LangGraph in dev mode:
163+
2. Install dependencies (already done if you ran yarn install at the root).
160164

161-
`yarn langgraph:dev`
165+
3. Start LangGraph in dev mode:
166+
167+
```bash
168+
yarn langgraph:dev
169+
```
162170

163171
This will launch a local LangGraph server on port 2024 by default. It should redirect you to a UI for interacting with the LangGraph server. [Langgraph studio guide](https://langchain-ai.github.io/langgraph/concepts/langgraph_studio/)
164172

165173
### Running the Frontend
166174

167-
Open a new terminal window/tab:
175+
1. Navigate to frontend:
168176

169-
`cd frontend`
177+
```bash
178+
cd frontend
179+
```
170180

171-
`yarn dev`
181+
2. Start the Next.js development server:
182+
183+
```bash
184+
yarn dev
185+
```
172186

173187
This will start a local Next.js development server (by default on port 3000).
188+
174189
Access the UI in your browser at http://localhost:3000.
175190

176191
## Usage
177192

178193
Once both services are running:
179-
1. Use langgraph studio UI to interact with the LangGraph server and ensure the workflow is working as expected.
180-
2. Navigate to http://localhost:3000 to use the chatbot UI.
181-
3. Upload a small PDF document via the file upload button at the bottom of the page. This will trigger the ingestion graph to extract the text and store the embeddings in Supabase via the frontend `app/api/ingest` route.
182-
4. After the ingestion is complete, ask questions in the chat input.
183-
5. The chatbot will trigger the retrieval graph via the `app/api/chat` route to retrieve the most relevant documents from the vector database and use the relevant PDF context (if needed) to answer.
194+
195+
1. Use langgraph studio UI to interact with the LangGraph server and ensure the workflow is working as expected.
196+
197+
2. Navigate to http://localhost:3000 to use the chatbot UI.
198+
199+
3. Upload a small PDF document via the file upload button at the bottom of the page. This will trigger the ingestion graph to extract the text and store the embeddings in Supabase via the frontend `app/api/ingest` route.
200+
201+
4. After the ingestion is complete, ask questions in the chat input.
202+
203+
5. The chatbot will trigger the retrieval graph via the `app/api/chat` route to retrieve the most relevant documents from the vector database and use the relevant PDF context (if needed) to answer.
204+
184205

185206
### Uploading/Ingesting PDFs
186207

@@ -191,38 +212,40 @@ Select one or more PDF files to upload ensuring a total of max 5, each under 10M
191212
The backend processes the PDFs, extracts text, and stores embeddings in Supabase (or your chosen vector store).
192213

193214
### Asking Questions
194-
• Type your question in the chat input field.
195-
• Responses stream in real time. If the system retrieved documents, you’ll see a link to “View Sources” for each chunk of text used in the answer.
196215

197-
Viewing Chat History
198-
• The system creates a unique thread per user session (frontend). All messages are kept in the state for the session.
199-
• For demonstration purposes, the current example UI does not store the entire conversation beyond the local thread state and is not persistent across sessions. You can extend it to persist threads in a database. However, the "ingested documents" are persistent across sessions as they are stored in a vector database.
216+
- Type your question in the chat input field.
217+
- Responses stream in real time. If the system retrieved documents, you’ll see a link to “View Sources” for each chunk of text used in the answer.
218+
219+
### Viewing Chat History
220+
221+
- The system creates a unique thread per user session (frontend). All messages are kept in the state for the session.
222+
- For demonstration purposes, the current example UI does not store the entire conversation beyond the local thread state and is not persistent across sessions. You can extend it to persist threads in a database. However, the "ingested documents" are persistent across sessions as they are stored in a vector database.
200223

201224

202225
## Deploying the Backend
203226

204-
To deploy your backend ai agent to a cloud service, you can either use LangGraph's cloud as per this [guide](https://langchain-ai.github.io/langgraph/cloud/quick_start/?h=studio#deploy-to-langgraph-cloud) or self-host it as per this [guide](https://langchain-ai.github.io/langgraph/how-tos/deploy-self-hosted/).
227+
To deploy your LangGraph agent to a cloud service, you can either use LangGraph's cloud as per this [guide](https://langchain-ai.github.io/langgraph/cloud/quick_start/?h=studio#deploy-to-langgraph-cloud) or self-host it as per this [guide](https://langchain-ai.github.io/langgraph/how-tos/deploy-self-hosted/).
205228

206229
## Deploying the Frontend
207230
The frontend can be deployed to any hosting that supports Next.js (Vercel, Netlify, etc.).
208-
Make sure NEXT_PUBLIC_LANGGRAPH_API_URL is pointing to your deployed backend URL.
231+
232+
Make sure to set relevant environment variables in your deployment environment. In particular, ensure `NEXT_PUBLIC_LANGGRAPH_API_URL` is pointing to your deployed backend URL.
209233

210234
## Customizing the Agent
211235

212236
You can customize the agent on the backend and frontend.
213237

214238
### Backend
215239

216-
- In the configuration file `src/shared/configuration.ts`, you can change the default configs i.e. the vector store, k-value, and filter kwargs, shared between the ingestion and retrieval graphs. Configs can be used in each node of the graph or passed into the graph as a config object via a client.
240+
- In the configuration file `src/shared/configuration.ts`, you can change the default configs i.e. the vector store, k-value, and filter kwargs, shared between the ingestion and retrieval graphs. On the backend, configs can be used in each node of the graph workflow or from frontend, you can pass a config object into the graph's client.
217241
- You can adjust the prompts in the `src/retrieval_graph/prompts.ts` file.
218-
- If you'd like to change the retrieval model, you can do so in the `src/shared/retrieval.ts` file by adding another makeRetriever function that encapsulates the desired client for the vector store.
219-
242+
- If you'd like to change the retrieval model, you can do so in the `src/shared/retrieval.ts` file by adding another retriever function that encapsulates the desired client for the vector store and then updating the `makeRetriever` function to return the new retriever.
220243

221244

222245
### Frontend
223246

224247
- You can modify the file upload restrictions in the `app/api/ingest` route.
225-
- In `constants/graphConfigs.ts`, you can change the default configs for the ingestion and retrieval graphs. These include the model, k value, and retriever provider.
248+
- In `constants/graphConfigs.ts`, you can change the default config objects sent to the ingestion and retrieval graphs. These include the model provider, k value (no of source documents to retrieve), and retriever provider (i.e. vector store).
226249

227250

228251
## Troubleshooting
@@ -244,7 +267,7 @@ You can customize the agent on the backend and frontend.
244267

245268
## Next Steps
246269

247-
If you'd like to contribute to this project, feel free to open a pull request. Ensure it is well documented and tested.
270+
If you'd like to contribute to this project, feel free to open a pull request. Ensure it is well documented and includes tests in the test files.
248271

249-
If you'd like to learn more about building AI agents with LangChain and LangGraph, check out the book [Learning LangChain (O'Reilly)](https://tinyurl.com/learning-langchain).
272+
If you'd like to learn more about building AI chatbots and agents with LangChain and LangGraph, check out the book [Learning LangChain (O'Reilly)](https://tinyurl.com/learning-langchain).
250273

0 commit comments

Comments
 (0)