#!/bin/bash
# Setup script for Hybrid RAG Project
# This script automates the installation process
set -e # Exit on error
echo "π Hybrid RAG Project Setup"
echo "=========================="
echo ""
# Check Python version
echo "π Checking Python version..."
if ! command -v python3 &> /dev/null; then
echo "β Python 3 is not installed. Please install Python 3.9 or higher."
exit 1
fi
PYTHON_VERSION=$(python3 --version | cut -d' ' -f2 | cut -d'.' -f1,2)
echo "β
Found Python $PYTHON_VERSION"
# Check if Ollama is installed
echo ""
echo "π Checking Ollama installation..."
if ! command -v ollama &> /dev/null; then
echo "β οΈ Ollama is not installed."
echo "π Please install Ollama from: https://ollama.ai"
echo " After installation, run this script again."
exit 1
fi
echo "β
Ollama is installed"
# Check if Ollama is running
echo ""
echo "π Checking if Ollama is running..."
if ! curl -s http://localhost:11434/api/tags > /dev/null 2>&1; then
echo "β οΈ Ollama is not running."
echo "π Please start Ollama and run this script again."
exit 1
fi
echo "β
Ollama is running"
# Check for required models
echo ""
echo "π Checking Ollama models..."
MODELS=$(curl -s http://localhost:11434/api/tags | python3 -c "import sys, json; data = json.load(sys.stdin); print(' '.join([m['name'] for m in data.get('models', [])]))" 2>/dev/null || echo "")
if [[ ! "$MODELS" =~ "nomic-embed-text" ]]; then
echo "β οΈ Model 'nomic-embed-text' not found."
echo "π₯ Pulling nomic-embed-text model..."
ollama pull nomic-embed-text
else
echo "β
Found nomic-embed-text model"
fi
if [[ ! "$MODELS" =~ "llama3.1" ]]; then
echo "β οΈ Model 'llama3.1' not found."
echo "π₯ Pulling llama3.1:latest model..."
ollama pull llama3.1:latest
else
echo "β
Found llama3.1 model"
fi
# Create virtual environment
echo ""
echo "π¦ Creating virtual environment..."
if [ -d ".venv" ]; then
echo "β οΈ Virtual environment already exists. Skipping creation."
else
python3 -m venv .venv
echo "β
Virtual environment created"
fi
# Activate virtual environment
echo ""
echo "π Activating virtual environment..."
source .venv/bin/activate
# Upgrade pip
echo ""
echo "π¦ Upgrading pip..."
pip install --upgrade pip -q
# Install dependencies
echo ""
echo "π¦ Installing dependencies..."
pip install -r requirements.txt -q
echo "β
Dependencies installed"
# Create necessary directories
echo ""
echo "π Creating necessary directories..."
mkdir -p data
mkdir -p chroma_db
echo "β
Directories created"
# Test the setup
echo ""
echo "π§ͺ Testing the setup..."
python3 -c "
import sys
sys.path.insert(0, '.')
from src.hybrid_rag import DocumentLoaderUtility, StructuredQueryEngine, configure_logging
print('β
All modules import successfully')
" 2>&1 | grep -v "WARNING" | grep -v "init:" | grep -v "level=WARN" || echo "β
Imports successful"
echo ""
echo "β
Setup complete!"
echo ""
echo "=========================="
echo "π You're ready to use the Hybrid RAG system!"
echo ""
echo "π Next steps:"
echo " 1. Add your documents to the 'data/' directory"
echo " 2. Run the demo: python scripts/run_demo.py"
echo " 3. Or start the REST API: python scripts/mcp_server.py"
echo " 4. Or configure Claude Desktop to use the MCP server"
echo ""
echo "π Documentation:"
echo " - README.md - Complete guide"
echo " - docs/INSTALLATION.md - Detailed installation instructions"
echo " - docs/STRUCTURED_QUERIES.md - How to query CSV data"
echo " - docs/ASYNC_INGESTION.md - Async ingestion guide"
echo ""
echo "π‘ Quick test: python scripts/run_demo.py"
echo ""