start_embedding_service.sh
1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/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")/.."
source ./activate.sh
DEFAULT_EMBEDDING_SERVICE_HOST=$(python -c "from embeddings.config import CONFIG; print(CONFIG.HOST)")
DEFAULT_EMBEDDING_SERVICE_PORT=$(python -c "from embeddings.config import CONFIG; print(CONFIG.PORT)")
USE_CLIP_AS_SERVICE=$(python -c "from embeddings.config import CONFIG; print('1' if CONFIG.USE_CLIP_AS_SERVICE else '0')")
EMBEDDING_SERVICE_HOST="${EMBEDDING_HOST:-${DEFAULT_EMBEDDING_SERVICE_HOST}}"
EMBEDDING_SERVICE_PORT="${EMBEDDING_PORT:-${DEFAULT_EMBEDDING_SERVICE_PORT}}"
if [[ "${USE_CLIP_AS_SERVICE}" == "1" ]]; then
if ! python - <<'PY'
try:
import pkg_resources # noqa: F401
except Exception:
raise SystemExit(1)
PY
then
echo "ERROR: clip-as-service image embedding requires pkg_resources, but current venv is missing it." >&2
echo "Fix:" >&2
echo " python -m pip install 'setuptools<82'" >&2
echo "Then restart: ./scripts/start_embedding_service.sh" >&2
exit 1
fi
fi
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