| FROM python:3.12-slim | |
| WORKDIR /app | |
| # Install system dependencies for sentence-transformers + llama-cpp + SSL | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| build-essential gcc g++ cmake ca-certificates openssl && \ | |
| rm -rf /var/lib/apt/lists/* | |
| # Copy requirements | |
| COPY requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy app | |
| COPY . . | |
| # Pre-download bge-m3 + build FAISS index from KB at build time | |
| # (single RUN layer so the model cache is reused) | |
| RUN python -c "from sentence_transformers import SentenceTransformer; SentenceTransformer('BAAI/bge-m3', trust_remote_code=True)" && \ | |
| python precompute_embeddings.py | |
| # Download Llama 3.2 3B GGUF at build time | |
| RUN mkdir -p /app/models && \ | |
| python -c "from huggingface_hub import hf_hub_download; hf_hub_download('QuantFactory/Llama-3.2-3B-Instruct-GGUF', 'Llama-3.2-3B-Instruct.Q4_K_M.gguf', local_dir='/app/models')" | |
| # Default path for local LLM (can be overridden by env) | |
| ENV PORT=7860 | |
| ENV LLAMA_MODEL_PATH=/app/models/Llama-3.2-3B-Instruct.Q4_K_M.gguf | |
| CMD ["python", "server.py"] | |