start_embedding_service.sh 1.17 KB
#!/bin/bash
#
# Start Local Embedding Service
#
# This service exposes:
# - POST /embed/text
# - POST /embed/image
#
# Defaults are defined in `embeddings/config.py`
#
set -e

cd "$(dirname "$0")/.."

# Load conda env if available (keep consistent with other scripts)
CONDA_ROOT="${CONDA_ROOT:-/home/tw/miniconda3}"
if [ -f "$CONDA_ROOT/etc/profile.d/conda.sh" ]; then
  source "$CONDA_ROOT/etc/profile.d/conda.sh"
  conda activate searchengine
fi

EMBEDDING_SERVICE_HOST=$(python -c "from embeddings.config import CONFIG; print(CONFIG.HOST)")
EMBEDDING_SERVICE_PORT=$(python -c "from embeddings.config import CONFIG; print(CONFIG.PORT)")

echo "========================================"
echo "Starting Local Embedding Service"
echo "========================================"
echo "Host: ${EMBEDDING_SERVICE_HOST}"
echo "Port: ${EMBEDDING_SERVICE_PORT}"
echo
echo "Tips:"
echo "  - Use a single worker (GPU models cannot be safely duplicated across workers)."
echo "  - Clients can set EMBEDDING_SERVICE_URL=http://localhost:${EMBEDDING_SERVICE_PORT}"
echo

exec python -m uvicorn embeddings.server:app \
  --host "${EMBEDDING_SERVICE_HOST}" \
  --port "${EMBEDDING_SERVICE_PORT}" \
  --workers 1