You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+50-27Lines changed: 50 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# AI PDF Chatbot & Agent Powered by LangChain and LangGraph
2
2
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.
4
4
5
5
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.
6
6
@@ -40,6 +40,7 @@ This template is also an accompanying example to the book [Learning LangChain (O
@@ -153,34 +156,52 @@ This monorepo uses Turborepo to manage both backend and frontend projects. You c
153
156
154
157
1. Navigate to backend:
155
158
156
-
`cd backend`
159
+
```bash
160
+
cd backend
161
+
```
157
162
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).
160
164
161
-
`yarn langgraph:dev`
165
+
3. Start LangGraph in dev mode:
166
+
167
+
```bash
168
+
yarn langgraph:dev
169
+
```
162
170
163
171
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/)
164
172
165
173
### Running the Frontend
166
174
167
-
Open a new terminal window/tab:
175
+
1. Navigate to frontend:
168
176
169
-
`cd frontend`
177
+
```bash
178
+
cd frontend
179
+
```
170
180
171
-
`yarn dev`
181
+
2. Start the Next.js development server:
182
+
183
+
```bash
184
+
yarn dev
185
+
```
172
186
173
187
This will start a local Next.js development server (by default on port 3000).
188
+
174
189
Access the UI in your browser at http://localhost:3000.
175
190
176
191
## Usage
177
192
178
193
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
+
184
205
185
206
### Uploading/Ingesting PDFs
186
207
@@ -191,38 +212,40 @@ Select one or more PDF files to upload ensuring a total of max 5, each under 10M
191
212
The backend processes the PDFs, extracts text, and stores embeddings in Supabase (or your chosen vector store).
192
213
193
214
### 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.
196
215
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.
200
223
201
224
202
225
## Deploying the Backend
203
226
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/).
205
228
206
229
## Deploying the Frontend
207
230
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.
209
233
210
234
## Customizing the Agent
211
235
212
236
You can customize the agent on the backend and frontend.
213
237
214
238
### Backend
215
239
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.
217
241
- 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.
220
243
221
244
222
245
### Frontend
223
246
224
247
- 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).
226
249
227
250
228
251
## Troubleshooting
@@ -244,7 +267,7 @@ You can customize the agent on the backend and frontend.
244
267
245
268
## Next Steps
246
269
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.
248
271
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).
0 commit comments