Skip to content

A modern Retrieval-Augmented Generation (RAG) chatbot for apartment rentals. Features a beautiful Streamlit web interface and a terminal chat mode. Supports real-time property search, pricing info, and conversation history using ChromaDB, MongoDB, and Gemini AI. Easy to set up, extensible, and perfect for demos or production use.

Notifications You must be signed in to change notification settings

farvath/rag-application-chatbot

Repository files navigation

RAG Apartment Chatbot - Installation & Usage Guide

🎯 Project Overview

This is a sophisticated RAG (Retrieval-Augmented Generation) chatbot for apartment rentals with dual interfaces:

  • Interactive Mode: Terminal-based chat
  • Web Mode: Beautiful Streamlit web interface

🔧 Installation

1. Install Dependencies

pip install streamlit google-genai chromadb pymongo python-dotenv sentence-transformers

2. Configure Environment Variables

Create a .env file in your project root with the following content:

# API Keys
GEMINI_API_KEY="your_gemini_api_key"
GEMINI_MODEL_NAME="gemini-2.5-flash-lite"

# MongoDB Configuration
MONGO_URI="your_mongodb_uri"
MONGO_DB_NAME="chat_sessions"
MONGO_COLLECTION_NAME="chatbot_context"

# ChromaDB Configuration
CHROMA_DB_PATH="./chroma_storage"
CHROMA_COLLECTION_NAME="json_docs"
CHROMA_EMBEDDING_MODEL_NAME="all-MiniLM-L6-v2"

# Data Configuration
JSON_FILE_PATH="./data_ingestion/apartments.json"

# Application Configuration
DEFAULT_USER_ID="default_user"
RAG_CONTEXT_LIMIT="5"
APP_MODE=web
WEB_HOST="127.0.0.1"
WEB_PORT="8501"

🚀 Usage

Interactive Mode

1. Start the FastAPI backend:

uvicorn api_server:app --host 127.0.0.1 --port 8000 --reload

2. Start the Streamlit frontend:

streamlit run frontend/app.py --server.port 8501

Make sure your .env has APP_MODE=web. Open: http://127.0.0.1:8501 in your browser.

🏗️ Architecture

Complete RAG Workflow:

┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│   User Query    │───▶│   ChromaDB       │───▶│   Context       │
│                 │    │   (Apartments)   │    │   Retrieved     │
└─────────────────┘    └──────────────────┘    └─────────────────┘
                                                         │
┌─────────────────┐    ┌──────────────────┐            ▼
│   Final         │◀───│   Gemini AI      │◀───┌─────────────────┐
│   Response      │    │   Generation     │    │   Enhanced      │
└─────────────────┘    └──────────────────┘    │   Prompt        │
         │                                      └─────────────────┘
         ▼                                               ▲
┌─────────────────┐    ┌──────────────────┐            │
│   MongoDB       │◀───│   Conversation   │────────────┘
│   Storage       │    │   History        │
└─────────────────┘    └──────────────────┘

🌐 Streamlit Web Interface Features

🎨 Beautiful UI Components:

  • ✅ Real-time chat interface with message bubbles
  • ✅ Session management with user/session IDs
  • ✅ Sidebar with controls and system status
  • ✅ Responsive design for mobile/desktop
  • ✅ Custom CSS styling with gradients
  • ✅ Loading indicators and error handling

🛠️ Interactive Features:

  • New Session: Start fresh conversation
  • Clear Chat: Remove history from UI and database
  • System Status: Check component health
  • Example Queries: Quick-start with sample questions
  • Auto-scroll: Latest messages always visible

📊 Session Information:

  • User ID and Session ID display
  • Message count tracking
  • Connection status indicator
  • Real-time updates

📊 Data Loading

  • First Run: Automatically loads apartments.json into ChromaDB
  • Subsequent Runs: Skips loading if data already exists
  • Persistent Storage: Data survives application restarts

🔄 Mode Switching

Switch between modes by changing the APP_MODE environment variable:

# Interactive mode
export APP_MODE="interactive"
python main.py

# Web mode (Streamlit)
export APP_MODE="web"
python main.py

🛠️ Streamlit Advantages

🚀 Why Streamlit over FastAPI?

  • Simpler Development: No HTML/CSS/JavaScript needed
  • Built for AI: Perfect for chatbots and ML applications
  • Native Chat Support: Built-in chat message handling
  • Rapid Prototyping: Get beautiful UI in minutes
  • Session Management: Built-in session state handling
  • Live Updates: Auto-refresh and real-time updates

🎯 Perfect for RAG Applications:

  • Chat interfaces are first-class citizens
  • Easy data visualization and status display
  • Simple deployment and sharing
  • Great for internal tools and demos

🛠️ Troubleshooting

Common Issues:

  1. Import Error: pip install streamlit
  2. Port Conflict: Change WEB_PORT in .env
  3. Database Connection: Check MongoDB URI
  4. API Limits: Verify Gemini API key

Streamlit-Specific:

  • Browser not opening: Use --server.headless true
  • Port issues: Use --server.port XXXX
  • Performance: Use st.cache_data() for large data

🎨 Customization

Frontend Styling:

  • Edit CSS in frontend/app.py
  • Use st.markdown() with custom CSS
  • Modify color schemes and layouts

Add New Features:

  • File upload for apartment data
  • Charts and visualizations
  • Export conversation history
  • Multi-language support

🚀 Deployment Options

Local Development:

streamlit run frontend/app.py

Streamlit Cloud:

  • Push to GitHub
  • Connect repository to Streamlit Cloud
  • Deploy with one click

About

A modern Retrieval-Augmented Generation (RAG) chatbot for apartment rentals. Features a beautiful Streamlit web interface and a terminal chat mode. Supports real-time property search, pricing info, and conversation history using ChromaDB, MongoDB, and Gemini AI. Easy to set up, extensible, and perfect for demos or production use.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages