CoolFace
Apppublic

huytrao123/Diary-chatbot-RAG

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes
App README

RAG Personal Diary Chatbot

๐Ÿ“– Project Description

RAG Personal Diary Chatbot is an intelligent chatbot application that uses RAG (Retrieval-Augmented Generation) architecture to interact with users' personal diaries. The application allows users to ask questions about diary content and receive accurate answers based on actual data.

โœจ Key Features

๐Ÿ—๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Streamlit UI  โ”‚    โ”‚   FastAPI       โ”‚    โ”‚   Vector        โ”‚
โ”‚   (Frontend)    โ”‚โ—„โ”€โ”€โ–บโ”‚   Backend       โ”‚โ—„โ”€โ”€โ–บโ”‚   Database     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                              โ–ผ
                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                       โ”‚   RAG Engine    โ”‚
                       โ”‚   (LLM +       โ”‚
                       โ”‚   Retrieval)    โ”‚
                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Installation and Setup

System Requirements

Install Dependencies

bash
# Create virtual environment
python -m venv .venv

# Activate virtual environment
# Windows
.venv\Scripts\activate
# Linux/Mac
source .venv/bin/activate

# Install packages
pip install -r requirements.txt

Environment Configuration

Create a .env file in the project root directory with the following structure:

env
# API Keys
OPENAI_API_KEY=your_openai_api_key_here
GOOGLE_API_KEY=your_google_api_key_here
ANTHROPIC_API_KEY=your_anthropic_api_key_here

# Database Configuration
DATABASE_URL=sqlite:///./user_database/auth.db
VECTOR_DB_PATH=./VectorDB

# Model Configuration
EMBEDDING_MODEL=google-universal-sentence-encoder
LLM_MODEL=gpt-3.5-turbo
CHUNK_SIZE=1000
CHUNK_OVERLAP=200

# Server Configuration
RAG_SERVICE_PORT=8001
STREAMLIT_PORT=8501
FASTAPI_PORT=8000

# Security
SECRET_KEY=your_secret_key_here
JWT_SECRET=your_jwt_secret_here

# Logging
LOG_LEVEL=INFO
LOG_FILE=./logs/app.log

# Vector Database
CHROMA_DB_PATH=./VectorDB
PERSIST_DIRECTORY=./VectorDB

# File Processing
SUPPORTED_FORMATS=pdf,docx,txt,md
MAX_FILE_SIZE=10485760
TEMP_DIR=./temp

# RAG Configuration
TOP_K_RESULTS=5
SIMILARITY_THRESHOLD=0.7
MAX_TOKENS=4096
TEMPERATURE=0.7

Important Notes:

Run the Application

1. Start RAG Service
bash
python start_rag_service.py

Service will run at: http://127.0.0.1:8001

2. Start Streamlit UI
bash
cd src/streamlit_app
streamlit run interface.py

UI will run at: http://localhost:8501

๐Ÿ“ Directory Structure

RAG-Personal-Diary-Chatbot/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ Indexingstep/          # Data indexing pipeline
โ”‚   โ”œโ”€โ”€ Retrivel_And_Generation/  # RAG engine
โ”‚   โ”œโ”€โ”€ rag_service/           # FastAPI backend
โ”‚   โ”œโ”€โ”€ streamlit_app/         # User interface
โ”‚   โ””โ”€โ”€ VectorDB/              # Vector database
โ”œโ”€โ”€ notebook/                   # Jupyter notebooks
โ”œโ”€โ”€ tests/                      # Unit tests
โ”œโ”€โ”€ images/                     # Documentation images
โ”œโ”€โ”€ start_rag_service.py       # Service startup script
โ”œโ”€โ”€ .env                       # Environment variables (create from template)
โ”œโ”€โ”€ env_template.txt           # Environment variables template
โ””โ”€โ”€ README.md

๐Ÿ”ง Configuration

Vector Database

AI Models

๐Ÿ“Š Performance

๐Ÿงช Testing

bash
# Run all tests
python -m pytest tests/

# Run specific test
python -m pytest tests/test_rag_system.py

๐Ÿค Contributing

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

๐Ÿ“ License

This project is distributed under the MIT License. See the LICENSE file for more details.

๐Ÿ“ž Contact

๐Ÿ™ Acknowledgments

๐Ÿ“– Project Description

