From ce4cfab92585a5a80cf1c75b9bd9fda459ea63af Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Sat, 6 Jan 2024 00:05:18 +0200 Subject: [PATCH 1/2] feat: Optimized docker image - Removed the re-download of hnsw - Removed build dependencies in final image to reduce size - Added flag for rebuilding hnsw lib from source - Added docs how to build in image with hardware-optimized hnsw --- Dockerfile | 21 ++++++++----------- bin/docker_entrypoint.sh | 2 -- examples/advanced/hadrware-optimized-image.md | 10 +++++++++ 3 files changed, 19 insertions(+), 14 deletions(-) create mode 100644 examples/advanced/hadrware-optimized-image.md diff --git a/Dockerfile b/Dockerfile index 489a6a961bd..f0661d1f4a3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,22 @@ -FROM python:3.10-slim-bookworm as builder - +FROM python:3.11-slim-bookworm AS builder +ARG REBUILD_HNSWLIB RUN apt-get update --fix-missing && apt-get install -y --fix-missing \ build-essential \ gcc \ - g++ && \ - rm -rf /var/lib/apt/lists/* + g++ \ + cmake \ + autoconf && \ + rm -rf /var/lib/apt/lists/* && \ + mkdir /install -RUN mkdir /install WORKDIR /install COPY ./requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade --prefix="/install" -r requirements.txt +RUN if [ "$REBUILD_HNSWLIB" = "true" ] ;pip install --no-binary :all: --force-reinstall --no-cache-dir --prefix="/install" chroma-hnswlib; fi -FROM python:3.10-slim-bookworm as final - -RUN apt-get update --fix-missing && apt-get install -y --fix-missing \ - build-essential \ - gcc \ - g++ && \ - rm -rf /var/lib/apt/lists/* +FROM python:3.11-slim-bookworm AS final RUN mkdir /chroma WORKDIR /chroma diff --git a/bin/docker_entrypoint.sh b/bin/docker_entrypoint.sh index b1336b8d455..f1597a0664c 100755 --- a/bin/docker_entrypoint.sh +++ b/bin/docker_entrypoint.sh @@ -1,7 +1,5 @@ #!/bin/bash -echo "Rebuilding hnsw to ensure architecture compatibility" -pip install --force-reinstall --no-cache-dir chroma-hnswlib export IS_PERSISTENT=1 export CHROMA_SERVER_NOFILE=65535 uvicorn chromadb.app:app --workers 1 --host 0.0.0.0 --port 8000 --proxy-headers --log-config chromadb/log_config.yml --timeout-keep-alive 30 diff --git a/examples/advanced/hadrware-optimized-image.md b/examples/advanced/hadrware-optimized-image.md new file mode 100644 index 00000000000..41aad017719 --- /dev/null +++ b/examples/advanced/hadrware-optimized-image.md @@ -0,0 +1,10 @@ +# Building Hardware Optimized ChromaDB Image + +The default Chroma DB image comes with binary distribution of hnsw lib which is not optimized to take advantage of +certain CPU architectures (Intel-based) with AVX support. This can be improved by building an image with hnsw rebuilt +from source. To do that run: + +```bash +docker build -t chroma-test1 --build-arg REBUILD_HNSWLIB=true --no-cache . +``` + From b5cfa9c58790834f0f05abf196cca111afb32412 Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Sat, 6 Jan 2024 12:10:51 +0200 Subject: [PATCH 2/2] fix: Fixed Dockerfile conditional statement. --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f0661d1f4a3..1f90733edbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,7 @@ WORKDIR /install COPY ./requirements.txt requirements.txt RUN pip install --no-cache-dir --upgrade --prefix="/install" -r requirements.txt -RUN if [ "$REBUILD_HNSWLIB" = "true" ] ;pip install --no-binary :all: --force-reinstall --no-cache-dir --prefix="/install" chroma-hnswlib; fi +RUN if [ "$REBUILD_HNSWLIB" = "true" ]; then pip install --no-binary :all: --force-reinstall --no-cache-dir --prefix="/install" chroma-hnswlib; fi FROM python:3.11-slim-bookworm AS final