An intelligent AI chatbot that remembers conversations and answers questions from your PDF documents using Retrieval-Augmented Generation (RAG)
This project demonstrates a modern Conversational AI application that combines:
- Conversational Memory - Remembers previous interactions
- PDF Processing - Extract and analyze document content
- Semantic Search - Find relevant information using embeddings
- RAG (Retrieval-Augmented Generation) - Answer questions using document context
Perfect for building intelligent assistants that can answer questions about your documents!
| Feature | Description |
|---|---|
| π¬ Memory System | Maintains conversation history for context-aware responses |
| π PDF Support | Upload and process PDF documents instantly |
| π Smart Search | Semantic search using HuggingFace embeddings |
| π€ AI Powered | Google Gemini API for intelligent responses |
| β‘ Fast Retrieval | FAISS vector database for efficient document search |
| π¨ Modern UI | Clean and intuitive Streamlit interface |
| π Free to Use | Leverages free Gemini API tier |
Frontend & Framework
βββ Streamlit β Interactive web interface
βββ LangChain β AI/ML orchestration framework
βββ Python β Core programming language
AI & NLP
βββ Google Gemini API β Large Language Model
βββ HuggingFace β Embeddings (sentence-transformers)
βββ LangChain Core β LLM chains and prompts
Data Storage
βββ FAISS β Vector similarity search
βββ PyPDF β PDF parsing
βββ Session State β Conversation memory
- Python 3.8 or higher
- Google API Key (free tier available)
- Internet connection
git clone https://github.com/YOUR_USERNAME/chatbot_with_memory.git
cd chatbot_with_memorypip install -r requirements.txtCreate a .env file in the root directory:
GOOGLE_API_KEY=your_gemini_api_key_hereGet your free API key:
- Visit Google AI Studio
- Click "Create API Key"
- Copy and paste into your
.envfile
streamlit run app.pyThe app will open at http://localhost:8501 π
User Input
β
[PDF Processing] β Upload PDF
β
[Text Splitting] β Break into chunks
β
[Embeddings] β Convert to vectors (HuggingFace)
β
[FAISS Index] β Store vectors for fast search
β
[Query Retrieval] β Find relevant documents
β
[LLM + Context] β Gemini generates answer
β
[Output] β Display to user + Sources
-
Upload a PDF
- Click "Choose File" in the sidebar
- Select your PDF document
- Click "Process PDF"
-
Ask Questions
- Type your question in the chat input
- The chatbot retrieves relevant content from the PDF
- Gemini generates an intelligent answer
-
View Sources
- Expand the "Sources" section to see which PDF content was used
chatbot_with_memory/
β
βββ app.py # Main Streamlit application
βββ requirements.txt # Python dependencies
βββ .env.example # Environment variables template
βββ .gitignore # Git ignore rules
βββ README.md # This file
β
βββ vectorstore/ # FAISS vector database (auto-created)
βββ index.faiss
All required packages are in requirements.txt:
streamlit # Web framework
langchain # AI orchestration
langchain-google-genai # Gemini integration
langchain-community # Additional tools
langchain-core # Core utilities
langchain-text-splitters # Text chunking
python-dotenv # Environment management
faiss-cpu # Vector search
sentence-transformers # Embeddings
pypdf # PDF parsing
# The app handles everything through the UI, but here's the flow:
# 1. Upload PDF β creates embeddings
# 2. User asks: "What is the main topic?"
# 3. System retrieves: Top 4 relevant document chunks
# 4. Gemini generates: Context-aware answer
# 5. Display: Answer + Source referencesEdit in app.py:
retriever = vectorstore.as_retriever(search_kwargs={"k": 4}) # Change k for more/fewer resultsUpdate in app.py:
llm = ChatGoogleGenerativeAI(
model="gemini-2.5-flash", # Or use gemini-pro
google_api_key=GOOGLE_API_KEY,
temperature=0.3 # Adjust for more/less creativity
)text_splitter = RecursiveCharacterTextSplitter(
chunk_size=1000, # Increase for larger chunks
chunk_overlap=200 # Overlap for context continuity
)| Issue | Solution |
|---|---|
ModuleNotFoundError |
Run pip install -r requirements.txt |
GOOGLE_API_KEY not found |
Check .env file and verify key is added |
No module named 'faiss' |
Install: pip install faiss-cpu |
Slow PDF processing |
Reduce chunk_size in RecursiveCharacterTextSplitter |
Poor answer quality |
Increase k value in retriever for more context |
β Upload clear, well-formatted PDFs β Ask specific questions - More specific = better answers β Use PDF reports, manuals, or books - Works great with technical docs β Ask follow-up questions - Leverage conversation memory β Check sources - Verify the answer against referenced documents
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Feel free to:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Issues? Open a GitHub issue
- Ideas? Discussions are welcome
- Questions? Check existing issues first
- LangChain - AI framework
- Google Gemini API - LLM
- Streamlit - Web framework
- FAISS - Vector search
- HuggingFace - Embeddings
β If you find this helpful, please give it a star!
Made with β€οΈ for the AI community
The chatbot remembers previous conversation history using LangChain memory.
PDF Question Answering
Users can upload PDFs and ask contextual questions from the document.
Semantic Search
FAISS retrieves the most relevant document chunks using vector embeddings.
π¦ Requirements streamlit langchain langchain-community langchain-google-genai faiss-cpu pypdf sentence-transformers python-dotenv google-generativeai βοΈ Deployment
Recommended platforms:
Hugging Face Spaces Streamlit Community Cloud π§ͺ Example Use Cases AI document assistant Resume analyzer Research paper Q&A Company knowledge chatbot Educational assistant Legal document search π Future Improvements Multi-PDF support Persistent database memory Voice input/output Authentication system Chat export Image understanding Local LLM support with Ollama π¨βπ» Author
umran666
GitHub:
https://github.com/your-username β If you like this project
Give it a star on GitHub β