A powerful AI chat application built with Streamlit + LangGraph + Ollama that supports:
- Multi-threaded conversations
- PDF-based Retrieval-Augmented Generation (RAG)
- Web search
- Stock price lookup
- Calculator tool
- Persistent memory using SQLite checkpoints
- Each conversation has a unique
thread_id - Threads are stored and can be reopened or deleted
- Chat history persists using LangGraph checkpoints
-
Upload a PDF per thread
-
Automatically:
- Splits into chunks
- Creates embeddings
- Stores in FAISS vector DB
-
Queries retrieve relevant chunks for accurate answers
-
Even if the LLM fails to call tools, document context is:
- Retrieved manually
- Injected into the system prompt
-
Ensures reliable answers even with small models
The assistant can use:
rag_tool→ query uploaded PDFsDuckDuckGoSearchRun→ web searchcalculator→ math operationsget_stock_price→ stock API (Alpha Vantage)
- Uses LangGraph streaming
- Displays tool usage in real-time
-
Uses
SqliteSaver -
Stores:
- Messages
- Tool calls
- State transitions
Handles:
- UI rendering
- Thread management
- File uploads
- Chat display
- Streaming responses
Handles:
- LLM reasoning
- Tool calling
- RAG retrieval
- State persistence
User Input
↓
chat_node (LLM)
↓
[optional] Tool Call
↓
tools node executes
↓
chat_node (final response)
↓
Stream to UI
.
├── app.py # Streamlit frontend
├── backend.py # LangGraph agent + tools + RAG
├── chatbot.db # SQLite checkpoint DB
├── .env # Environment variables
└── README.md
git clone <your-repo-url>
cd <repo>pip install -r requirements.txtDownload Ollama: https://ollama.com
Pull a model:
ollama pull qwen3:4b
⚠️ Recommended: use qwen3:4b or higher (0.6b is weak for tool calling)
Create .env:
OLLAMA_MODEL=qwen3:0.6bstreamlit run app.py- Stored temporarily
- Loaded using
PyPDFLoader
RecursiveCharacterTextSplitter- Chunk size: 1000
- Overlap: 200
- Model:
nomic-embed-text
- FAISS in-memory store
- Top-K similarity search (k=4)
- Retrieved chunks inserted into system prompt
rag_tool(query: str)- Retrieves relevant document chunks
- Returns context + metadata
calculator(first_num, second_num, operation)- add, sub, mul, div
get_stock_price(symbol)- Uses Alpha Vantage API
- DuckDuckGo web search
-
Each thread = unique UUID
-
Stored in:
checkpointstablewritestable
-
Managed via
SqliteSaver
-
Removes:
- UI state
- Database checkpoints
- Fix Delete logic