Skip to content

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

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

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages