huytrao123/Diary-chatbot
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
# 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.txtEnvironment Configuration
Create a .env file in the project root directory with the following structure:
# 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.7Important Notes:
Run the Application
1. Start RAG Service
python start_rag_service.pyService will run at: http://127.0.0.1:8001
2. Start Streamlit UI
cd src/streamlit_app
streamlit run interface.pyUI 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
# Run all tests
python -m pytest tests/
# Run specific test
python -m pytest tests/test_rag_system.py๐ค Contributing
- Fork the project
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add some AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - 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
# 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.txtEnvironment Configuration
Create a .env file in the project root directory with the following structure:
# 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-flashImportant Notes:
- Replace all placeholder values with your actual API keys and configuration
- Keep your
.envfile secure and never commit it to version control - The
.envfile is already included in.gitignore - Use
env_template.txtas a reference to create your.envfile
Run the Application
# 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
- Fork the project
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
๐ Contact
- Author: [DongAnh]
- Email: [donganhng098@gmail.com]
- GitHub: [github.com/DongAnh]
๐ Acknowledgments
- Gemini for GPT models
- Google for Universal Sentence Encoder
- ChromaDB team for vector database
- FastAPI and Streamlit communities
- RAG architecture
