An intelligent conversational AI chatbot built with LangGraph, LangChain, Google Gemini, Streamlit, FAISS, and SQLite.
The chatbot supports persistent conversations, PDF-based Retrieval-Augmented Generation (RAG), web search, stock price lookup, calculator tools, and real-time streaming responses.
- Create and switch between multiple chat threads
- Persistent conversation history using SQLite
- LangGraph checkpointing for state management
- Automatically restores previous conversations
- Thread titles generated from the first user message
Upload a PDF to provide document-specific context to the chatbot.
The chatbot:
- Extracts text using
PyPDFLoader - Splits documents into chunks using
RecursiveCharacterTextSplitter - Generates embeddings using HuggingFace embeddings
- Stores vector embeddings using FAISS
- Retrieves relevant document chunks during conversations
- Maintains document context separately for each chat thread
The chatbot can search the web when additional or up-to-date information is required using the Tavily Search API.
Fetch stock information using the Alpha Vantage API.
Example:
What is the current stock price of AAPL?
Perform basic arithmetic operations:
- Addition
- Subtraction
- Multiplication
- Division
Example:
Calculate 245 * 67
The chatbot uses LangGraph tool calling to decide when external tools are required.
Available tools:
User Query
↓
Gemini LLM
↓
Does the query require a tool?
↓
┌──────────┬───────────┬─────────────┬────────────┐
│ RAG │ Web Search│ Stock Price │ Calculator │
└──────────┴───────────┴─────────────┴────────────┘
↓
Tool Result
↓
Gemini LLM
↓
Final Response
The UI also displays the current tool execution status.
AI responses are streamed in real time using Streamlit's st.write_stream().
This provides a more interactive experience instead of waiting for the complete response.
Each conversation has its own document context.
Thread A
├── Conversation History
└── PDF / FAISS Vector Store
Thread B
├── Conversation History
└── PDF / FAISS Vector Store
This prevents documents from one conversation from being used in another conversation.
The application includes limits to help prevent excessive resource usage:
- Maximum PDF pages per file:
100 - Maximum chunks per thread:
5000 - Document/vector-store TTL:
24 hours
Expired vector stores and document metadata are automatically cleaned up.
| Technology | Usage |
|---|---|
| Python | Core programming language |
| Streamlit | Chatbot frontend |
| LangChain | LLM and tool integration |
| LangGraph | Agent workflow and conversation state |
| Google Gemini 2.5 Flash | Large Language Model |
| HuggingFace | Text embeddings |
| FAISS | Vector similarity search |
| SQLite | Checkpoint and metadata storage |
| PyPDFLoader | PDF document loading |
| Tavily | Web search |
| Alpha Vantage | Stock data |
┌─────────────────┐
│ Streamlit UI │
└────────┬────────┘
│
▼
┌─────────────────┐
│ LangGraph │
│ Agent │
└────────┬────────┘
│
▼
┌─────────────────┐
│ Gemini 2.5 Flash│
└────────┬────────┘
│
Tool Required?
╱ │ │ ╲
▼ ▼ ▼ ▼
RAG Web Stock Calculator
│ │ │ │
▼ ▼ ▼ ▼
FAISS Tavily Alpha Python
Search Vantage
│
▼
PDF Context
PDF Upload
↓
PyPDFLoader
↓
Extract Pages
↓
Text Chunking
↓
HuggingFace Embeddings
↓
FAISS Vector Store
↓
Persisted Per Thread
↓
User Question
↓
Similarity Search
↓
Top Relevant Chunks
↓
Gemini LLM
↓
Final Answer
.
├── app.py
├── backend_rag.py
├── chatbot.db
├── faiss_stores/
├── .env
├── requirements.txt
└── README.md
Contains the Streamlit frontend.
Responsibilities:
- Chat UI
- Conversation navigation
- Thread management
- PDF upload
- Chat history rendering
- Streaming responses
- Tool execution status
Contains the chatbot backend.
Responsibilities:
- Gemini LLM initialization
- HuggingFace embeddings
- FAISS vector store
- PDF ingestion
- RAG retrieval
- LangGraph workflow
- Tool definitions
- SQLite persistence
- Thread management
git clone <your-repository-url>
cd <your-repository-name>python -m venv venvActivate it on Windows:
venv\Scripts\activateOn macOS/Linux:
source venv/bin/activatepip install -r requirements.txtCreate a .env file in the project root:
GEMINI_API_KEY=your_gemini_api_key
TAVILY_API_KEY=your_tavily_api_key
ALPHA_VANTAGE_API_KEY=your_alpha_vantage_api_keyImportant: Never commit your
.envfile or API keys to GitHub.
Add the following to .gitignore:
.env
venv/
__pycache__/
chatbot.db
faiss_stores/
Start the Streamlit application:
streamlit run app.pyThe application will be available locally in your browser.
User
↓
LangGraph
↓
Gemini
↓
Response
User: "Summarize chapter 2"
↓
Gemini detects
document query
↓
RAG Tool
↓
FAISS Similarity Search
↓
Relevant PDF Chunks
↓
Gemini
↓
Final Response
User: "What is 245 × 67?"
↓
Gemini
↓
Calculator Tool
↓
16415
↓
Gemini Response
Explain what Retrieval-Augmented Generation is.
Summarize the uploaded document.
What are the main concepts discussed in chapter 3?
Explain the uploaded PDF in simple terms.
What are the latest developments in generative AI?
Get the stock price of TSLA.
Calculate (245 * 67) / 5.
The chatbot follows this workflow:
START
│
▼
chat_node
│
├── No Tool Call ──────────────► END
│
└── Tool Call
│
▼
ToolNode
│
▼
chat_node
│
▼
END
The chat_node sends the conversation to Gemini.
If Gemini requests a tool, LangGraph routes execution to the ToolNode. After receiving the tool result, the response is sent back to the LLM to generate the final answer.
The project currently uses:
- Vector similarity search instead of hybrid search
- Basic document metadata management
- No user authentication
- No semantic long-term memory
- No RAG page/source citations in final responses
- No document deletion interface
- No conversation deletion or renaming
- No automated evaluation pipeline
- Hybrid search using BM25 + vector search
- Reranking retrieved documents
- Page-level source citations
- Multi-document retrieval
- Document selection and deletion
- Long-term user memory
- Automatic memory extraction
- Conversation summarization
- Semantic memory retrieval
- Rename conversations
- Delete conversations
- Search conversations
- Pin important conversations
- AI-generated conversation titles
- Query routing node
- Tool usage evaluation
- RAG evaluation
- Answer faithfulness evaluation
- Latency monitoring
- Token and cost tracking
- User feedback system
- User authentication
- Secure API key management
- Rate limiting
- Improved prompt injection protection
- Tool permission controls
┌──────────────┐
│ Streamlit UI │
└──────┬───────┘
│
▼
┌──────────────┐
│ Auth │
└──────┬───────┘
│
▼
┌──────────────┐
│ LangGraph │
│ Query Router │
└──────┬───────┘
│
┌──────────────┼──────────────┐
▼ ▼ ▼
Chat Node RAG Tools
│ ╱ │ ╲
▼ Web Stock Calc
Hybrid Search
│
┌─────┴─────┐
▼ ▼
BM25 FAISS
│ │
└─────┬─────┘
▼
Reranker
│
▼
Source Citations
│
▼
Final Response
┌──────────┴──────────┐
▼ ▼
Short-Term Memory Long-Term Memory
SQLite Checkpoints User Memory Store
Contributions, suggestions, and improvements are welcome.
- Fork the repository
- Create a new branch
git checkout -b feature/your-feature-name- Make your changes
- Commit your changes
git commit -m "Add your feature"- Push to your branch
git push origin feature/your-feature-name- Open a Pull Request
This project is currently intended for educational and portfolio purposes.
Sahil Yadav
Engineering Student | AI/ML Enthusiast | Software Developer
⭐ If you found this project useful, consider giving it a star!