RAG Personal Diary Chatbot is an intelligent chatbot application that leverages Retrieval-Augmented Generation (RAG) architecture to interact with users' personal diaries. Users can ask questions about their diary content and receive accurate, context-based answers.

โœจ Key Features

  • โ€”Diary Indexing: Automatically processes and indexes diary files (PDF, DOCX, TXT)
  • โ€”Semantic Search: Uses a vector database for semantic search
  • โ€”AI Chatbot: Natural interaction with diary data
  • โ€”User Isolation: Each user has a separate vector database
  • โ€”Web Interface: Easy-to-use Streamlit UI
  • โ€”REST API: FastAPI backend for integration

๐Ÿ—๏ธ System Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Streamlit UI  โ”‚โ—„โ”€โ”€โ–บโ”‚   FastAPI     โ”‚โ—„โ”€โ”€โ–บโ”‚  Vector DB    โ”‚
โ”‚ (Frontend)    โ”‚    โ”‚   Backend     โ”‚    โ”‚  (ChromaDB)   โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚
                              โ–ผ
                       โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                       โ”‚   RAG Engine  โ”‚
                       โ”‚ (LLM +        โ”‚
                       โ”‚  Retrieval)   โ”‚
                       โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Installation and Setup

System Requirements

  • โ€”Python 3.8+

Install Dependencies

bash
# Create virtual environment
python -m venv .venv

# Activate virtual environment
# Windows
.venv\Scripts\activate
# Linux/Mac
source .venv/bin/activate

# Install packages
pip install -r requirements.txt

Environment Configuration

Create a .env file in the project root directory with the following structure:

env
# Google API Configuration for RAG System
GOOGLE_API_KEY=[Google API key]

# Database Configuration
DATABASE_PATH=./src/streamlit_app/backend/diary.db

# Vector Database Configuration
VECTOR_DB_PATH=./src/Indexingstep/diary_vector_db_enhanced
COLLECTION_NAME=diary_entries

# RAG Configuration
EMBEDDING_MODEL=models/embedding-001
CHAT_MODEL=gemini-2.5-flash

Important Notes:

  • โ€”Replace all placeholder values with your actual API keys and configuration
  • โ€”Keep your .env file secure and never commit it to version control
  • โ€”The .env file is already included in .gitignore
  • โ€”Use env_template.txt as a reference to create your .env file

Run the Application

bash
# Start the RAG backend service
python start_rag_service.py

# Start the Streamlit UI
streamlit run src/streamlit_app/interface.py

๐Ÿ“ Directory Structure

RAG-Personal-Diary-Chatbot/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ Indexingstep/          # Data indexing pipeline
โ”‚   โ”œโ”€โ”€ Retrivel_And_Generation/  # RAG engine
โ”‚   โ”œโ”€โ”€ rag_service/           # FastAPI backend
โ”‚   โ”œโ”€โ”€ streamlit_app/         # User interface
โ”‚   โ””โ”€โ”€ VectorDB/              # Vector database
โ”œโ”€โ”€ notebook/                  # Jupyter notebooks
โ”œโ”€โ”€ tests/                     # Unit tests
โ”œโ”€โ”€ images/                    # Documentation images
โ”œโ”€โ”€ start_rag_service.py       # Service startup script
โ”œโ”€โ”€ .env                       # Environment variables (create from template)
โ”œโ”€โ”€ env_template.txt           # Environment variables template
โ””โ”€โ”€ README.md

๐Ÿ”ง Configuration

Vector Database

  • โ€”ChromaDB: Main database for vector embeddings
  • โ€”Chunk size: 1000 characters (customizable)
  • โ€”Overlap: 200 characters between chunks

AI Models

  • โ€”Embedding: Google's Universal Sentence Encoder
  • โ€”LLM: Google Gemini (can be replaced with other models)

๐Ÿ“Š Performance

  • โ€”Processing time: ~2-5 seconds per question
  • โ€”Accuracy: 85-95% depending on data quality
  • โ€”Scalability: Supports thousands of diaries

๐Ÿค Contributing

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

๐Ÿ“ž Contact

  • โ€”Author: [huytrao]
  • โ€”Email: [traohuy098@gmail.com]
  • โ€”GitHub: [github.com/huytrao]

๐Ÿ™ Acknowledgments

  • โ€”Gemini for GPT models
  • โ€”Google for Universal Sentence Encoder
  • โ€”ChromaDB team for vector database
  • โ€”FastAPI and Streamlit communities
  • โ€”RAG architecture