{"repo": "areeb297/document-search-app", "files": {".env": {"3ad41fbae234e529a8484c058e00bfc476234ab0": {"t": 1785745113.9270043, "n": 831, "h": "ded3d9c055f35b31", "c": "OPENAI_API_KEY=\"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\"\nLANGCHAIN_API_KEY=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\nLANGCHAIN_TRACING_V2=true\nLANGCHAIN_PROJECT=\"Onasi Helper API\"\nGROQ_API_KEY=\"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\"\nHUGGINGFACEHUB_API_TOKEN=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\nGOOGLE_API_KEY=AIzaSyC9oaMyY663q1od00Mwo4oLDdc_mzCtXyg\n\n\n\nSQL_SERVER_DRIVER={ODBC Driver 17 for SQL Server}\nSQL_SERVER_SERVER=areeb-server.database.windows.net\nSQL_SERVER_DATABASE=document_search_app\nSQL_SERVER_UID=areeb_admin\nSQL_SERVER_PWD=Nightingale@098\nSQL_SERVER_TRUSTED_CONNECTION=yes\n\nDEEPSEEK_KEY=\"sk-e7da2c49b9f9412da305659f29c95979\"\n\n\nBACKEND_URL=http://127.0.0.1:7860\n\n"}, "cb6c34ef18adaaf5f8ed91058c2a11c0ff7886d2": {"t": 1785747854.4970665, "n": 831, "h": "ded3d9c055f35b31", "c": "OPENAI_API_KEY=\"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\"\nLANGCHAIN_API_KEY=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\nLANGCHAIN_TRACING_V2=true\nLANGCHAIN_PROJECT=\"Onasi Helper API\"\nGROQ_API_KEY=\"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\"\nHUGGINGFACEHUB_API_TOKEN=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\nGOOGLE_API_KEY=AIzaSyC9oaMyY663q1od00Mwo4oLDdc_mzCtXyg\n\n\n\nSQL_SERVER_DRIVER={ODBC Driver 17 for SQL Server}\nSQL_SERVER_SERVER=areeb-server.database.windows.net\nSQL_SERVER_DATABASE=document_search_app\nSQL_SERVER_UID=areeb_admin\nSQL_SERVER_PWD=Nightingale@098\nSQL_SERVER_TRUSTED_CONNECTION=yes\n\nDEEPSEEK_KEY=\"sk-e7da2c49b9f9412da305659f29c95979\"\n\n\nBACKEND_URL=http://127.0.0.1:7860\n\n"}, "ea54555839e027afa6e1d92fd32a07c6ddfbd511": {"t": 1785747855.5708623, "n": 1728, "h": "e7d07e2878f2ddb5", "c": "OPENAI_API_KEY=\"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\"\nLANGCHAIN_API_KEY=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\nLANGCHAIN_TRACING_V2=true\nLANGCHAIN_PROJECT=\"Onasi Helper API\"\nGROQ_API_KEY=\"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\"\nHUGGINGFACEHUB_API_TOKEN=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\nGOOGLE_API_KEY=AIzaSyC9oaMyY663q1od00Mwo4oLDdc_mzCtXyg\nPINECONE_API_KEY=pcsk_5fPbVN_2WaRajU7h1XxiC2bR4SuSi2VGGKson5DeAipFuCff5g91AaC1G4tzizF8HUTRGb\nPINECONE_ENV=\"eu-west-1\"\n# GitHub Repository Info\n# GITHUB_TOKEN = \"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\" # Replace with your token\n# REPO_OWNER = \"Areeb-acs\" # Replace with your GitHub username\n# REPO_NAME = \"Onasi-Helper-Bot\" # Replace with your repo name\n# FILE_PATH = \"conversations.txt\" # Path to your file in the repo\n# BRANCH = \"main\" # Branch where the file is located \n# SERVER_NAME = \"ACS-NHTC-02\"\n# DATABASE_NAME = \"NphiesIntegrationDB_New\"\n# USERNAME = \"sa\"\n# PASSWORD = \"hts@6789\" \n# SERVER_NAME=\"ACS-NHTC-02\"\n# DATABASE_NAME=\"NphiesIntegrationDB_New\"\n# DB_USERNAME=\"sa\"\n# DB_PASSWORD=\"hts@6789\"\n# SERVER_NAME = \"localhost\\SQLEXPRESS\"\n# DATABASE_NAME = \"AreebBlogDB\"\n\nSQL_SERVER_DRIVER={ODBC Driver 17 for SQL Server}\nSQL_SERVER_SERVER=areeb-server.database.windows.net\nSQL_SERVER_DATABASE=document_search_app\nSQL_SERVER_UID=areeb_admin\nSQL_SERVER_PWD=Nightingale@098\nSQL_SERVER_TRUSTED_CONNECTION=yes\n\nDEEPSEEK_KEY=\"sk-e7da2c49b9f9412da305659f29c95979\"\n\n\n\n# GITHUB_TOKEN=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\n# REPO_OWNER=Areeb-acs\n# REPO_NAME=Onasi-Helper-Bot\n# FILE_PATH=conversations.txt\n# BRANCH=main"}, "3137e9876c1bd45b612a14c08828dc2dc1134afe": {"t": 1785747856.708429, "n": 1599, "h": "21201e9a40b516ed", "c": "OPENAI_API_KEY=\"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\"\nLANGCHAIN_API_KEY=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\nLANGCHAIN_TRACING_V2=true\nLANGCHAIN_PROJECT=\"Onasi Helper API\"\nGROQ_API_KEY=\"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\"\nHUGGINGFACEHUB_API_TOKEN=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\nGOOGLE_API_KEY=AIzaSyC9oaMyY663q1od00Mwo4oLDdc_mzCtXyg\nPINECONE_API_KEY=pcsk_5fPbVN_2WaRajU7h1XxiC2bR4SuSi2VGGKson5DeAipFuCff5g91AaC1G4tzizF8HUTRGb\nPINECONE_ENV=\"eu-west-1\"\n# GitHub Repository Info\n# GITHUB_TOKEN = \"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\" # Replace with your token\n# REPO_OWNER = \"Areeb-acs\" # Replace with your GitHub username\n# REPO_NAME = \"Onasi-Helper-Bot\" # Replace with your repo name\n# FILE_PATH = \"conversations.txt\" # Path to your file in the repo\n# BRANCH = \"main\" # Branch where the file is located \n# SERVER_NAME = \"ACS-NHTC-02\"\n# DATABASE_NAME = \"NphiesIntegrationDB_New\"\n# USERNAME = \"sa\"\n# PASSWORD = \"hts@6789\" \n# SERVER_NAME=\"ACS-NHTC-02\"\n# DATABASE_NAME=\"NphiesIntegrationDB_New\"\n# DB_USERNAME=\"sa\"\n# DB_PASSWORD=\"hts@6789\"\n# SERVER_NAME = \"localhost\\SQLEXPRESS\"\n# DATABASE_NAME = \"AreebBlogDB\"\n\nSERVER_NAME=\"ACS-NHTC-02\"\nDATABASE_NAME=\"NphiesIntegrationDB_New\"\nDB_USERNAME=\"sa\"\nDB_PASSWORD=\"hts@6789\"\nDEEPSEEK_KEY=\"sk-e7da2c49b9f9412da305659f29c95979\"\n\n\n\n# GITHUB_TOKEN=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\n# REPO_OWNER=Areeb-acs\n# REPO_NAME=Onasi-Helper-Bot\n# FILE_PATH=conversations.txt\n# BRANCH=main"}, "1fdc2c20bc8f69bf45e870bb236fc207ef5b3e6b": {"t": 1785747857.800444, "n": 1548, "h": "3dc94efcef2c5cc3", "c": "OPENAI_API_KEY=\"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\"\nLANGCHAIN_API_KEY=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\nLANGCHAIN_TRACING_V2=true\nLANGCHAIN_PROJECT=\"Onasi Helper API\"\nGROQ_API_KEY=\"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\"\nHUGGINGFACEHUB_API_TOKEN=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\nGOOGLE_API_KEY=AIzaSyC9oaMyY663q1od00Mwo4oLDdc_mzCtXyg\nPINECONE_API_KEY=pcsk_5fPbVN_2WaRajU7h1XxiC2bR4SuSi2VGGKson5DeAipFuCff5g91AaC1G4tzizF8HUTRGb\nPINECONE_ENV=\"eu-west-1\"\n# GitHub Repository Info\n# GITHUB_TOKEN = \"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\" # Replace with your token\n# REPO_OWNER = \"Areeb-acs\" # Replace with your GitHub username\n# REPO_NAME = \"Onasi-Helper-Bot\" # Replace with your repo name\n# FILE_PATH = \"conversations.txt\" # Path to your file in the repo\n# BRANCH = \"main\" # Branch where the file is located \n# SERVER_NAME = \"ACS-NHTC-02\"\n# DATABASE_NAME = \"NphiesIntegrationDB_New\"\n# USERNAME = \"sa\"\n# PASSWORD = \"hts@6789\" \n# SERVER_NAME=\"ACS-NHTC-02\"\n# DATABASE_NAME=\"NphiesIntegrationDB_New\"\n# DB_USERNAME=\"sa\"\n# DB_PASSWORD=\"hts@6789\"\n# SERVER_NAME = \"localhost\\SQLEXPRESS\"\n# DATABASE_NAME = \"AreebBlogDB\"\n\nSERVER_NAME=\"ACS-NHTC-02\"\nDATABASE_NAME=\"NphiesIntegrationDB_New\"\nDB_USERNAME=\"sa\"\nDB_PASSWORD=\"hts@6789\"\n\n\n\n# GITHUB_TOKEN=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\n# REPO_OWNER=Areeb-acs\n# REPO_NAME=Onasi-Helper-Bot\n# FILE_PATH=conversations.txt\n# BRANCH=main"}}, "INSTALLATION.md": {"3ad41fbae234e529a8484c058e00bfc476234ab0": {"t": 1785746624.5660214, "n": 14383, "h": "b3c145238b1765ec", "c": "# Installation Guide\n\nThis guide provides step-by-step instructions for installing and setting up the Document Search Application.\n\n## ๐Ÿ“‹ Prerequisites\n\n### System Requirements\n\n- **Operating System**: Windows 10+, macOS 10.15+, or Linux (Ubuntu 18.04+)\n- **Python**: Version 3.8 or higher\n- **Memory**: Minimum 4GB RAM (8GB recommended)\n- **Storage**: At least 2GB free space for application and indexes\n- **Network**: Internet connection for AI API calls\n\n### Required Services\n\n1. **SQL Server Database**\n - Azure SQL Database (recommended for production)\n - SQL Server Express (for development)\n - Or any SQL Server-compatible database\n\n2. **AI API Keys**\n - Groq API key (for Llama 3 70B model)\n - DeepSeek API key (for DeepSeek Chat model)\n - OpenAI API key (for embeddings)\n\n## ๐Ÿš€ Installation Methods\n\n### Method 1: Standard Installation (Recommended)\n\n#### Step 1: Clone the Repository\n\n```bash\n# Clone the repository\ngit clone https://github.com/your-username/document-search-app.git\ncd document-search-app\n\n# Or download and extract the ZIP file\nwget https://github.com/your-username/document-search-app/archive/main.zip\nunzip main.zip\ncd document-search-app-main\n```\n\n#### Step 2: Set Up Python Environment\n\n**Using venv (Recommended):**\n```bash\n# Create virtual environment\npython -m venv document-search-env\n\n# Activate virtual environment\n# On Windows:\ndocument-search-env\\Scripts\\activate\n# On macOS/Linux:\nsource document-search-env/bin/activate\n```\n\n**Using conda:**\n```bash\n# Create conda environment\nconda create -n document-search python=3.11\nconda activate document-search\n```\n\n#### Step 3: Install Dependencies\n\n```bash\n# Upgrade pip\npip install --upgrade pip\n\n# Install requirements\npip install -r requirements.txt\n\n# Verify installation\npip list\n```\n\n**Common Installation Issues:**\n```bash\n# If you encounter issues with FAISS on Windows:\npip install faiss-cpu --no-cache-dir\n\n# If you have issues with python-tds:\npip install python-tds --upgrade\n\n# For Apple Silicon Macs:\npip install --upgrade --force-reinstall faiss-cpu\n```\n\n#### Step 4: Set Up Environment Variables\n\nCreate a `.env` file in the project root:\n\n```bash\n# Copy the example file\ncp .env.example .env\n\n# Edit the file with your configuration\nnano .env # or use your preferred editor\n```\n\n**Required Environment Variables:**\n```env\n# Database Configuration (Azure SQL Database example)\nSQL_SERVER_SERVER=your-server.database.windows.net\nSQL_SERVER_DATABASE=your-database-name\nSQL_SERVER_UID=your-username\nSQL_SERVER_PWD=your-password\nSQL_SERVER_PORT=1433\n\n# AI API Keys\nGROQ_API_KEY=gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nDEEPSEEK_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nOPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n# Security\nJWT_SECRET_KEY=your-very-long-and-random-secret-key-here\n\n# Application Settings\nDEPLOYMENT_ENV=development\nEMBEDDING_PROVIDER=openai\nPORT=7860\n```\n\n#### Step 5: Set Up the Database\n\n**Option A: Using Azure SQL Database (Recommended for Production)**\n\n1. Create an Azure SQL Database\n2. Connect to the database using Azure Data Studio or SQL Server Management Studio\n3. Run the following SQL script:\n\n```sql\n-- Create users table\nCREATE TABLE dbo.users (\n id INT IDENTITY(1,1) PRIMARY KEY,\n email NVARCHAR(255) UNIQUE NOT NULL,\n password NVARCHAR(255) NOT NULL,\n name NVARCHAR(255) NOT NULL,\n role NVARCHAR(50) DEFAULT 'user',\n created_at DATETIME2 DEFAULT GETUTCDATE(),\n updated_at DATETIME2 DEFAULT GETUTCDATE()\n);\n\n-- Create index for faster lookups\nCREATE INDEX IX_users_email ON dbo.users(email);\n\n-- Verify table creation\nSELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'users';\n```\n\n**Option B: Using SQL Server Express (Development)**\n\n1. Download and install SQL Server Express\n2. Install SQL Server Management Studio (SSMS)\n3. Create a new database\n4. Run the SQL script above\n\n#### Step 6: Install NLTK Data (Optional)\n\n```bash\n# Run the NLTK data download script\npython download_nltk.py\n```\n\n#### Step 7: Test the Installation\n\n```bash\n# Test database connection\npython -c \"\nfrom db_utils import get_db_connection\nwith get_db_connection() as conn:\n print('Database connection: Success' if conn else 'Database connection: Failed')\n\"\n\n# Test AI API keys\npython -c \"\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\nprint('Groq API Key:', 'Loaded' if os.getenv('GROQ_API_KEY') else 'Missing')\nprint('DeepSeek API Key:', 'Loaded' if os.getenv('DEEPSEEK_KEY') else 'Missing')\nprint('OpenAI API Key:', 'Loaded' if os.getenv('OPENAI_API_KEY') else 'Missing')\n\"\n```\n\n#### Step 8: Run the Application\n\n```bash\n# Start the application\npython main.py\n\n# Or with specific host/port\npython main.py --host 0.0.0.0 --port 7860\n```\n\nThe application should now be running at `http://localhost:7860`\n\n---\n\n### Method 2: Docker Installation\n\n#### Prerequisites\n- Docker Desktop installed\n- Docker Compose installed\n\n#### Step 1: Create Docker Files\n\n**Dockerfile:**\n```dockerfile\nFROM python:3.11-slim\n\n# Set working directory\nWORKDIR /app\n\n# Install system dependencies\nRUN apt-get update && apt-get install -y \\\n gcc \\\n g++ \\\n && rm -rf /var/lib/apt/lists/*\n\n# Copy requirements first for better caching\nCOPY requirements.txt .\n\n# Install Python dependencies\nRUN pip install --no-cache-dir -r requirements.txt\n\n# Copy application code\nCOPY . .\n\n# Create storage directory\nRUN mkdir -p storage_faiss\n\n# Expose port\nEXPOSE 7860\n\n# Run the application\nCMD [\"python\", \"main.py\"]\n```\n\n**docker-compose.yml:**\n```yaml\nversion: '3.8'\n\nservices:\n document-search:\n build: .\n ports:\n - \"7860:7860\"\n environment:\n - SQL_SERVER_SERVER=${SQL_SERVER_SERVER}\n - SQL_SERVER_DATABASE=${SQL_SERVER_DATABASE}\n - SQL_SERVER_UID=${SQL_SERVER_UID}\n - SQL_SERVER_PWD=${SQL_SERVER_PWD}\n - GROQ_API_KEY=${GROQ_API_KEY}\n - DEEPSEEK_KEY=${DEEPSEEK_KEY}\n - OPENAI_API_KEY=${OPENAI_API_KEY}\n - JWT_SECRET_KEY=${JWT_SECRET_KEY}\n volumes:\n - ./storage_faiss:/app/storage_faiss\n env_file:\n - .env\n```\n\n#### Step 2: Build and Run\n\n```bash\n# Build the Docker image\ndocker-compose build\n\n# Run the application\ndocker-compose up -d\n\n# View logs\ndocker-compose logs -f\n\n# Stop the application\ndocker-compose down\n```\n\n---\n\n## ๐Ÿ”ง Configuration\n\n### API Key Setup\n\n#### 1. Groq API Key\n\n1. Visit [Groq Console](https://console.groq.com/)\n2. Sign up or log in\n3. Navigate to API Keys section\n4. Create a new API key\n5. Copy the key and add to your `.env` file\n\n#### 2. DeepSeek API Key\n\n1. Visit [DeepSeek Platform](https://platform.deepseek.com/)\n2. Register for an account\n3. Go to API section\n4. Generate an API key\n5. Copy the key and add to your `.env` file\n\n#### 3. OpenAI API Key\n\n1. Visit [OpenAI Platform](https://platform.openai.com/)\n2. Sign up or log in\n3. Go to API Keys section\n4. Create a new secret key\n5. Copy the key and add to your `.env` file\n\n### Database Setup Options\n\n#### Azure SQL Database (Production)\n\n1. **Create Azure SQL Database:**\n ```bash\n # Using Azure CLI\n az sql server create --name your-server --resource-group your-rg --admin-user your-admin --admin-password your-password\n az sql db create --server your-server --resource-group your-rg --name your-database --edition Basic\n ```\n\n2. **Configure Firewall:**\n ```bash\n # Allow your IP\n az sql server firewall-rule create --server your-server --resource-group your-rg --name AllowMyIP --start-ip-address YOUR_IP --end-ip-address YOUR_IP\n ```\n\n3. **Connection String:**\n ```\n Server: your-server.database.windows.net\n Database: your-database\n Port: 1433\n Authentication: SQL Authentication\n ```\n\n#### Local SQL Server Express\n\n1. **Download and Install:**\n - Download SQL Server Express from Microsoft\n - Install with default settings\n - Enable TCP/IP connections\n\n2. **Create Database:**\n ```sql\n CREATE DATABASE DocumentSearchDB;\n USE DocumentSearchDB;\n -- Run the users table creation script\n ```\n\n### SSL/TLS Configuration\n\nFor production deployment, enable HTTPS:\n\n```python\n# In main.py, add SSL configuration\nif __name__ == \"__main__\":\n uvicorn.run(\n \"main:app\", \n host=\"0.0.0.0\", \n port=port,\n ssl_keyfile=\"path/to/private.key\",\n ssl_certfile=\"path/to/certificate.crt\"\n )\n```\n\n---\n\n## ๐Ÿงช Testing the Installation\n\n### Basic Functionality Test\n\n```bash\n# Test 1: Database Connection\npython -c \"\nfrom db_utils import get_db_connection\nwith get_db_connection() as conn:\n if conn:\n print('โœ… Database connection successful')\n cursor = conn.cursor()\n cursor.execute('SELECT 1')\n result = cursor.fetchone()\n print(f'โœ… Database query successful: {result}')\n else:\n print('โŒ Database connection failed')\n\"\n\n# Test 2: AI API Keys\npython -c \"\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\n\nkeys = {\n 'Groq': os.getenv('GROQ_API_KEY'),\n 'DeepSeek': os.getenv('DEEPSEEK_KEY'),\n 'OpenAI': os.getenv('OPENAI_API_KEY')\n}\n\nfor name, key in keys.items():\n status = 'โœ…' if key else 'โŒ'\n print(f'{status} {name} API Key: {\\\"Loaded\\\" if key else \\\"Missing\\\"}')\n\"\n\n# Test 3: RAG Engine Initialization\npython -c \"\nfrom rag_engine import RAGEngine\ntry:\n engine = RAGEngine()\n print('โœ… RAG Engine initialized successfully')\n print(f'โœ… Active LLM: {engine.active_llm_type}')\nexcept Exception as e:\n print(f'โŒ RAG Engine initialization failed: {e}')\n\"\n```\n\n### Web Interface Test\n\n1. Start the application: `python main.py`\n2. Open browser to `http://localhost:7860`\n3. Test login/signup functionality\n4. Upload a test document\n5. Try querying the document\n\n---\n\n## ๐Ÿ” Troubleshooting\n\n### Common Issues\n\n#### 1. Database Connection Issues\n\n**Problem:** Cannot connect to SQL Server\n```\nDatabase connection error: Login failed for user\n```\n\n**Solutions:**\n```bash\n# Check connection string\npython -c \"\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\nprint('Server:', os.getenv('SQL_SERVER_SERVER'))\nprint('Database:', os.getenv('SQL_SERVER_DATABASE'))\nprint('User:', os.getenv('SQL_SERVER_UID'))\n\"\n\n# Test with sqlcmd (if available)\nsqlcmd -S your-server.database.windows.net -d your-database -U your-user -P your-password -Q \"SELECT 1\"\n\n# Check firewall rules (Azure SQL)\naz sql server firewall-rule list --server your-server --resource-group your-rg\n```\n\n#### 2. Python Package Issues\n\n**Problem:** Import errors or package conflicts\n```\nModuleNotFoundError: No module named 'xxx'\n```\n\n**Solutions:**\n```bash\n# Reinstall requirements\npip uninstall -r requirements.txt -y\npip install -r requirements.txt\n\n# Clear pip cache\npip cache purge\n\n# Use fresh virtual environment\ndeactivate\nrm -rf document-search-env\npython -m venv document-search-env\nsource document-search-env/bin/activate # or activate.bat on Windows\npip install -r requirements.txt\n```\n\n#### 3. API Key Issues\n\n**Problem:** AI API calls failing\n```\nError: Invalid API key\n```\n\n**Solutions:**\n```bash\n# Verify API keys are loaded\npython -c \"\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\nfor key in ['GROQ_API_KEY', 'DEEPSEEK_KEY', 'OPENAI_API_KEY']:\n value = os.getenv(key)\n print(f'{key}: {value[:10]}...{value[-4:] if value else \\\"Not found\\\"}')\n\"\n\n# Test API keys directly\ncurl -H \"Authorization: Bearer $GROQ_API_KEY\" https://api.groq.com/v1/models\n```\n\n#### 4. Port Already in Use\n\n**Problem:** Port 7860 is already in use\n```\nOSError: [Errno 48] Address already in use\n```\n\n**Solutions:**\n```bash\n# Find process using the port\nlsof -i :7860 # macOS/Linux\nnetstat -ano | findstr :7860 # Windows\n\n# Kill the process\nkill -9 # macOS/Linux\ntaskkill /PID /F # Windows\n\n# Or use a different port\npython main.py --port 8080\n```\n\n#### 5. FAISS Installation Issues\n\n**Problem:** FAISS installation fails\n```\nERROR: Failed building wheel for faiss-cpu\n```\n\n**Solutions:**\n```bash\n# For Windows\npip install faiss-cpu --no-cache-dir --only-binary=all\n\n# For macOS with Apple Silicon\nconda install -c conda-forge faiss-cpu\n\n# Alternative: use pip with specific version\npip install faiss-cpu==1.7.4\n```\n\n### Getting Help\n\nIf you continue to experience issues:\n\n1. **Check the logs:** Look for error messages in the console output\n2. **Verify configuration:** Double-check your `.env` file\n3. **Test components individually:** Use the test scripts provided\n4. **Check system resources:** Ensure sufficient RAM and disk space\n5. **Update dependencies:** Try updating to the latest package versions\n\nFor additional support:\n- Check the [Troubleshooting Guide](TROUBLESHOOTING.md)\n- Open an issue on GitHub\n- Review the [FAQ section](README.md#faq)\n\n---\n\n## ๐Ÿ”„ Updating the Application\n\n### Regular Updates\n\n```bash\n# Pull latest changes\ngit pull origin main\n\n# Update dependencies\npip install -r requirements.txt --upgrade\n\n# Check for breaking changes\ngit diff HEAD~1 requirements.txt\ngit diff HEAD~1 .env.example\n\n# Restart the application\npython main.py\n```\n\n### Database Migrations\n\nIf database schema changes are required:\n\n```sql\n-- Example migration script\n-- Add new column to users table\nALTER TABLE dbo.users ADD created_at DATETIME2 DEFAULT GETUTCDATE();\nALTER TABLE dbo.users ADD updated_at DATETIME2 DEFAULT GETUTCDATE();\n\n-- Create index for better performance\nCREATE INDEX IX_users_created_at ON dbo.users(created_at);\n```\n\n---\n\n## ๐Ÿ“ˆ Performance Optimization\n\n### Memory Usage\n\n```bash\n# Monitor memory usage\npython -c \"\nimport psutil\nimport os\nprocess = psutil.Process(os.getpid())\nprint(f'Memory usage: {process.memory_info().rss / 1024 / 1024:.2f} MB')\n\"\n```\n\n### Database Optimization\n\n```sql\n-- Create indexes for better performance\nCREATE INDEX IX_users_email ON dbo.users(email);\nCREATE INDEX IX_users_role ON dbo.users(role);\n\n-- Update statistics\nUPDATE STATISTICS dbo.users;\n```\n\n### File Storage\n\n```bash\n# Clean up old FAISS indexes if needed\nls -la storage_faiss/\n# Remove old indexes if disk space is low\n```\n\n---\n\n## โœ… Verification Checklist\n\nAfter installation, verify these components work:\n\n- [ ] Application starts without errors\n- [ ] Database connection is successful\n- [ ] All API keys are loaded\n- [ ] Web interface is accessible\n- [ ] User registration works\n- [ ] User login works\n- [ ] Document upload works\n- [ ] Document indexing works\n- [ ] Query functionality works\n- [ ] LLM switching works\n- [ ] Logout functionality works\n\nCongratulations! Your Document Search Application is now ready to use. ๐ŸŽ‰"}, "744ec922d275fd9cdec5d17cc32e1f84b1d046eb": {"t": 1785747853.2791567, "n": 14383, "h": "b3c145238b1765ec", "c": "# Installation Guide\n\nThis guide provides step-by-step instructions for installing and setting up the Document Search Application.\n\n## ๐Ÿ“‹ Prerequisites\n\n### System Requirements\n\n- **Operating System**: Windows 10+, macOS 10.15+, or Linux (Ubuntu 18.04+)\n- **Python**: Version 3.8 or higher\n- **Memory**: Minimum 4GB RAM (8GB recommended)\n- **Storage**: At least 2GB free space for application and indexes\n- **Network**: Internet connection for AI API calls\n\n### Required Services\n\n1. **SQL Server Database**\n - Azure SQL Database (recommended for production)\n - SQL Server Express (for development)\n - Or any SQL Server-compatible database\n\n2. **AI API Keys**\n - Groq API key (for Llama 3 70B model)\n - DeepSeek API key (for DeepSeek Chat model)\n - OpenAI API key (for embeddings)\n\n## ๐Ÿš€ Installation Methods\n\n### Method 1: Standard Installation (Recommended)\n\n#### Step 1: Clone the Repository\n\n```bash\n# Clone the repository\ngit clone https://github.com/your-username/document-search-app.git\ncd document-search-app\n\n# Or download and extract the ZIP file\nwget https://github.com/your-username/document-search-app/archive/main.zip\nunzip main.zip\ncd document-search-app-main\n```\n\n#### Step 2: Set Up Python Environment\n\n**Using venv (Recommended):**\n```bash\n# Create virtual environment\npython -m venv document-search-env\n\n# Activate virtual environment\n# On Windows:\ndocument-search-env\\Scripts\\activate\n# On macOS/Linux:\nsource document-search-env/bin/activate\n```\n\n**Using conda:**\n```bash\n# Create conda environment\nconda create -n document-search python=3.11\nconda activate document-search\n```\n\n#### Step 3: Install Dependencies\n\n```bash\n# Upgrade pip\npip install --upgrade pip\n\n# Install requirements\npip install -r requirements.txt\n\n# Verify installation\npip list\n```\n\n**Common Installation Issues:**\n```bash\n# If you encounter issues with FAISS on Windows:\npip install faiss-cpu --no-cache-dir\n\n# If you have issues with python-tds:\npip install python-tds --upgrade\n\n# For Apple Silicon Macs:\npip install --upgrade --force-reinstall faiss-cpu\n```\n\n#### Step 4: Set Up Environment Variables\n\nCreate a `.env` file in the project root:\n\n```bash\n# Copy the example file\ncp .env.example .env\n\n# Edit the file with your configuration\nnano .env # or use your preferred editor\n```\n\n**Required Environment Variables:**\n```env\n# Database Configuration (Azure SQL Database example)\nSQL_SERVER_SERVER=your-server.database.windows.net\nSQL_SERVER_DATABASE=your-database-name\nSQL_SERVER_UID=your-username\nSQL_SERVER_PWD=your-password\nSQL_SERVER_PORT=1433\n\n# AI API Keys\nGROQ_API_KEY=gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nDEEPSEEK_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\nOPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\n# Security\nJWT_SECRET_KEY=your-very-long-and-random-secret-key-here\n\n# Application Settings\nDEPLOYMENT_ENV=development\nEMBEDDING_PROVIDER=openai\nPORT=7860\n```\n\n#### Step 5: Set Up the Database\n\n**Option A: Using Azure SQL Database (Recommended for Production)**\n\n1. Create an Azure SQL Database\n2. Connect to the database using Azure Data Studio or SQL Server Management Studio\n3. Run the following SQL script:\n\n```sql\n-- Create users table\nCREATE TABLE dbo.users (\n id INT IDENTITY(1,1) PRIMARY KEY,\n email NVARCHAR(255) UNIQUE NOT NULL,\n password NVARCHAR(255) NOT NULL,\n name NVARCHAR(255) NOT NULL,\n role NVARCHAR(50) DEFAULT 'user',\n created_at DATETIME2 DEFAULT GETUTCDATE(),\n updated_at DATETIME2 DEFAULT GETUTCDATE()\n);\n\n-- Create index for faster lookups\nCREATE INDEX IX_users_email ON dbo.users(email);\n\n-- Verify table creation\nSELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = 'users';\n```\n\n**Option B: Using SQL Server Express (Development)**\n\n1. Download and install SQL Server Express\n2. Install SQL Server Management Studio (SSMS)\n3. Create a new database\n4. Run the SQL script above\n\n#### Step 6: Install NLTK Data (Optional)\n\n```bash\n# Run the NLTK data download script\npython download_nltk.py\n```\n\n#### Step 7: Test the Installation\n\n```bash\n# Test database connection\npython -c \"\nfrom db_utils import get_db_connection\nwith get_db_connection() as conn:\n print('Database connection: Success' if conn else 'Database connection: Failed')\n\"\n\n# Test AI API keys\npython -c \"\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\nprint('Groq API Key:', 'Loaded' if os.getenv('GROQ_API_KEY') else 'Missing')\nprint('DeepSeek API Key:', 'Loaded' if os.getenv('DEEPSEEK_KEY') else 'Missing')\nprint('OpenAI API Key:', 'Loaded' if os.getenv('OPENAI_API_KEY') else 'Missing')\n\"\n```\n\n#### Step 8: Run the Application\n\n```bash\n# Start the application\npython main.py\n\n# Or with specific host/port\npython main.py --host 0.0.0.0 --port 7860\n```\n\nThe application should now be running at `http://localhost:7860`\n\n---\n\n### Method 2: Docker Installation\n\n#### Prerequisites\n- Docker Desktop installed\n- Docker Compose installed\n\n#### Step 1: Create Docker Files\n\n**Dockerfile:**\n```dockerfile\nFROM python:3.11-slim\n\n# Set working directory\nWORKDIR /app\n\n# Install system dependencies\nRUN apt-get update && apt-get install -y \\\n gcc \\\n g++ \\\n && rm -rf /var/lib/apt/lists/*\n\n# Copy requirements first for better caching\nCOPY requirements.txt .\n\n# Install Python dependencies\nRUN pip install --no-cache-dir -r requirements.txt\n\n# Copy application code\nCOPY . .\n\n# Create storage directory\nRUN mkdir -p storage_faiss\n\n# Expose port\nEXPOSE 7860\n\n# Run the application\nCMD [\"python\", \"main.py\"]\n```\n\n**docker-compose.yml:**\n```yaml\nversion: '3.8'\n\nservices:\n document-search:\n build: .\n ports:\n - \"7860:7860\"\n environment:\n - SQL_SERVER_SERVER=${SQL_SERVER_SERVER}\n - SQL_SERVER_DATABASE=${SQL_SERVER_DATABASE}\n - SQL_SERVER_UID=${SQL_SERVER_UID}\n - SQL_SERVER_PWD=${SQL_SERVER_PWD}\n - GROQ_API_KEY=${GROQ_API_KEY}\n - DEEPSEEK_KEY=${DEEPSEEK_KEY}\n - OPENAI_API_KEY=${OPENAI_API_KEY}\n - JWT_SECRET_KEY=${JWT_SECRET_KEY}\n volumes:\n - ./storage_faiss:/app/storage_faiss\n env_file:\n - .env\n```\n\n#### Step 2: Build and Run\n\n```bash\n# Build the Docker image\ndocker-compose build\n\n# Run the application\ndocker-compose up -d\n\n# View logs\ndocker-compose logs -f\n\n# Stop the application\ndocker-compose down\n```\n\n---\n\n## ๐Ÿ”ง Configuration\n\n### API Key Setup\n\n#### 1. Groq API Key\n\n1. Visit [Groq Console](https://console.groq.com/)\n2. Sign up or log in\n3. Navigate to API Keys section\n4. Create a new API key\n5. Copy the key and add to your `.env` file\n\n#### 2. DeepSeek API Key\n\n1. Visit [DeepSeek Platform](https://platform.deepseek.com/)\n2. Register for an account\n3. Go to API section\n4. Generate an API key\n5. Copy the key and add to your `.env` file\n\n#### 3. OpenAI API Key\n\n1. Visit [OpenAI Platform](https://platform.openai.com/)\n2. Sign up or log in\n3. Go to API Keys section\n4. Create a new secret key\n5. Copy the key and add to your `.env` file\n\n### Database Setup Options\n\n#### Azure SQL Database (Production)\n\n1. **Create Azure SQL Database:**\n ```bash\n # Using Azure CLI\n az sql server create --name your-server --resource-group your-rg --admin-user your-admin --admin-password your-password\n az sql db create --server your-server --resource-group your-rg --name your-database --edition Basic\n ```\n\n2. **Configure Firewall:**\n ```bash\n # Allow your IP\n az sql server firewall-rule create --server your-server --resource-group your-rg --name AllowMyIP --start-ip-address YOUR_IP --end-ip-address YOUR_IP\n ```\n\n3. **Connection String:**\n ```\n Server: your-server.database.windows.net\n Database: your-database\n Port: 1433\n Authentication: SQL Authentication\n ```\n\n#### Local SQL Server Express\n\n1. **Download and Install:**\n - Download SQL Server Express from Microsoft\n - Install with default settings\n - Enable TCP/IP connections\n\n2. **Create Database:**\n ```sql\n CREATE DATABASE DocumentSearchDB;\n USE DocumentSearchDB;\n -- Run the users table creation script\n ```\n\n### SSL/TLS Configuration\n\nFor production deployment, enable HTTPS:\n\n```python\n# In main.py, add SSL configuration\nif __name__ == \"__main__\":\n uvicorn.run(\n \"main:app\", \n host=\"0.0.0.0\", \n port=port,\n ssl_keyfile=\"path/to/private.key\",\n ssl_certfile=\"path/to/certificate.crt\"\n )\n```\n\n---\n\n## ๐Ÿงช Testing the Installation\n\n### Basic Functionality Test\n\n```bash\n# Test 1: Database Connection\npython -c \"\nfrom db_utils import get_db_connection\nwith get_db_connection() as conn:\n if conn:\n print('โœ… Database connection successful')\n cursor = conn.cursor()\n cursor.execute('SELECT 1')\n result = cursor.fetchone()\n print(f'โœ… Database query successful: {result}')\n else:\n print('โŒ Database connection failed')\n\"\n\n# Test 2: AI API Keys\npython -c \"\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\n\nkeys = {\n 'Groq': os.getenv('GROQ_API_KEY'),\n 'DeepSeek': os.getenv('DEEPSEEK_KEY'),\n 'OpenAI': os.getenv('OPENAI_API_KEY')\n}\n\nfor name, key in keys.items():\n status = 'โœ…' if key else 'โŒ'\n print(f'{status} {name} API Key: {\\\"Loaded\\\" if key else \\\"Missing\\\"}')\n\"\n\n# Test 3: RAG Engine Initialization\npython -c \"\nfrom rag_engine import RAGEngine\ntry:\n engine = RAGEngine()\n print('โœ… RAG Engine initialized successfully')\n print(f'โœ… Active LLM: {engine.active_llm_type}')\nexcept Exception as e:\n print(f'โŒ RAG Engine initialization failed: {e}')\n\"\n```\n\n### Web Interface Test\n\n1. Start the application: `python main.py`\n2. Open browser to `http://localhost:7860`\n3. Test login/signup functionality\n4. Upload a test document\n5. Try querying the document\n\n---\n\n## ๐Ÿ” Troubleshooting\n\n### Common Issues\n\n#### 1. Database Connection Issues\n\n**Problem:** Cannot connect to SQL Server\n```\nDatabase connection error: Login failed for user\n```\n\n**Solutions:**\n```bash\n# Check connection string\npython -c \"\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\nprint('Server:', os.getenv('SQL_SERVER_SERVER'))\nprint('Database:', os.getenv('SQL_SERVER_DATABASE'))\nprint('User:', os.getenv('SQL_SERVER_UID'))\n\"\n\n# Test with sqlcmd (if available)\nsqlcmd -S your-server.database.windows.net -d your-database -U your-user -P your-password -Q \"SELECT 1\"\n\n# Check firewall rules (Azure SQL)\naz sql server firewall-rule list --server your-server --resource-group your-rg\n```\n\n#### 2. Python Package Issues\n\n**Problem:** Import errors or package conflicts\n```\nModuleNotFoundError: No module named 'xxx'\n```\n\n**Solutions:**\n```bash\n# Reinstall requirements\npip uninstall -r requirements.txt -y\npip install -r requirements.txt\n\n# Clear pip cache\npip cache purge\n\n# Use fresh virtual environment\ndeactivate\nrm -rf document-search-env\npython -m venv document-search-env\nsource document-search-env/bin/activate # or activate.bat on Windows\npip install -r requirements.txt\n```\n\n#### 3. API Key Issues\n\n**Problem:** AI API calls failing\n```\nError: Invalid API key\n```\n\n**Solutions:**\n```bash\n# Verify API keys are loaded\npython -c \"\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\nfor key in ['GROQ_API_KEY', 'DEEPSEEK_KEY', 'OPENAI_API_KEY']:\n value = os.getenv(key)\n print(f'{key}: {value[:10]}...{value[-4:] if value else \\\"Not found\\\"}')\n\"\n\n# Test API keys directly\ncurl -H \"Authorization: Bearer $GROQ_API_KEY\" https://api.groq.com/v1/models\n```\n\n#### 4. Port Already in Use\n\n**Problem:** Port 7860 is already in use\n```\nOSError: [Errno 48] Address already in use\n```\n\n**Solutions:**\n```bash\n# Find process using the port\nlsof -i :7860 # macOS/Linux\nnetstat -ano | findstr :7860 # Windows\n\n# Kill the process\nkill -9 # macOS/Linux\ntaskkill /PID /F # Windows\n\n# Or use a different port\npython main.py --port 8080\n```\n\n#### 5. FAISS Installation Issues\n\n**Problem:** FAISS installation fails\n```\nERROR: Failed building wheel for faiss-cpu\n```\n\n**Solutions:**\n```bash\n# For Windows\npip install faiss-cpu --no-cache-dir --only-binary=all\n\n# For macOS with Apple Silicon\nconda install -c conda-forge faiss-cpu\n\n# Alternative: use pip with specific version\npip install faiss-cpu==1.7.4\n```\n\n### Getting Help\n\nIf you continue to experience issues:\n\n1. **Check the logs:** Look for error messages in the console output\n2. **Verify configuration:** Double-check your `.env` file\n3. **Test components individually:** Use the test scripts provided\n4. **Check system resources:** Ensure sufficient RAM and disk space\n5. **Update dependencies:** Try updating to the latest package versions\n\nFor additional support:\n- Check the [Troubleshooting Guide](TROUBLESHOOTING.md)\n- Open an issue on GitHub\n- Review the [FAQ section](README.md#faq)\n\n---\n\n## ๐Ÿ”„ Updating the Application\n\n### Regular Updates\n\n```bash\n# Pull latest changes\ngit pull origin main\n\n# Update dependencies\npip install -r requirements.txt --upgrade\n\n# Check for breaking changes\ngit diff HEAD~1 requirements.txt\ngit diff HEAD~1 .env.example\n\n# Restart the application\npython main.py\n```\n\n### Database Migrations\n\nIf database schema changes are required:\n\n```sql\n-- Example migration script\n-- Add new column to users table\nALTER TABLE dbo.users ADD created_at DATETIME2 DEFAULT GETUTCDATE();\nALTER TABLE dbo.users ADD updated_at DATETIME2 DEFAULT GETUTCDATE();\n\n-- Create index for better performance\nCREATE INDEX IX_users_created_at ON dbo.users(created_at);\n```\n\n---\n\n## ๐Ÿ“ˆ Performance Optimization\n\n### Memory Usage\n\n```bash\n# Monitor memory usage\npython -c \"\nimport psutil\nimport os\nprocess = psutil.Process(os.getpid())\nprint(f'Memory usage: {process.memory_info().rss / 1024 / 1024:.2f} MB')\n\"\n```\n\n### Database Optimization\n\n```sql\n-- Create indexes for better performance\nCREATE INDEX IX_users_email ON dbo.users(email);\nCREATE INDEX IX_users_role ON dbo.users(role);\n\n-- Update statistics\nUPDATE STATISTICS dbo.users;\n```\n\n### File Storage\n\n```bash\n# Clean up old FAISS indexes if needed\nls -la storage_faiss/\n# Remove old indexes if disk space is low\n```\n\n---\n\n## โœ… Verification Checklist\n\nAfter installation, verify these components work:\n\n- [ ] Application starts without errors\n- [ ] Database connection is successful\n- [ ] All API keys are loaded\n- [ ] Web interface is accessible\n- [ ] User registration works\n- [ ] User login works\n- [ ] Document upload works\n- [ ] Document indexing works\n- [ ] Query functionality works\n- [ ] LLM switching works\n- [ ] Logout functionality works\n\nCongratulations! Your Document Search Application is now ready to use. ๐ŸŽ‰"}}, "CONFIGURATION.md": {"3ad41fbae234e529a8484c058e00bfc476234ab0": {"t": 1785746624.616587, "n": 17207, "h": "69bde7bf39a48382", "c": "# Configuration Guide\n\nThis document provides detailed information about configuring the Document Search Application for different environments and use cases.\n\n## ๐Ÿ“‹ Environment Variables\n\n### Core Configuration\n\nCreate a `.env` file in the project root with the following variables:\n\n```env\n# Database Configuration\nSQL_SERVER_SERVER=your-server.database.windows.net\nSQL_SERVER_DATABASE=your-database-name\nSQL_SERVER_UID=your-username\nSQL_SERVER_PWD=your-password\nSQL_SERVER_PORT=1433\n\n# AI API Keys\nGROQ_API_KEY=your-groq-api-key\nDEEPSEEK_KEY=your-deepseek-api-key\nOPENAI_API_KEY=your-openai-api-key\n\n# Security\nJWT_SECRET_KEY=your-very-long-and-random-secret-key\n\n# Application Settings\nDEPLOYMENT_ENV=development\nEMBEDDING_PROVIDER=openai\nPORT=7860\n```\n\n### Database Configuration\n\n#### SQL Server Settings\n\n| Variable | Description | Default | Required |\n|----------|-------------|---------|----------|\n| `SQL_SERVER_SERVER` | SQL Server hostname or IP | None | Yes |\n| `SQL_SERVER_DATABASE` | Database name | None | Yes |\n| `SQL_SERVER_UID` | Username for authentication | None | Yes |\n| `SQL_SERVER_PWD` | Password for authentication | None | Yes |\n| `SQL_SERVER_PORT` | SQL Server port | 1433 | No |\n\n**Examples:**\n\n```env\n# Azure SQL Database\nSQL_SERVER_SERVER=myserver.database.windows.net\nSQL_SERVER_DATABASE=DocumentSearchDB\nSQL_SERVER_UID=sqladmin\nSQL_SERVER_PWD=SecurePassword123!\nSQL_SERVER_PORT=1433\n\n# Local SQL Server\nSQL_SERVER_SERVER=localhost\nSQL_SERVER_DATABASE=DocumentSearchDB\nSQL_SERVER_UID=sa\nSQL_SERVER_PWD=MyLocalPassword123!\nSQL_SERVER_PORT=1433\n\n# SQL Server with Instance\nSQL_SERVER_SERVER=localhost\\\\SQLEXPRESS\nSQL_SERVER_DATABASE=DocumentSearchDB\nSQL_SERVER_UID=sa\nSQL_SERVER_PWD=MyPassword123!\n```\n\n### AI API Configuration\n\n#### Groq Configuration\n\n```env\n# Groq API Key\nGROQ_API_KEY=gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n```\n\n**Getting a Groq API Key:**\n1. Visit [Groq Console](https://console.groq.com/)\n2. Sign up for an account\n3. Navigate to the API Keys section\n4. Create a new API key\n5. Copy the key (starts with `gsk_`)\n\n**Supported Models:**\n- `llama3-70b-8192` (default)\n- `llama3-8b-8192`\n- `mixtral-8x7b-32768`\n\n#### DeepSeek Configuration\n\n```env\n# DeepSeek API Key\nDEEPSEEK_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n```\n\n**Getting a DeepSeek API Key:**\n1. Visit [DeepSeek Platform](https://platform.deepseek.com/)\n2. Register for an account\n3. Go to the API section\n4. Generate an API key\n5. Copy the key (starts with `sk-`)\n\n**Supported Models:**\n- `deepseek-chat` (default)\n- `deepseek-coder`\n\n#### OpenAI Configuration\n\n```env\n# OpenAI API Key\nOPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n```\n\n**Getting an OpenAI API Key:**\n1. Visit [OpenAI Platform](https://platform.openai.com/)\n2. Sign up or log in\n3. Go to API Keys section\n4. Create a new secret key\n5. Copy the key (starts with `sk-`)\n\n**Supported Embedding Models:**\n- `text-embedding-3-small` (default, 1536 dimensions)\n- `text-embedding-3-large` (3072 dimensions)\n- `text-embedding-ada-002` (1536 dimensions)\n\n### Security Configuration\n\n#### JWT Settings\n\n```env\n# JWT Secret Key (minimum 32 characters)\nJWT_SECRET_KEY=your-very-long-and-random-secret-key-that-should-be-at-least-32-characters-long\n\n# JWT Algorithm (default: HS256)\nJWT_ALGORITHM=HS256\n\n# Token expiration in minutes (default: 30)\nJWT_EXPIRE_MINUTES=30\n```\n\n**Generating a Secure JWT Secret:**\n\n```bash\n# Using OpenSSL\nopenssl rand -hex 32\n\n# Using Python\npython -c \"import secrets; print(secrets.token_hex(32))\"\n\n# Using Node.js\nnode -e \"console.log(require('crypto').randomBytes(32).toString('hex'))\"\n```\n\n### Application Settings\n\n#### Deployment Environment\n\n```env\n# Deployment environment\nDEPLOYMENT_ENV=development # or 'production'\n```\n\n**Development vs Production:**\n\n| Setting | Development | Production |\n|---------|-------------|------------|\n| Cookie Secure Flag | False | True |\n| Debug Mode | Enabled | Disabled |\n| Error Details | Shown | Hidden |\n| HTTPS Required | No | Yes |\n| Logging Level | DEBUG | INFO |\n\n#### Embedding Provider\n\n```env\n# Embedding provider\nEMBEDDING_PROVIDER=openai # Only 'openai' supported currently\n```\n\n#### Server Configuration\n\n```env\n# Server port\nPORT=7860\n\n# Server host (for development)\nHOST=localhost\n\n# Server host (for production)\nHOST=0.0.0.0\n```\n\n---\n\n## ๐ŸŽ›๏ธ Advanced Configuration\n\n### Model Settings\n\n#### Groq Model Configuration\n\n```python\n# In rag_engine.py, modify these constants:\nGROQ_LLM_MODEL_NAME = \"llama3-70b-8192\" # Default model\nGROQ_TEMPERATURE = 0.7 # Creativity level (0-1)\nGROQ_MAX_TOKENS = 2048 # Maximum response length\n```\n\n#### DeepSeek Model Configuration\n\n```python\n# In rag_engine.py, modify these constants:\nDEEPSEEK_LLM_MODEL_NAME = \"deepseek-chat\" # Default model\nDEEPSEEK_TEMPERATURE = 0.7 # Creativity level (0-1)\nDEEPSEEK_MAX_TOKENS = 2048 # Maximum response length\n```\n\n#### OpenAI Embedding Configuration\n\n```python\n# In rag_engine.py, modify these constants:\nOPENAI_EMBED_MODEL_NAME = \"text-embedding-3-small\" # Default model\nOPENAI_EMBED_DIM = 1536 # Embedding dimensions\n```\n\n### FAISS Configuration\n\n```python\n# Storage path for FAISS index\nFAISS_PERSIST_PATH = \"./storage_faiss\"\n\n# Index file name\nINDEX_FILE = \"vector_store.faiss\"\n```\n\n### Database Connection Pool\n\n```python\n# In db_utils.py, you can modify connection settings:\nCONNECTION_TIMEOUT = 30 # Connection timeout in seconds\nCOMMAND_TIMEOUT = 30 # Command timeout in seconds\nMAX_RETRIES = 3 # Maximum connection retries\n```\n\n---\n\n## ๐ŸŒ Environment-Specific Configurations\n\n### Development Environment\n\n**.env.development:**\n```env\n# Development Database (Local SQL Server)\nSQL_SERVER_SERVER=localhost\\\\SQLEXPRESS\nSQL_SERVER_DATABASE=DocumentSearchDB_Dev\nSQL_SERVER_UID=sa\nSQL_SERVER_PWD=DevPassword123!\n\n# Development API Keys (use test keys if available)\nGROQ_API_KEY=your-groq-dev-key\nDEEPSEEK_KEY=your-deepseek-dev-key\nOPENAI_API_KEY=your-openai-dev-key\n\n# Development Security (use simple key for testing)\nJWT_SECRET_KEY=development-jwt-secret-key-for-testing-only\n\n# Development Settings\nDEPLOYMENT_ENV=development\nPORT=7860\nHOST=localhost\nDEBUG=true\n```\n\n### Production Environment\n\n**.env.production:**\n```env\n# Production Database (Azure SQL)\nSQL_SERVER_SERVER=myapp-prod.database.windows.net\nSQL_SERVER_DATABASE=DocumentSearchDB_Prod\nSQL_SERVER_UID=produser\nSQL_SERVER_PWD=VerySecureProductionPassword123!\n\n# Production API Keys\nGROQ_API_KEY=your-groq-prod-key\nDEEPSEEK_KEY=your-deepseek-prod-key\nOPENAI_API_KEY=your-openai-prod-key\n\n# Production Security (use strong random key)\nJWT_SECRET_KEY=very-long-random-production-jwt-secret-key\n\n# Production Settings\nDEPLOYMENT_ENV=production\nPORT=80\nHOST=0.0.0.0\nDEBUG=false\n```\n\n### Staging Environment\n\n**.env.staging:**\n```env\n# Staging Database\nSQL_SERVER_SERVER=myapp-staging.database.windows.net\nSQL_SERVER_DATABASE=DocumentSearchDB_Staging\nSQL_SERVER_UID=staginguser\nSQL_SERVER_PWD=StagingPassword123!\n\n# Staging API Keys (can use production keys)\nGROQ_API_KEY=your-groq-staging-key\nDEEPSEEK_KEY=your-deepseek-staging-key\nOPENAI_API_KEY=your-openai-staging-key\n\n# Staging Security\nJWT_SECRET_KEY=staging-jwt-secret-key\n\n# Staging Settings\nDEPLOYMENT_ENV=staging\nPORT=8080\nHOST=0.0.0.0\nDEBUG=false\n```\n\n---\n\n## ๐Ÿ”ง Configuration Management\n\n### Environment File Selection\n\n```bash\n# Use specific environment file\ncp .env.development .env # For development\ncp .env.production .env # For production\ncp .env.staging .env # For staging\n\n# Or use environment variable\nexport ENV_FILE=.env.production\n```\n\n### Configuration Validation\n\n**Validation Script** (`validate_config.py`):\n```python\nimport os\nfrom dotenv import load_dotenv\n\ndef validate_config():\n \"\"\"Validate configuration settings.\"\"\"\n load_dotenv()\n \n required_vars = [\n 'SQL_SERVER_SERVER',\n 'SQL_SERVER_DATABASE', \n 'SQL_SERVER_UID',\n 'SQL_SERVER_PWD',\n 'JWT_SECRET_KEY'\n ]\n \n missing_vars = []\n for var in required_vars:\n if not os.getenv(var):\n missing_vars.append(var)\n \n if missing_vars:\n print(f\"โŒ Missing required variables: {', '.join(missing_vars)}\")\n return False\n \n # Validate JWT secret key length\n jwt_secret = os.getenv('JWT_SECRET_KEY')\n if len(jwt_secret) < 32:\n print(\"โŒ JWT_SECRET_KEY must be at least 32 characters long\")\n return False\n \n # Check API keys\n api_keys = {\n 'GROQ_API_KEY': os.getenv('GROQ_API_KEY'),\n 'DEEPSEEK_KEY': os.getenv('DEEPSEEK_KEY'),\n 'OPENAI_API_KEY': os.getenv('OPENAI_API_KEY')\n }\n \n for key_name, key_value in api_keys.items():\n if key_value:\n print(f\"โœ… {key_name}: Configured\")\n else:\n print(f\"โš ๏ธ {key_name}: Not configured\")\n \n print(\"โœ… Configuration validation passed\")\n return True\n\nif __name__ == \"__main__\":\n validate_config()\n```\n\n### Configuration Testing\n\n**Test Script** (`test_config.py`):\n```python\nimport os\nfrom dotenv import load_dotenv\nfrom db_utils import get_db_connection\nfrom rag_engine import RAGEngine\n\ndef test_database_connection():\n \"\"\"Test database connection.\"\"\"\n try:\n with get_db_connection() as conn:\n if conn:\n cursor = conn.cursor()\n cursor.execute(\"SELECT 1\")\n result = cursor.fetchone()\n print(\"โœ… Database connection successful\")\n return True\n else:\n print(\"โŒ Database connection failed\")\n return False\n except Exception as e:\n print(f\"โŒ Database connection error: {e}\")\n return False\n\ndef test_rag_engine():\n \"\"\"Test RAG engine initialization.\"\"\"\n try:\n engine = RAGEngine()\n print(f\"โœ… RAG Engine initialized, active LLM: {engine.active_llm_type}\")\n return True\n except Exception as e:\n print(f\"โŒ RAG Engine initialization failed: {e}\")\n return False\n\ndef test_api_keys():\n \"\"\"Test API key configuration.\"\"\"\n load_dotenv()\n \n keys = {\n 'Groq': os.getenv('GROQ_API_KEY'),\n 'DeepSeek': os.getenv('DEEPSEEK_KEY'),\n 'OpenAI': os.getenv('OPENAI_API_KEY')\n }\n \n for name, key in keys.items():\n if key:\n print(f\"โœ… {name} API key configured\")\n else:\n print(f\"โš ๏ธ {name} API key not configured\")\n\nif __name__ == \"__main__\":\n print(\"Testing configuration...\")\n test_database_connection()\n test_rag_engine()\n test_api_keys()\n```\n\n---\n\n## ๐Ÿš€ Deployment Configurations\n\n### Docker Configuration\n\n**Dockerfile:**\n```dockerfile\nFROM python:3.11-slim\n\nWORKDIR /app\n\n# Install system dependencies\nRUN apt-get update && apt-get install -y \\\n gcc g++ \\\n && rm -rf /var/lib/apt/lists/*\n\n# Copy and install Python dependencies\nCOPY requirements.txt .\nRUN pip install --no-cache-dir -r requirements.txt\n\n# Copy application code\nCOPY . .\n\n# Create storage directory\nRUN mkdir -p storage_faiss\n\n# Expose port\nEXPOSE 7860\n\n# Run application\nCMD [\"python\", \"main.py\"]\n```\n\n**docker-compose.yml:**\n```yaml\nversion: '3.8'\n\nservices:\n document-search:\n build: .\n ports:\n - \"${PORT:-7860}:7860\"\n environment:\n - SQL_SERVER_SERVER=${SQL_SERVER_SERVER}\n - SQL_SERVER_DATABASE=${SQL_SERVER_DATABASE}\n - SQL_SERVER_UID=${SQL_SERVER_UID}\n - SQL_SERVER_PWD=${SQL_SERVER_PWD}\n - GROQ_API_KEY=${GROQ_API_KEY}\n - DEEPSEEK_KEY=${DEEPSEEK_KEY}\n - OPENAI_API_KEY=${OPENAI_API_KEY}\n - JWT_SECRET_KEY=${JWT_SECRET_KEY}\n - DEPLOYMENT_ENV=${DEPLOYMENT_ENV:-production}\n volumes:\n - ./storage_faiss:/app/storage_faiss\n - ./logs:/app/logs\n env_file:\n - .env\n restart: unless-stopped\n healthcheck:\n test: [\"CMD\", \"curl\", \"-f\", \"http://localhost:7860/\"]\n interval: 30s\n timeout: 10s\n retries: 3\n```\n\n### Kubernetes Configuration\n\n**deployment.yaml:**\n```yaml\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: document-search\nspec:\n replicas: 2\n selector:\n matchLabels:\n app: document-search\n template:\n metadata:\n labels:\n app: document-search\n spec:\n containers:\n - name: document-search\n image: your-registry/document-search:latest\n ports:\n - containerPort: 7860\n env:\n - name: SQL_SERVER_SERVER\n valueFrom:\n secretKeyRef:\n name: app-secrets\n key: sql-server\n - name: SQL_SERVER_DATABASE\n valueFrom:\n secretKeyRef:\n name: app-secrets\n key: sql-database\n - name: JWT_SECRET_KEY\n valueFrom:\n secretKeyRef:\n name: app-secrets\n key: jwt-secret\n volumeMounts:\n - name: storage\n mountPath: /app/storage_faiss\n volumes:\n - name: storage\n persistentVolumeClaim:\n claimName: document-search-storage\n```\n\n---\n\n## ๐Ÿ”’ Security Configuration\n\n### HTTPS Configuration\n\n**For Production with SSL:**\n```python\n# In main.py\nimport uvicorn\nimport ssl\n\nif __name__ == \"__main__\":\n port = int(os.environ.get(\"PORT\", 7860))\n \n if os.getenv(\"DEPLOYMENT_ENV\") == \"production\":\n # Configure SSL\n ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)\n ssl_context.load_cert_chain(\n certfile=\"path/to/certificate.crt\",\n keyfile=\"path/to/private.key\"\n )\n \n uvicorn.run(\n \"main:app\",\n host=\"0.0.0.0\",\n port=port,\n ssl_context=ssl_context\n )\n else:\n uvicorn.run(\"main:app\", host=\"0.0.0.0\", port=port)\n```\n\n### CORS Configuration\n\n```python\n# In main.py or backend_app.py\nfrom fastapi.middleware.cors import CORSMiddleware\n\napp.add_middleware(\n CORSMiddleware,\n allow_origins=[\"https://yourdomain.com\"], # Update with your domain\n allow_credentials=True,\n allow_methods=[\"GET\", \"POST\"],\n allow_headers=[\"*\"],\n)\n```\n\n### Rate Limiting Configuration\n\n```python\n# Optional: Add rate limiting\nfrom slowapi import Limiter, _rate_limit_exceeded_handler\nfrom slowapi.util import get_remote_address\n\nlimiter = Limiter(key_func=get_remote_address)\napp.state.limiter = limiter\napp.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)\n\n# Apply to specific endpoints\n@app.post(\"/login\")\n@limiter.limit(\"5/minute\")\nasync def login_user(request: Request, user_credentials: UserLoginRequest):\n # ... existing code\n```\n\n---\n\n## ๐Ÿ“Š Monitoring Configuration\n\n### Logging Configuration\n\n```python\n# In main.py\nimport logging\n\n# Configure logging\nlogging.basicConfig(\n level=logging.INFO if os.getenv(\"DEPLOYMENT_ENV\") == \"production\" else logging.DEBUG,\n format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',\n handlers=[\n logging.FileHandler('app.log'),\n logging.StreamHandler()\n ]\n)\n\nlogger = logging.getLogger(__name__)\n```\n\n### Health Check Configuration\n\n```python\n# Add health check endpoint\n@app.get(\"/health\")\nasync def health_check():\n \"\"\"Health check endpoint.\"\"\"\n return {\n \"status\": \"healthy\",\n \"timestamp\": datetime.utcnow().isoformat(),\n \"version\": \"1.0.0\"\n }\n```\n\n---\n\n## ๐Ÿ”„ Configuration Updates\n\n### Hot Reload Configuration\n\nFor development, enable hot reload:\n```python\nif __name__ == \"__main__\":\n uvicorn.run(\n \"main:app\",\n host=\"0.0.0.0\",\n port=port,\n reload=True if os.getenv(\"DEPLOYMENT_ENV\") == \"development\" else False\n )\n```\n\n### Configuration Refresh\n\nTo update configuration without restart:\n```python\n# Add configuration refresh endpoint (development only)\n@app.post(\"/admin/refresh-config\")\nasync def refresh_config():\n if os.getenv(\"DEPLOYMENT_ENV\") != \"development\":\n raise HTTPException(status_code=404, detail=\"Not found\")\n \n # Reload environment variables\n load_dotenv(override=True)\n \n return {\"status\": \"Configuration refreshed\"}\n```\n\n---\n\n## โœ… Configuration Checklist\n\nBefore deployment, verify:\n\n- [ ] All required environment variables are set\n- [ ] Database connection works\n- [ ] All API keys are valid\n- [ ] JWT secret key is secure (32+ characters)\n- [ ] Deployment environment is set correctly\n- [ ] SSL certificates are configured (production)\n- [ ] CORS settings are appropriate\n- [ ] Logging is configured\n- [ ] Health checks work\n- [ ] Backup procedures are in place\n\n---\n\n## ๐Ÿ†˜ Configuration Troubleshooting\n\n### Common Issues\n\n1. **Database Connection Failed**\n - Check server name and port\n - Verify credentials\n - Check firewall settings\n\n2. **API Key Errors**\n - Verify key format and validity\n - Check API quotas and limits\n - Ensure keys are not expired\n\n3. **JWT Token Issues**\n - Check secret key length\n - Verify token expiration settings\n - Check clock synchronization\n\n4. **CORS Errors**\n - Update allowed origins\n - Check request methods\n - Verify credentials setting\n\nFor more troubleshooting help, see [TROUBLESHOOTING.md](TROUBLESHOOTING.md).\n\n---\n\n**Remember to keep your configuration files secure and never commit sensitive information to version control!**"}, "744ec922d275fd9cdec5d17cc32e1f84b1d046eb": {"t": 1785747854.667329, "n": 17207, "h": "69bde7bf39a48382", "c": "# Configuration Guide\n\nThis document provides detailed information about configuring the Document Search Application for different environments and use cases.\n\n## ๐Ÿ“‹ Environment Variables\n\n### Core Configuration\n\nCreate a `.env` file in the project root with the following variables:\n\n```env\n# Database Configuration\nSQL_SERVER_SERVER=your-server.database.windows.net\nSQL_SERVER_DATABASE=your-database-name\nSQL_SERVER_UID=your-username\nSQL_SERVER_PWD=your-password\nSQL_SERVER_PORT=1433\n\n# AI API Keys\nGROQ_API_KEY=your-groq-api-key\nDEEPSEEK_KEY=your-deepseek-api-key\nOPENAI_API_KEY=your-openai-api-key\n\n# Security\nJWT_SECRET_KEY=your-very-long-and-random-secret-key\n\n# Application Settings\nDEPLOYMENT_ENV=development\nEMBEDDING_PROVIDER=openai\nPORT=7860\n```\n\n### Database Configuration\n\n#### SQL Server Settings\n\n| Variable | Description | Default | Required |\n|----------|-------------|---------|----------|\n| `SQL_SERVER_SERVER` | SQL Server hostname or IP | None | Yes |\n| `SQL_SERVER_DATABASE` | Database name | None | Yes |\n| `SQL_SERVER_UID` | Username for authentication | None | Yes |\n| `SQL_SERVER_PWD` | Password for authentication | None | Yes |\n| `SQL_SERVER_PORT` | SQL Server port | 1433 | No |\n\n**Examples:**\n\n```env\n# Azure SQL Database\nSQL_SERVER_SERVER=myserver.database.windows.net\nSQL_SERVER_DATABASE=DocumentSearchDB\nSQL_SERVER_UID=sqladmin\nSQL_SERVER_PWD=SecurePassword123!\nSQL_SERVER_PORT=1433\n\n# Local SQL Server\nSQL_SERVER_SERVER=localhost\nSQL_SERVER_DATABASE=DocumentSearchDB\nSQL_SERVER_UID=sa\nSQL_SERVER_PWD=MyLocalPassword123!\nSQL_SERVER_PORT=1433\n\n# SQL Server with Instance\nSQL_SERVER_SERVER=localhost\\\\SQLEXPRESS\nSQL_SERVER_DATABASE=DocumentSearchDB\nSQL_SERVER_UID=sa\nSQL_SERVER_PWD=MyPassword123!\n```\n\n### AI API Configuration\n\n#### Groq Configuration\n\n```env\n# Groq API Key\nGROQ_API_KEY=gsk_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n```\n\n**Getting a Groq API Key:**\n1. Visit [Groq Console](https://console.groq.com/)\n2. Sign up for an account\n3. Navigate to the API Keys section\n4. Create a new API key\n5. Copy the key (starts with `gsk_`)\n\n**Supported Models:**\n- `llama3-70b-8192` (default)\n- `llama3-8b-8192`\n- `mixtral-8x7b-32768`\n\n#### DeepSeek Configuration\n\n```env\n# DeepSeek API Key\nDEEPSEEK_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n```\n\n**Getting a DeepSeek API Key:**\n1. Visit [DeepSeek Platform](https://platform.deepseek.com/)\n2. Register for an account\n3. Go to the API section\n4. Generate an API key\n5. Copy the key (starts with `sk-`)\n\n**Supported Models:**\n- `deepseek-chat` (default)\n- `deepseek-coder`\n\n#### OpenAI Configuration\n\n```env\n# OpenAI API Key\nOPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n```\n\n**Getting an OpenAI API Key:**\n1. Visit [OpenAI Platform](https://platform.openai.com/)\n2. Sign up or log in\n3. Go to API Keys section\n4. Create a new secret key\n5. Copy the key (starts with `sk-`)\n\n**Supported Embedding Models:**\n- `text-embedding-3-small` (default, 1536 dimensions)\n- `text-embedding-3-large` (3072 dimensions)\n- `text-embedding-ada-002` (1536 dimensions)\n\n### Security Configuration\n\n#### JWT Settings\n\n```env\n# JWT Secret Key (minimum 32 characters)\nJWT_SECRET_KEY=your-very-long-and-random-secret-key-that-should-be-at-least-32-characters-long\n\n# JWT Algorithm (default: HS256)\nJWT_ALGORITHM=HS256\n\n# Token expiration in minutes (default: 30)\nJWT_EXPIRE_MINUTES=30\n```\n\n**Generating a Secure JWT Secret:**\n\n```bash\n# Using OpenSSL\nopenssl rand -hex 32\n\n# Using Python\npython -c \"import secrets; print(secrets.token_hex(32))\"\n\n# Using Node.js\nnode -e \"console.log(require('crypto').randomBytes(32).toString('hex'))\"\n```\n\n### Application Settings\n\n#### Deployment Environment\n\n```env\n# Deployment environment\nDEPLOYMENT_ENV=development # or 'production'\n```\n\n**Development vs Production:**\n\n| Setting | Development | Production |\n|---------|-------------|------------|\n| Cookie Secure Flag | False | True |\n| Debug Mode | Enabled | Disabled |\n| Error Details | Shown | Hidden |\n| HTTPS Required | No | Yes |\n| Logging Level | DEBUG | INFO |\n\n#### Embedding Provider\n\n```env\n# Embedding provider\nEMBEDDING_PROVIDER=openai # Only 'openai' supported currently\n```\n\n#### Server Configuration\n\n```env\n# Server port\nPORT=7860\n\n# Server host (for development)\nHOST=localhost\n\n# Server host (for production)\nHOST=0.0.0.0\n```\n\n---\n\n## ๐ŸŽ›๏ธ Advanced Configuration\n\n### Model Settings\n\n#### Groq Model Configuration\n\n```python\n# In rag_engine.py, modify these constants:\nGROQ_LLM_MODEL_NAME = \"llama3-70b-8192\" # Default model\nGROQ_TEMPERATURE = 0.7 # Creativity level (0-1)\nGROQ_MAX_TOKENS = 2048 # Maximum response length\n```\n\n#### DeepSeek Model Configuration\n\n```python\n# In rag_engine.py, modify these constants:\nDEEPSEEK_LLM_MODEL_NAME = \"deepseek-chat\" # Default model\nDEEPSEEK_TEMPERATURE = 0.7 # Creativity level (0-1)\nDEEPSEEK_MAX_TOKENS = 2048 # Maximum response length\n```\n\n#### OpenAI Embedding Configuration\n\n```python\n# In rag_engine.py, modify these constants:\nOPENAI_EMBED_MODEL_NAME = \"text-embedding-3-small\" # Default model\nOPENAI_EMBED_DIM = 1536 # Embedding dimensions\n```\n\n### FAISS Configuration\n\n```python\n# Storage path for FAISS index\nFAISS_PERSIST_PATH = \"./storage_faiss\"\n\n# Index file name\nINDEX_FILE = \"vector_store.faiss\"\n```\n\n### Database Connection Pool\n\n```python\n# In db_utils.py, you can modify connection settings:\nCONNECTION_TIMEOUT = 30 # Connection timeout in seconds\nCOMMAND_TIMEOUT = 30 # Command timeout in seconds\nMAX_RETRIES = 3 # Maximum connection retries\n```\n\n---\n\n## ๐ŸŒ Environment-Specific Configurations\n\n### Development Environment\n\n**.env.development:**\n```env\n# Development Database (Local SQL Server)\nSQL_SERVER_SERVER=localhost\\\\SQLEXPRESS\nSQL_SERVER_DATABASE=DocumentSearchDB_Dev\nSQL_SERVER_UID=sa\nSQL_SERVER_PWD=DevPassword123!\n\n# Development API Keys (use test keys if available)\nGROQ_API_KEY=your-groq-dev-key\nDEEPSEEK_KEY=your-deepseek-dev-key\nOPENAI_API_KEY=your-openai-dev-key\n\n# Development Security (use simple key for testing)\nJWT_SECRET_KEY=development-jwt-secret-key-for-testing-only\n\n# Development Settings\nDEPLOYMENT_ENV=development\nPORT=7860\nHOST=localhost\nDEBUG=true\n```\n\n### Production Environment\n\n**.env.production:**\n```env\n# Production Database (Azure SQL)\nSQL_SERVER_SERVER=myapp-prod.database.windows.net\nSQL_SERVER_DATABASE=DocumentSearchDB_Prod\nSQL_SERVER_UID=produser\nSQL_SERVER_PWD=VerySecureProductionPassword123!\n\n# Production API Keys\nGROQ_API_KEY=your-groq-prod-key\nDEEPSEEK_KEY=your-deepseek-prod-key\nOPENAI_API_KEY=your-openai-prod-key\n\n# Production Security (use strong random key)\nJWT_SECRET_KEY=very-long-random-production-jwt-secret-key\n\n# Production Settings\nDEPLOYMENT_ENV=production\nPORT=80\nHOST=0.0.0.0\nDEBUG=false\n```\n\n### Staging Environment\n\n**.env.staging:**\n```env\n# Staging Database\nSQL_SERVER_SERVER=myapp-staging.database.windows.net\nSQL_SERVER_DATABASE=DocumentSearchDB_Staging\nSQL_SERVER_UID=staginguser\nSQL_SERVER_PWD=StagingPassword123!\n\n# Staging API Keys (can use production keys)\nGROQ_API_KEY=your-groq-staging-key\nDEEPSEEK_KEY=your-deepseek-staging-key\nOPENAI_API_KEY=your-openai-staging-key\n\n# Staging Security\nJWT_SECRET_KEY=staging-jwt-secret-key\n\n# Staging Settings\nDEPLOYMENT_ENV=staging\nPORT=8080\nHOST=0.0.0.0\nDEBUG=false\n```\n\n---\n\n## ๐Ÿ”ง Configuration Management\n\n### Environment File Selection\n\n```bash\n# Use specific environment file\ncp .env.development .env # For development\ncp .env.production .env # For production\ncp .env.staging .env # For staging\n\n# Or use environment variable\nexport ENV_FILE=.env.production\n```\n\n### Configuration Validation\n\n**Validation Script** (`validate_config.py`):\n```python\nimport os\nfrom dotenv import load_dotenv\n\ndef validate_config():\n \"\"\"Validate configuration settings.\"\"\"\n load_dotenv()\n \n required_vars = [\n 'SQL_SERVER_SERVER',\n 'SQL_SERVER_DATABASE', \n 'SQL_SERVER_UID',\n 'SQL_SERVER_PWD',\n 'JWT_SECRET_KEY'\n ]\n \n missing_vars = []\n for var in required_vars:\n if not os.getenv(var):\n missing_vars.append(var)\n \n if missing_vars:\n print(f\"โŒ Missing required variables: {', '.join(missing_vars)}\")\n return False\n \n # Validate JWT secret key length\n jwt_secret = os.getenv('JWT_SECRET_KEY')\n if len(jwt_secret) < 32:\n print(\"โŒ JWT_SECRET_KEY must be at least 32 characters long\")\n return False\n \n # Check API keys\n api_keys = {\n 'GROQ_API_KEY': os.getenv('GROQ_API_KEY'),\n 'DEEPSEEK_KEY': os.getenv('DEEPSEEK_KEY'),\n 'OPENAI_API_KEY': os.getenv('OPENAI_API_KEY')\n }\n \n for key_name, key_value in api_keys.items():\n if key_value:\n print(f\"โœ… {key_name}: Configured\")\n else:\n print(f\"โš ๏ธ {key_name}: Not configured\")\n \n print(\"โœ… Configuration validation passed\")\n return True\n\nif __name__ == \"__main__\":\n validate_config()\n```\n\n### Configuration Testing\n\n**Test Script** (`test_config.py`):\n```python\nimport os\nfrom dotenv import load_dotenv\nfrom db_utils import get_db_connection\nfrom rag_engine import RAGEngine\n\ndef test_database_connection():\n \"\"\"Test database connection.\"\"\"\n try:\n with get_db_connection() as conn:\n if conn:\n cursor = conn.cursor()\n cursor.execute(\"SELECT 1\")\n result = cursor.fetchone()\n print(\"โœ… Database connection successful\")\n return True\n else:\n print(\"โŒ Database connection failed\")\n return False\n except Exception as e:\n print(f\"โŒ Database connection error: {e}\")\n return False\n\ndef test_rag_engine():\n \"\"\"Test RAG engine initialization.\"\"\"\n try:\n engine = RAGEngine()\n print(f\"โœ… RAG Engine initialized, active LLM: {engine.active_llm_type}\")\n return True\n except Exception as e:\n print(f\"โŒ RAG Engine initialization failed: {e}\")\n return False\n\ndef test_api_keys():\n \"\"\"Test API key configuration.\"\"\"\n load_dotenv()\n \n keys = {\n 'Groq': os.getenv('GROQ_API_KEY'),\n 'DeepSeek': os.getenv('DEEPSEEK_KEY'),\n 'OpenAI': os.getenv('OPENAI_API_KEY')\n }\n \n for name, key in keys.items():\n if key:\n print(f\"โœ… {name} API key configured\")\n else:\n print(f\"โš ๏ธ {name} API key not configured\")\n\nif __name__ == \"__main__\":\n print(\"Testing configuration...\")\n test_database_connection()\n test_rag_engine()\n test_api_keys()\n```\n\n---\n\n## ๐Ÿš€ Deployment Configurations\n\n### Docker Configuration\n\n**Dockerfile:**\n```dockerfile\nFROM python:3.11-slim\n\nWORKDIR /app\n\n# Install system dependencies\nRUN apt-get update && apt-get install -y \\\n gcc g++ \\\n && rm -rf /var/lib/apt/lists/*\n\n# Copy and install Python dependencies\nCOPY requirements.txt .\nRUN pip install --no-cache-dir -r requirements.txt\n\n# Copy application code\nCOPY . .\n\n# Create storage directory\nRUN mkdir -p storage_faiss\n\n# Expose port\nEXPOSE 7860\n\n# Run application\nCMD [\"python\", \"main.py\"]\n```\n\n**docker-compose.yml:**\n```yaml\nversion: '3.8'\n\nservices:\n document-search:\n build: .\n ports:\n - \"${PORT:-7860}:7860\"\n environment:\n - SQL_SERVER_SERVER=${SQL_SERVER_SERVER}\n - SQL_SERVER_DATABASE=${SQL_SERVER_DATABASE}\n - SQL_SERVER_UID=${SQL_SERVER_UID}\n - SQL_SERVER_PWD=${SQL_SERVER_PWD}\n - GROQ_API_KEY=${GROQ_API_KEY}\n - DEEPSEEK_KEY=${DEEPSEEK_KEY}\n - OPENAI_API_KEY=${OPENAI_API_KEY}\n - JWT_SECRET_KEY=${JWT_SECRET_KEY}\n - DEPLOYMENT_ENV=${DEPLOYMENT_ENV:-production}\n volumes:\n - ./storage_faiss:/app/storage_faiss\n - ./logs:/app/logs\n env_file:\n - .env\n restart: unless-stopped\n healthcheck:\n test: [\"CMD\", \"curl\", \"-f\", \"http://localhost:7860/\"]\n interval: 30s\n timeout: 10s\n retries: 3\n```\n\n### Kubernetes Configuration\n\n**deployment.yaml:**\n```yaml\napiVersion: apps/v1\nkind: Deployment\nmetadata:\n name: document-search\nspec:\n replicas: 2\n selector:\n matchLabels:\n app: document-search\n template:\n metadata:\n labels:\n app: document-search\n spec:\n containers:\n - name: document-search\n image: your-registry/document-search:latest\n ports:\n - containerPort: 7860\n env:\n - name: SQL_SERVER_SERVER\n valueFrom:\n secretKeyRef:\n name: app-secrets\n key: sql-server\n - name: SQL_SERVER_DATABASE\n valueFrom:\n secretKeyRef:\n name: app-secrets\n key: sql-database\n - name: JWT_SECRET_KEY\n valueFrom:\n secretKeyRef:\n name: app-secrets\n key: jwt-secret\n volumeMounts:\n - name: storage\n mountPath: /app/storage_faiss\n volumes:\n - name: storage\n persistentVolumeClaim:\n claimName: document-search-storage\n```\n\n---\n\n## ๐Ÿ”’ Security Configuration\n\n### HTTPS Configuration\n\n**For Production with SSL:**\n```python\n# In main.py\nimport uvicorn\nimport ssl\n\nif __name__ == \"__main__\":\n port = int(os.environ.get(\"PORT\", 7860))\n \n if os.getenv(\"DEPLOYMENT_ENV\") == \"production\":\n # Configure SSL\n ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)\n ssl_context.load_cert_chain(\n certfile=\"path/to/certificate.crt\",\n keyfile=\"path/to/private.key\"\n )\n \n uvicorn.run(\n \"main:app\",\n host=\"0.0.0.0\",\n port=port,\n ssl_context=ssl_context\n )\n else:\n uvicorn.run(\"main:app\", host=\"0.0.0.0\", port=port)\n```\n\n### CORS Configuration\n\n```python\n# In main.py or backend_app.py\nfrom fastapi.middleware.cors import CORSMiddleware\n\napp.add_middleware(\n CORSMiddleware,\n allow_origins=[\"https://yourdomain.com\"], # Update with your domain\n allow_credentials=True,\n allow_methods=[\"GET\", \"POST\"],\n allow_headers=[\"*\"],\n)\n```\n\n### Rate Limiting Configuration\n\n```python\n# Optional: Add rate limiting\nfrom slowapi import Limiter, _rate_limit_exceeded_handler\nfrom slowapi.util import get_remote_address\n\nlimiter = Limiter(key_func=get_remote_address)\napp.state.limiter = limiter\napp.add_exception_handler(RateLimitExceeded, _rate_limit_exceeded_handler)\n\n# Apply to specific endpoints\n@app.post(\"/login\")\n@limiter.limit(\"5/minute\")\nasync def login_user(request: Request, user_credentials: UserLoginRequest):\n # ... existing code\n```\n\n---\n\n## ๐Ÿ“Š Monitoring Configuration\n\n### Logging Configuration\n\n```python\n# In main.py\nimport logging\n\n# Configure logging\nlogging.basicConfig(\n level=logging.INFO if os.getenv(\"DEPLOYMENT_ENV\") == \"production\" else logging.DEBUG,\n format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',\n handlers=[\n logging.FileHandler('app.log'),\n logging.StreamHandler()\n ]\n)\n\nlogger = logging.getLogger(__name__)\n```\n\n### Health Check Configuration\n\n```python\n# Add health check endpoint\n@app.get(\"/health\")\nasync def health_check():\n \"\"\"Health check endpoint.\"\"\"\n return {\n \"status\": \"healthy\",\n \"timestamp\": datetime.utcnow().isoformat(),\n \"version\": \"1.0.0\"\n }\n```\n\n---\n\n## ๐Ÿ”„ Configuration Updates\n\n### Hot Reload Configuration\n\nFor development, enable hot reload:\n```python\nif __name__ == \"__main__\":\n uvicorn.run(\n \"main:app\",\n host=\"0.0.0.0\",\n port=port,\n reload=True if os.getenv(\"DEPLOYMENT_ENV\") == \"development\" else False\n )\n```\n\n### Configuration Refresh\n\nTo update configuration without restart:\n```python\n# Add configuration refresh endpoint (development only)\n@app.post(\"/admin/refresh-config\")\nasync def refresh_config():\n if os.getenv(\"DEPLOYMENT_ENV\") != \"development\":\n raise HTTPException(status_code=404, detail=\"Not found\")\n \n # Reload environment variables\n load_dotenv(override=True)\n \n return {\"status\": \"Configuration refreshed\"}\n```\n\n---\n\n## โœ… Configuration Checklist\n\nBefore deployment, verify:\n\n- [ ] All required environment variables are set\n- [ ] Database connection works\n- [ ] All API keys are valid\n- [ ] JWT secret key is secure (32+ characters)\n- [ ] Deployment environment is set correctly\n- [ ] SSL certificates are configured (production)\n- [ ] CORS settings are appropriate\n- [ ] Logging is configured\n- [ ] Health checks work\n- [ ] Backup procedures are in place\n\n---\n\n## ๐Ÿ†˜ Configuration Troubleshooting\n\n### Common Issues\n\n1. **Database Connection Failed**\n - Check server name and port\n - Verify credentials\n - Check firewall settings\n\n2. **API Key Errors**\n - Verify key format and validity\n - Check API quotas and limits\n - Ensure keys are not expired\n\n3. **JWT Token Issues**\n - Check secret key length\n - Verify token expiration settings\n - Check clock synchronization\n\n4. **CORS Errors**\n - Update allowed origins\n - Check request methods\n - Verify credentials setting\n\nFor more troubleshooting help, see [TROUBLESHOOTING.md](TROUBLESHOOTING.md).\n\n---\n\n**Remember to keep your configuration files secure and never commit sensitive information to version control!**"}}}}