kietphan0202/RAG_Chatbot

A RAG-powered chatbot that answers questions directly from user-provided documents.

Python

0

2 commits

updated Sep 10, 2025

See the code

README

PDF RAG Chatbot

Overview

PDF RAG Chatbot is a Streamlit-based AI assistant that allows users to upload PDF documents and interactively ask questions about their content. The chatbot leverages Retrieval-Augmented Generation (RAG) techniques, combining semantic chunking, vector search, and a large language model (LLM) to provide accurate answers based on the uploaded PDF.

Features

  • PDF Upload & Processing: Users can upload PDF files, which are semantically chunked and indexed for efficient retrieval.
  • Vietnamese Language Support: Uses Vietnamese-specific embedding and LLM models for best results on Vietnamese documents.
  • Chat Interface: Intuitive chat UI for asking questions and receiving answers based on the PDF content.
  • Session Management: Maintains chat history and allows users to clear conversations.
  • Model Loading: Loads embeddings and LLM only once per session for efficiency.

How It Works

  1. Upload PDF: The user uploads a PDF file via the sidebar.
  2. Processing: The PDF is split into semantic chunks using SemanticChunker and embedded using HuggingFaceEmbeddings.
  3. Vector Store: Chunks are stored in a Chroma vector database for fast retrieval.
  4. RAG Pipeline: When a question is asked, relevant chunks are retrieved and passed to the LLM (Vicuna-7B) using a RAG prompt.
  5. Chat: The assistant answers questions based on the PDF content, maintaining a chat history.

Technologies Used

  • Streamlit: For the web UI and session management.
  • LangChain: For document loading, chunking, and RAG pipeline.
  • HuggingFace Transformers: For embeddings and LLM (Vicuna-7B).
  • Chroma: For vector database and retrieval.
  • PyPDFLoader: For PDF parsing.

File Structure

  • app.py: Main Streamlit app, UI, and chat logic.
  • model.py: Loads embeddings and LLM models.
  • pdf.py: Handles PDF processing, chunking, and RAG pipeline setup.
  • session_state.py: Initializes and manages Streamlit session state variables.
  • data/: Contains sample PDF files.
  • logo/: Contains logo image for the app.

Setup Instructions

  1. Install Dependencies:
    • Python 3.11+
    • Install required packages:
      pip install streamlit langchain langchain_huggingface langchain_chroma langchain_community langchain_experimental transformers torch chromadb
      
  2. Run the App:
    streamlit run app.py
    
  3. Usage:
    • Upload a PDF file in the sidebar.
    • Click "Xử lý PDF" to process the document.
    • Ask questions in the chat box.
    • Clear chat history or upload a new PDF as needed.

Customization

  • Models:
    • Embeddings: bkai-foundation-models/vietnamese-bi-encoder
    • LLM: lmsys/vicuna-7b-v1.5
  • Chunking:
    • Uses semantic chunking for better context retrieval.

Notes

  • The app is optimized for Vietnamese documents but can be adapted for other languages by changing the models.
  • Large models may require significant system resources (RAM/VRAM).

License

This project is for educational and research purposes.

Credits

kietphan0202/RAG_Chatbot

A RAG-powered chatbot that answers questions directly from user-provided documents.

Python

0

2 commits

updated Sep 10, 2025

See the code

README

PDF RAG Chatbot

Overview

PDF RAG Chatbot is a Streamlit-based AI assistant that allows users to upload PDF documents and interactively ask questions about their content. The chatbot leverages Retrieval-Augmented Generation (RAG) techniques, combining semantic chunking, vector search, and a large language model (LLM) to provide accurate answers based on the uploaded PDF.

Features

  • PDF Upload & Processing: Users can upload PDF files, which are semantically chunked and indexed for efficient retrieval.
  • Vietnamese Language Support: Uses Vietnamese-specific embedding and LLM models for best results on Vietnamese documents.
  • Chat Interface: Intuitive chat UI for asking questions and receiving answers based on the PDF content.
  • Session Management: Maintains chat history and allows users to clear conversations.
  • Model Loading: Loads embeddings and LLM only once per session for efficiency.

How It Works

  1. Upload PDF: The user uploads a PDF file via the sidebar.
  2. Processing: The PDF is split into semantic chunks using SemanticChunker and embedded using HuggingFaceEmbeddings.
  3. Vector Store: Chunks are stored in a Chroma vector database for fast retrieval.
  4. RAG Pipeline: When a question is asked, relevant chunks are retrieved and passed to the LLM (Vicuna-7B) using a RAG prompt.
  5. Chat: The assistant answers questions based on the PDF content, maintaining a chat history.

Technologies Used

  • Streamlit: For the web UI and session management.
  • LangChain: For document loading, chunking, and RAG pipeline.
  • HuggingFace Transformers: For embeddings and LLM (Vicuna-7B).
  • Chroma: For vector database and retrieval.
  • PyPDFLoader: For PDF parsing.

File Structure

  • app.py: Main Streamlit app, UI, and chat logic.
  • model.py: Loads embeddings and LLM models.
  • pdf.py: Handles PDF processing, chunking, and RAG pipeline setup.
  • session_state.py: Initializes and manages Streamlit session state variables.
  • data/: Contains sample PDF files.
  • logo/: Contains logo image for the app.

Setup Instructions

  1. Install Dependencies:
    • Python 3.11+
    • Install required packages:
      pip install streamlit langchain langchain_huggingface langchain_chroma langchain_community langchain_experimental transformers torch chromadb
      
  2. Run the App:
    streamlit run app.py
    
  3. Usage:
    • Upload a PDF file in the sidebar.
    • Click "Xử lý PDF" to process the document.
    • Ask questions in the chat box.
    • Clear chat history or upload a new PDF as needed.

Customization

  • Models:
    • Embeddings: bkai-foundation-models/vietnamese-bi-encoder
    • LLM: lmsys/vicuna-7b-v1.5
  • Chunking:
    • Uses semantic chunking for better context retrieval.

Notes

  • The app is optimized for Vietnamese documents but can be adapted for other languages by changing the models.
  • Large models may require significant system resources (RAM/VRAM).

License

This project is for educational and research purposes.

Credits