Skip to content

Commit

Permalink
Made onxxrutime an optional dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
mangin committed Aug 25, 2024
1 parent 3b096c0 commit 99e186a
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/actions/python/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ runs:
cache: "pip"
cache-dependency-path: "requirements*.txt"
- name: Install test dependencies
run: python -m pip install -r requirements.txt && python -m pip install -r requirements_dev.txt
run: python -m pip install -r requirements.txt && python -m pip install -r requirements.txt && python -m pip install -r requirements_dev.txt
shell: bash
- name: Upgrade SQLite
run: python bin/windows_upgrade_sqlite.py
Expand Down
1 change: 1 addition & 0 deletions DEVELOP.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and dev requirements:
python3 -m venv venv # Only need to do this once
source venv/bin/activate # Do this each time you use a new shell for the project
pip install -r requirements.txt
pip install -r requirements_optional.txt
pip install -r requirements_dev.txt
pre-commit install # install the precommit hooks
```
Expand Down
2 changes: 2 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ RUN apt-get update --fix-missing && apt-get install -y --fix-missing \
WORKDIR /install

COPY ./requirements.txt requirements.txt
COPY ./requirements_optional.txt requirements_optional.txt

RUN pip install --no-cache-dir --upgrade --prefix="/install" -r requirements.txt
RUN pip install --no-cache-dir --upgrade --prefix="/install" -r requirements_optional.txt
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
Expand Down
38 changes: 38 additions & 0 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
FROM python:3.11-alpine AS builder
ARG REBUILD_HNSWLIB
RUN apk add build-base && \
rm -rf /var/lib/apt/lists/* && \
mkdir /install

WORKDIR /install

COPY ./requirements.txt requirements.txt
# COPY ./requirements_optional.txt requirements_optional.txt onxxruntime doesn't support alpine T_T

RUN pip install --no-cache-dir --upgrade --prefix="/install" -r requirements.txt
# RUN pip install --no-cache-dir --upgrade --prefix="/install" -r requirements_optional.txt onxxrutime doesn't support alpoine T_T
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-alpine AS final

RUN mkdir /chroma
WORKDIR /chroma

COPY --from=builder /install /usr/local
COPY ./bin/docker_entrypoint.sh /docker_entrypoint.sh
COPY ./ /chroma

RUN apk add curl libstdc++ && \
chmod +x /docker_entrypoint.sh && \
rm -rf /var/lib/apt/lists/*

ENV CHROMA_HOST_ADDR "0.0.0.0"
ENV CHROMA_HOST_PORT 8000
ENV CHROMA_WORKERS 1
ENV CHROMA_LOG_CONFIG "chromadb/log_config.yml"
ENV CHROMA_TIMEOUT_KEEP_ALIVE 30

EXPOSE 8000

ENTRYPOINT ["/bin/sh", "/docker_entrypoint.sh"]
CMD [ "--workers ${CHROMA_WORKERS} --host ${CHROMA_HOST_ADDR} --port ${CHROMA_HOST_PORT} --proxy-headers --log-config ${CHROMA_LOG_CONFIG} --timeout-keep-alive ${CHROMA_TIMEOUT_KEEP_ALIVE}"]
2 changes: 2 additions & 0 deletions Dockerfile.windows
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tl
WORKDIR C:\\chroma

COPY ./requirements.txt requirements.txt
COPY ./requirements_optional.txt requirements_optional.txt

RUN pip install --no-cache-dir --upgrade -r requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements_optional.txt
RUN if ($env:REBUILD_HNSWLIB -eq 'true') { pip install --no-binary :all: --force-reinstall --no-cache-dir chroma-hnswlib }

COPY ./bin/docker_entrypoint.ps1 C:\\docker_entrypoint.ps1
Expand Down
2 changes: 1 addition & 1 deletion Tiltfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ docker_build(
docker_build(
'local:frontend-service',
'.',
only=['chromadb/', 'idl/', 'requirements.txt', 'bin/'],
only=['chromadb/', 'idl/', 'requirements.txt', 'requirements_optional.txt' 'bin/'],
dockerfile='./Dockerfile',
ignore=['**/*.pyc', 'chromadb/test/'],
)
Expand Down
10 changes: 10 additions & 0 deletions chromadb/utils/embedding_functions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ def DefaultEmbeddingFunction() -> Optional[EmbeddingFunction[Documents]]:
if is_thin_client:
return None
else:
# Onxx doesn't support all operation systems.
# For example Onxx doesn't support alpine
has_onnxruntime = False
try:
self.ort = importlib.import_module("onnxruntime")
has_onnxruntime = True
except ImportError:
pass
if not has_onnxruntime:
return None
return cast(
EmbeddingFunction[Documents],
# This is implicitly imported above
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dependencies = [
'numpy >= 1.22.5, < 2.0.0',
'posthog >= 2.4.0',
'typing_extensions >= 4.5.0',
'onnxruntime >= 1.14.1',
'opentelemetry-api>=1.2.0',
'opentelemetry-exporter-otlp-proto-grpc>=1.2.0',
'opentelemetry-instrumentation-fastapi>=0.41b0',
Expand All @@ -46,6 +45,9 @@ dependencies = [
'rich>=10.11.0',
]

[project.optional-dependencies]
onnx = ["onnxruntime >= 1.14.1"]

[tool.black]
line-length = 88
required-version = "23.3.0" # Black will refuse to run if it's not this version.
Expand Down
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ importlib-resources
kubernetes>=28.1.0
mmh3>=4.0.1
numpy>=1.22.5, <2.0.0
onnxruntime>=1.14.1
opentelemetry-api>=1.2.0
opentelemetry-exporter-otlp-proto-grpc>=1.24.0
opentelemetry-instrumentation-fastapi>=0.41b0
Expand Down
1 change: 1 addition & 0 deletions requirements_optional.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
onnxruntime>=1.14.1

0 comments on commit 99e186a

Please sign in to comment.