Skip to content

umran666/ChatBot_With_Memory

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’¬ Chatbot with Memory + PDF Q&A

An intelligent AI chatbot that remembers conversations and answers questions from your PDF documents using Retrieval-Augmented Generation (RAG)

Python Streamlit LangChain License

🎯 Overview

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!


✨ Key Features

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

πŸ› οΈ Technology Stack

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

πŸ“‹ Requirements

  • Python 3.8 or higher
  • Google API Key (free tier available)
  • Internet connection

πŸš€ Quick Start

1️⃣ Clone the Repository

git clone https://github.com/YOUR_USERNAME/chatbot_with_memory.git
cd chatbot_with_memory

2️⃣ Install Dependencies

pip install -r requirements.txt

3️⃣ Set Up Environment Variables

Create a .env file in the root directory:

GOOGLE_API_KEY=your_gemini_api_key_here

Get your free API key:

  1. Visit Google AI Studio
  2. Click "Create API Key"
  3. Copy and paste into your .env file

4️⃣ Run the Application

streamlit run app.py

The app will open at http://localhost:8501 πŸŽ‰


πŸ’‘ How It Works

Architecture Flow

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

Step-by-Step Usage

  1. Upload a PDF

    • Click "Choose File" in the sidebar
    • Select your PDF document
    • Click "Process PDF"
  2. Ask Questions

    • Type your question in the chat input
    • The chatbot retrieves relevant content from the PDF
    • Gemini generates an intelligent answer
  3. View Sources

    • Expand the "Sources" section to see which PDF content was used

πŸ“ Project Structure

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

πŸ“¦ Dependencies

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

πŸŽ“ Example Usage

# 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 references

βš™οΈ Configuration

Customize Retrieval

Edit in app.py:

retriever = vectorstore.as_retriever(search_kwargs={"k": 4})  # Change k for more/fewer results

Change LLM Model

Update 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
)

Adjust Text Chunk Size

text_splitter = RecursiveCharacterTextSplitter(
    chunk_size=1000,      # Increase for larger chunks
    chunk_overlap=200     # Overlap for context continuity
)

πŸ”§ Troubleshooting

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

🌟 Tips for Best Results

βœ… 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


πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


🀝 Contributing

Contributions are welcome! Feel free to:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“§ Contact & Support

  • Issues? Open a GitHub issue
  • Ideas? Discussions are welcome
  • Questions? Check existing issues first

πŸ™ Acknowledgments


⭐ If you find this helpful, please give it a star!

Made with ❀️ for the AI community

▢️ Run the Application streamlit run app.py 🧠 How It Works PDF Processing Pipeline PDF Upload ↓ Text Extraction ↓ Chunking ↓ Embeddings Generation ↓ FAISS Vector Storage ↓ Retriever ↓ Gemini Response πŸ“Έ Features Overview Chat Memory

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 ⭐

About

An intelligent AI chatbot that remembers conversations and answers questions from your PDF documents using Retrieval-Augmented Generation (RAG)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages