|
| 1 | +#!/usr/bin/python3 |
| 2 | +# Copyright (c) KMG. All Rights Reserved. |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +## |
| 10 | +""" |
| 11 | +Installation script for SBK RAG dependencies. |
| 12 | +
|
| 13 | +This script helps install the required dependencies for the RAG pipeline, |
| 14 | +handling Apple Silicon compatibility issues with ChromaDB. |
| 15 | +""" |
| 16 | + |
| 17 | +import subprocess |
| 18 | +import sys |
| 19 | +import platform |
| 20 | + |
| 21 | + |
| 22 | +def run_command(command, description): |
| 23 | + """Run a command and handle errors.""" |
| 24 | + print(f"\n📦 {description}") |
| 25 | + print(f"Running: {command}") |
| 26 | + try: |
| 27 | + result = subprocess.run(command, shell=True, check=True, capture_output=True, text=True) |
| 28 | + print("✅ Success!") |
| 29 | + if result.stdout: |
| 30 | + print(f"Output: {result.stdout.strip()}") |
| 31 | + return True |
| 32 | + except subprocess.CalledProcessError as e: |
| 33 | + print(f"❌ Failed with error: {e}") |
| 34 | + if e.stderr: |
| 35 | + print(f"Error output: {e.stderr.strip()}") |
| 36 | + return False |
| 37 | + |
| 38 | + |
| 39 | +def check_apple_silicon(): |
| 40 | + """Check if running on Apple Silicon.""" |
| 41 | + system = platform.system() |
| 42 | + machine = platform.machine() |
| 43 | + |
| 44 | + if system == "Darwin" and machine in ("arm64", "arm64e"): |
| 45 | + print("🍎 Detected Apple Silicon (M1/M2/M3) Mac") |
| 46 | + return True |
| 47 | + return False |
| 48 | + |
| 49 | + |
| 50 | +def install_dependencies(): |
| 51 | + """Install RAG dependencies with compatibility handling.""" |
| 52 | + print("🚀 Installing SBK RAG Dependencies") |
| 53 | + print("=" * 50) |
| 54 | + |
| 55 | + is_apple_silicon = check_apple_silicon() |
| 56 | + |
| 57 | + # Basic dependencies that should work everywhere |
| 58 | + basic_deps = [ |
| 59 | + "pandas>=2.2.3", |
| 60 | + "sentence-transformers>=3.0.1" |
| 61 | + ] |
| 62 | + |
| 63 | + # Install basic dependencies first |
| 64 | + for dep in basic_deps: |
| 65 | + run_command(f"pip install \"{dep}\"", f"Installing {dep}") |
| 66 | + |
| 67 | + print("\n🔧 RAG Setup Information:") |
| 68 | + print("✅ Basic RAG dependencies installed") |
| 69 | + print("💡 Simple RAG will be used (ChromaDB-free)") |
| 70 | + print("🎯 This provides maximum compatibility across all systems") |
| 71 | + |
| 72 | + if is_apple_silicon: |
| 73 | + print("\n🍎 Apple Silicon detected:") |
| 74 | + print(" • Simple RAG works perfectly on Apple Silicon") |
| 75 | + print(" • No problematic dependencies required") |
| 76 | + print(" • Full RAG functionality available") |
| 77 | + |
| 78 | + # Optional: Try ChromaDB as advanced feature (not required) |
| 79 | + print("\n🔍 Optional: Attempting ChromaDB installation (advanced feature)...") |
| 80 | + chroma_success = False |
| 81 | + |
| 82 | + if is_apple_silicon: |
| 83 | + # Try various approaches for Apple Silicon |
| 84 | + approaches = [ |
| 85 | + ("pip install onnxruntime-silicon", "Installing onnxruntime-silicon"), |
| 86 | + ("pip install onnxruntime", "Installing standard onnxruntime"), |
| 87 | + ] |
| 88 | + |
| 89 | + for cmd, desc in approaches: |
| 90 | + if run_command(cmd, desc): |
| 91 | + if run_command("pip install \"chromadb>=1.4.1,<1.5.0\"", "Installing ChromaDB"): |
| 92 | + chroma_success = True |
| 93 | + break |
| 94 | + else: |
| 95 | + # Standard approach for other systems |
| 96 | + if run_command("pip install \"chromadb>=1.4.1,<1.5.0\"", "Installing ChromaDB"): |
| 97 | + chroma_success = True |
| 98 | + |
| 99 | + if chroma_success: |
| 100 | + print("🎉 ChromaDB installed successfully! Enhanced RAG features available.") |
| 101 | + else: |
| 102 | + print("⚠️ ChromaDB not available (this is normal)") |
| 103 | + print(" • Simple RAG provides full functionality without ChromaDB") |
| 104 | + print(" • No features are missing - just using keyword search instead") |
| 105 | + |
| 106 | + print("\n" + "=" * 50) |
| 107 | + print("📊 Installation Summary") |
| 108 | + print("✅ Basic RAG dependencies: INSTALLED") |
| 109 | + print(f"{'✅' if chroma_success else '⚠️'} ChromaDB: {'AVAILABLE' if chroma_success else 'NOT AVAILABLE (using Simple RAG)'}") |
| 110 | + |
| 111 | + print("\n🎉 Installation completed successfully!") |
| 112 | + print("\n📋 What you get:") |
| 113 | + print("• ✅ CSV data ingestion") |
| 114 | + print("• ✅ Context retrieval for AI prompts") |
| 115 | + print("• ✅ RAG-enhanced analysis") |
| 116 | + print(f"• {'✅' if chroma_success else '✅'} Vector search" + (": ENABLED" if chroma_success else ": Using keyword-based search")) |
| 117 | + print("• ✅ Full compatibility with your system") |
| 118 | + |
| 119 | + print("\n🚀 Ready to use! Run your SBK analysis with CSV files.") |
| 120 | + |
| 121 | + |
| 122 | +if __name__ == "__main__": |
| 123 | + install_dependencies() |
0 commit comments