FROM python:3.11-slim WORKDIR /app # Install system deps RUN apt-get update && apt-get install -y \ libpq-dev \ gcc \ libmagic1 \ curl \ && rm -rf /var/lib/apt/lists/* # Install PyTorch CPU first (cached layer) RUN pip install --no-cache-dir torch --index-url https://download.pytorch.org/whl/cpu # Install requirements COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Pre-download the reranker model during build (no cold start!) RUN python -c "from sentence_transformers import CrossEncoder; CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2')" # Environment ENV TOKENIZERS_PARALLELISM=false ENV TRANSFORMERS_CACHE=/app/.cache/huggingface ENV SENTENCE_TRANSFORMERS_HOME=/app/.cache/sentence-transformers COPY . . EXPOSE 8000 CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]