cembedding 0.7.0__tar.gz → 0.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- cembedding-0.9.0/.dockerignore +23 -0
- cembedding-0.9.0/.github/workflows/ci.yml +161 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/.github/workflows/publish.yml +25 -5
- cembedding-0.9.0/Dockerfile +112 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/PKG-INFO +93 -4
- {cembedding-0.7.0 → cembedding-0.9.0}/README.md +91 -3
- {cembedding-0.7.0 → cembedding-0.9.0}/cembedding/__init__.py +1 -1
- {cembedding-0.7.0 → cembedding-0.9.0}/cembedding/server.py +396 -13
- cembedding-0.9.0/cloto-connector.json +143 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/pyproject.toml +11 -2
- {cembedding-0.7.0 → cembedding-0.9.0}/skills/cembedding/SKILL.md +3 -1
- cembedding-0.9.0/tests/test_capabilities.py +367 -0
- cembedding-0.9.0/tests/test_http_bind.py +141 -0
- cembedding-0.9.0/tests/test_token_info.py +257 -0
- cembedding-0.9.0/tests/test_version_surface.py +52 -0
- cembedding-0.7.0/.github/workflows/ci.yml +0 -26
- cembedding-0.7.0/cloto-connector.json +0 -103
- {cembedding-0.7.0 → cembedding-0.9.0}/.github/ISSUE_TEMPLATE/bug_report.yml +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/.github/ISSUE_TEMPLATE/config.yml +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/.github/ISSUE_TEMPLATE/feature_request.yml +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/.gitignore +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/LICENSE +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/cembedding/__main__.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/cembedding/_vendored_mcp_common/__init__.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/cembedding/_vendored_mcp_common/mcp_utils.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/cembedding/_vendored_mcp_common/validation.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/cembedding/auth.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/cembedding/download_model.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/cembedding/sidecar.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/conftest.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/docs/CONTIGUOUS_SIDECAR_DESIGN.md +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/scripts/backfill_embedding_index.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/scripts/bench_sidecar_startup.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/server.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/tests/test_auth.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/tests/test_backfill.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/tests/test_batch_coalescing.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/tests/test_model_variants.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/tests/test_onnx_padding.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/tests/test_ort_session_options.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/tests/test_sidecar.py +0 -0
- {cembedding-0.7.0 → cembedding-0.9.0}/tests/test_vector_index.py +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# What the build stage is allowed to read.
|
|
2
|
+
#
|
|
3
|
+
# An allowlist, not a list of exclusions. A denylist fails silently in the
|
|
4
|
+
# expensive direction: a directory added to the repository later is copied into
|
|
5
|
+
# the build context by default, and nobody notices until the image is large or
|
|
6
|
+
# something private is inside it. This repository has a `data/` directory that a
|
|
7
|
+
# developer's model download fills with a gigabyte of weights, and a `.venv`
|
|
8
|
+
# beside it -- neither is an input to the wheel.
|
|
9
|
+
#
|
|
10
|
+
# The admitted set is exactly what building the wheel reads: the package and the
|
|
11
|
+
# three files hatchling opens (metadata, readme, licence).
|
|
12
|
+
*
|
|
13
|
+
|
|
14
|
+
!cembedding/
|
|
15
|
+
!pyproject.toml
|
|
16
|
+
!README.md
|
|
17
|
+
!LICENSE
|
|
18
|
+
|
|
19
|
+
# Re-excluded after the directory above is admitted: compiled artifacts from a
|
|
20
|
+
# host interpreter are not inputs, and a stale one can shadow the source it was
|
|
21
|
+
# compiled from.
|
|
22
|
+
**/__pycache__/
|
|
23
|
+
**/*.pyc
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
push:
|
|
6
|
+
branches: [master, main]
|
|
7
|
+
|
|
8
|
+
jobs:
|
|
9
|
+
test:
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
strategy:
|
|
12
|
+
matrix:
|
|
13
|
+
python-version: ["3.10", "3.12"]
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v4
|
|
16
|
+
- uses: actions/setup-python@v5
|
|
17
|
+
with:
|
|
18
|
+
python-version: ${{ matrix.python-version }}
|
|
19
|
+
- name: Install
|
|
20
|
+
run: pip install -e ".[dev]"
|
|
21
|
+
- name: Lint
|
|
22
|
+
run: |
|
|
23
|
+
ruff check cembedding/ tests/ scripts/
|
|
24
|
+
ruff format --check cembedding/ tests/ scripts/
|
|
25
|
+
- name: Test
|
|
26
|
+
run: pytest -q
|
|
27
|
+
|
|
28
|
+
container:
|
|
29
|
+
# The image is built and run here rather than linted. A Dockerfile that no
|
|
30
|
+
# gate executes is a file that agrees with itself: the sibling memory server
|
|
31
|
+
# shipped one for five months whose EXPOSE named a port the process never
|
|
32
|
+
# bound, and nothing said so because nothing ever started it.
|
|
33
|
+
#
|
|
34
|
+
# Every check below is offline once the image is built. The providers that
|
|
35
|
+
# need weights download them from a model hub on first use, so a gate that
|
|
36
|
+
# exercised one would go red for reasons that have nothing to do with the
|
|
37
|
+
# commit; api_openai needs no weights and no reachable API to start, which
|
|
38
|
+
# is what these questions are about.
|
|
39
|
+
runs-on: ubuntu-latest
|
|
40
|
+
timeout-minutes: 15
|
|
41
|
+
env:
|
|
42
|
+
IMAGE: cembedding:ci
|
|
43
|
+
COMMON: -e EMBEDDING_PROVIDER=api_openai -e EMBEDDING_API_KEY=unused -e EMBEDDING_INDEX_ENABLED=false
|
|
44
|
+
steps:
|
|
45
|
+
- uses: actions/checkout@v4
|
|
46
|
+
|
|
47
|
+
- name: Build the image
|
|
48
|
+
run: docker build -t "$IMAGE" .
|
|
49
|
+
|
|
50
|
+
- name: The build context carries only the wheel's inputs
|
|
51
|
+
# .dockerignore is an allowlist, and an allowlist that stops matching
|
|
52
|
+
# fails by admitting more rather than by erroring: this repository holds
|
|
53
|
+
# a `data/` directory that a model download fills with a gigabyte of
|
|
54
|
+
# weights, and a `.venv` beside it.
|
|
55
|
+
#
|
|
56
|
+
# Reading the built image cannot see that. Every COPY above names its
|
|
57
|
+
# source, so the image stays clean whatever the context holds -- deleting
|
|
58
|
+
# .dockerignore entirely leaves an image-side check green, which was
|
|
59
|
+
# measured before this step was written this way. The allowlist decides
|
|
60
|
+
# the context, so the context is what is read here, by building a
|
|
61
|
+
# throwaway image that copies all of it.
|
|
62
|
+
#
|
|
63
|
+
# The comparison is exact rather than a search for known-bad names:
|
|
64
|
+
# admitting one more path should have to be a deliberate edit here, and
|
|
65
|
+
# a list of things to look for only ever finds what someone thought of.
|
|
66
|
+
run: |
|
|
67
|
+
set -uo pipefail
|
|
68
|
+
printf 'FROM busybox\nCOPY . /ctx\n' > "$RUNNER_TEMP/context.Dockerfile"
|
|
69
|
+
docker build -q -f "$RUNNER_TEMP/context.Dockerfile" -t cembedding-context:ci .
|
|
70
|
+
admitted=$(docker run --rm cembedding-context:ci sh -c 'ls -A /ctx' | LC_ALL=C sort | tr '\n' ' ')
|
|
71
|
+
expected="LICENSE README.md cembedding pyproject.toml "
|
|
72
|
+
echo "context admits: $admitted"
|
|
73
|
+
if [ "$admitted" != "$expected" ]; then
|
|
74
|
+
echo "::error::the build context is [$admitted], expected [$expected] — .dockerignore admitted more (or the wheel's inputs changed and this line did not)"
|
|
75
|
+
exit 1
|
|
76
|
+
fi
|
|
77
|
+
|
|
78
|
+
- name: A published port reaches the endpoint
|
|
79
|
+
# The question a user asks first, and the one the image exists to answer
|
|
80
|
+
# yes to: the server's own default binds the container's loopback, where
|
|
81
|
+
# a published port forwards to a socket nothing is listening on.
|
|
82
|
+
# 405 is the wanted answer -- /embed is POST-only, so a GET that is
|
|
83
|
+
# answered at all proves the socket is bound and the app is behind it.
|
|
84
|
+
#
|
|
85
|
+
# The status is captured with `) || code=000` rather than `|| echo 000`
|
|
86
|
+
# inside the substitution: a curl that cannot connect prints its own
|
|
87
|
+
# "000" first, so the appended one makes "000000" -- a value no server
|
|
88
|
+
# returns, which is not equal to "000" either, so the wait loop exits on
|
|
89
|
+
# the first attempt and the step fails while the container is merely
|
|
90
|
+
# still starting.
|
|
91
|
+
run: |
|
|
92
|
+
set -uo pipefail
|
|
93
|
+
docker run -d --name reachable -p 18401:8401 $COMMON "$IMAGE"
|
|
94
|
+
code=000
|
|
95
|
+
for _ in $(seq 1 40); do
|
|
96
|
+
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 2 http://127.0.0.1:18401/embed) || code=000
|
|
97
|
+
[ "$code" != "000" ] && break
|
|
98
|
+
sleep 0.5
|
|
99
|
+
done
|
|
100
|
+
docker logs reachable
|
|
101
|
+
docker rm -f reachable >/dev/null
|
|
102
|
+
if [ "$code" != "405" ]; then
|
|
103
|
+
echo "::error::GET /embed through the published port answered $code, expected 405"
|
|
104
|
+
exit 1
|
|
105
|
+
fi
|
|
106
|
+
|
|
107
|
+
- name: Forcing the address back to loopback makes it unreachable
|
|
108
|
+
# The control for the check above. Without it, a published port that
|
|
109
|
+
# answers proves nothing about the bind: it would answer just as well if
|
|
110
|
+
# some other change had made the port reachable. Same image, one
|
|
111
|
+
# variable moved, opposite outcome.
|
|
112
|
+
run: |
|
|
113
|
+
set -uo pipefail
|
|
114
|
+
docker run -d --name loopback -p 18402:8401 -e EMBEDDING_HTTP_HOST=127.0.0.1 $COMMON "$IMAGE"
|
|
115
|
+
sleep 8
|
|
116
|
+
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 3 http://127.0.0.1:18402/embed) || code=000
|
|
117
|
+
running=$(docker inspect -f '{{.State.Running}}' loopback)
|
|
118
|
+
docker rm -f loopback >/dev/null
|
|
119
|
+
if [ "$code" != "000" ]; then
|
|
120
|
+
echo "::error::the loopback-bound container answered $code through a published port"
|
|
121
|
+
exit 1
|
|
122
|
+
fi
|
|
123
|
+
if [ "$running" != "true" ]; then
|
|
124
|
+
echo "::error::the loopback-bound container is not running, so the refusal above proves nothing about the bind"
|
|
125
|
+
exit 1
|
|
126
|
+
fi
|
|
127
|
+
|
|
128
|
+
- name: It survives a run with no interactive stdin
|
|
129
|
+
# Under the stdio transport the process shuts down on stdin EOF, which a
|
|
130
|
+
# container without -i delivers at once. The failure is silent -- the
|
|
131
|
+
# endpoint logs that it started and the container exits 0 -- so this
|
|
132
|
+
# asks the only question that separates the two: is it still running.
|
|
133
|
+
run: |
|
|
134
|
+
set -uo pipefail
|
|
135
|
+
docker run -d --name survives $COMMON "$IMAGE"
|
|
136
|
+
sleep 10
|
|
137
|
+
running=$(docker inspect -f '{{.State.Running}}' survives)
|
|
138
|
+
code=$(docker inspect -f '{{.State.ExitCode}}' survives)
|
|
139
|
+
docker logs survives
|
|
140
|
+
docker rm -f survives >/dev/null
|
|
141
|
+
if [ "$running" != "true" ]; then
|
|
142
|
+
echo "::error::the container exited (status $code) without an interactive stdin"
|
|
143
|
+
exit 1
|
|
144
|
+
fi
|
|
145
|
+
|
|
146
|
+
- name: A configured token is enforced on the published port
|
|
147
|
+
run: |
|
|
148
|
+
set -uo pipefail
|
|
149
|
+
docker run -d --name guarded -p 18403:8401 -e CEMBEDDING_AUTH_TOKEN=probe-token $COMMON "$IMAGE"
|
|
150
|
+
code=000
|
|
151
|
+
for _ in $(seq 1 40); do
|
|
152
|
+
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 2 -X POST http://127.0.0.1:18403/embed \
|
|
153
|
+
-H 'content-type: application/json' -d '{"texts":["x"]}') || code=000
|
|
154
|
+
[ "$code" != "000" ] && break
|
|
155
|
+
sleep 0.5
|
|
156
|
+
done
|
|
157
|
+
docker rm -f guarded >/dev/null
|
|
158
|
+
if [ "$code" != "401" ]; then
|
|
159
|
+
echo "::error::an anonymous POST /embed answered $code with a token configured, expected 401"
|
|
160
|
+
exit 1
|
|
161
|
+
fi
|
|
@@ -60,18 +60,38 @@ jobs:
|
|
|
60
60
|
with:
|
|
61
61
|
enable-cache: true
|
|
62
62
|
|
|
63
|
-
- name: Verify tag version matches
|
|
63
|
+
- name: Verify tag version matches the package version
|
|
64
64
|
run: |
|
|
65
|
-
|
|
65
|
+
# The package version lives in cembedding/__init__.py; pyproject derives
|
|
66
|
+
# it from there (hatch dynamic version), so this is the one place to read.
|
|
67
|
+
package_version=$(sed -nE 's/^__version__ = "(.*)"$/\1/p' cembedding/__init__.py | head -1)
|
|
66
68
|
tag_version="${{ steps.ref.outputs.tag_version }}"
|
|
67
|
-
if [
|
|
68
|
-
echo "::error::
|
|
69
|
+
if [ -z "$package_version" ]; then
|
|
70
|
+
echo "::error::could not read __version__ from cembedding/__init__.py"
|
|
69
71
|
exit 1
|
|
70
72
|
fi
|
|
71
|
-
|
|
73
|
+
if [ "$package_version" != "$tag_version" ]; then
|
|
74
|
+
echo "::error::tag version '$tag_version' does not match package version '$package_version'"
|
|
75
|
+
exit 1
|
|
76
|
+
fi
|
|
77
|
+
echo "version match: $package_version"
|
|
72
78
|
|
|
73
79
|
- name: Build sdist + wheel
|
|
74
80
|
run: uv build
|
|
75
81
|
|
|
82
|
+
- name: Verify the built artifacts carry the tag version
|
|
83
|
+
run: |
|
|
84
|
+
# What gets uploaded is the artifact, not the source file the step above
|
|
85
|
+
# read: this fails if the build backend ever resolves a different version.
|
|
86
|
+
tag_version="${{ steps.ref.outputs.tag_version }}"
|
|
87
|
+
for artifact in "dist/cembedding-${tag_version}-py3-none-any.whl" "dist/cembedding-${tag_version}.tar.gz"; do
|
|
88
|
+
if [ ! -f "$artifact" ]; then
|
|
89
|
+
echo "::error::expected $artifact; built instead:"
|
|
90
|
+
ls -1 dist
|
|
91
|
+
exit 1
|
|
92
|
+
fi
|
|
93
|
+
done
|
|
94
|
+
echo "artifacts match: $(ls -1 dist | tr '\n' ' ')"
|
|
95
|
+
|
|
76
96
|
- name: Publish to PyPI (OIDC Trusted Publishing)
|
|
77
97
|
uses: pypa/gh-action-pypi-publish@release/v1
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# CEmbedding as a container.
|
|
2
|
+
#
|
|
3
|
+
# What this image serves: the REST surface -- /embed, and the index endpoints
|
|
4
|
+
# (/index, /search, /remove, /purge) while the index is enabled -- on 8401,
|
|
5
|
+
# bound to every interface, with the model and the index on a volume.
|
|
6
|
+
#
|
|
7
|
+
# EMBEDDING_HTTP_HOST is the one value this image must override. The server
|
|
8
|
+
# defaults to 127.0.0.1, which inside a container is the container's own
|
|
9
|
+
# loopback: a published port would forward to a socket nothing is listening on,
|
|
10
|
+
# and the symptom is a refused connection that reads like a crash. Binding every
|
|
11
|
+
# interface is not a decision about who may call -- a tunnel or a reverse proxy
|
|
12
|
+
# reaches loopback just as well, which is why the server refuses to treat the
|
|
13
|
+
# bind address as a boundary. Set CEMBEDDING_AUTH_TOKEN before publishing this
|
|
14
|
+
# port anywhere a stranger can reach.
|
|
15
|
+
#
|
|
16
|
+
# The weights are not in the image. An ONNX provider fetches what it needs on
|
|
17
|
+
# first use, so a container started against an empty volume reaches Hugging Face
|
|
18
|
+
# and cannot answer until that download finishes -- half a gigabyte for bge-m3,
|
|
19
|
+
# with no progress visible to whoever is waiting on the port. Fill the volume
|
|
20
|
+
# once, before anything depends on the service:
|
|
21
|
+
#
|
|
22
|
+
# docker run --rm -v cembedding-data:/data <image> \
|
|
23
|
+
# cembedding-download-model --model jina-v5-nano
|
|
24
|
+
#
|
|
25
|
+
# ONNX_MODEL_DIR below points both that command and the server at the same
|
|
26
|
+
# directory, so the model a run downloads is the model the next run loads. One
|
|
27
|
+
# model per volume: the variable names a directory, not a collection.
|
|
28
|
+
#
|
|
29
|
+
# Baking the weights in instead would trade a small image for a gigabyte-scale
|
|
30
|
+
# one and freeze a choice the environment is supposed to make.
|
|
31
|
+
|
|
32
|
+
FROM python:3.12-slim AS build
|
|
33
|
+
|
|
34
|
+
WORKDIR /src
|
|
35
|
+
|
|
36
|
+
# Only the wheel's inputs; .dockerignore admits nothing else. Copied as separate
|
|
37
|
+
# layers from the install so editing the package does not re-resolve the build
|
|
38
|
+
# backend.
|
|
39
|
+
COPY pyproject.toml README.md LICENSE ./
|
|
40
|
+
COPY cembedding/ ./cembedding/
|
|
41
|
+
|
|
42
|
+
# The wheel, not the source tree. The runtime stage installs this artifact, so
|
|
43
|
+
# the container runs what a `pip install cembedding` user runs rather than a
|
|
44
|
+
# second copy of the repository that happens to sit on sys.path -- the two
|
|
45
|
+
# diverge exactly when the packaging is wrong, which is the case worth catching.
|
|
46
|
+
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /wheels .
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# 3.12 rather than the newest release: it is one of the two versions CI runs the
|
|
50
|
+
# suite on, and onnxruntime publishes wheels for it on every platform this image
|
|
51
|
+
# is built for. A base image nothing tests is a dependency resolution waiting to
|
|
52
|
+
# happen at `docker build` time.
|
|
53
|
+
FROM python:3.12-slim
|
|
54
|
+
|
|
55
|
+
# A fixed uid, because it outlives the image. A named volume inherits ownership
|
|
56
|
+
# from the image and needs nothing; a bind-mounted host directory does not, so
|
|
57
|
+
# the host side has to be writable by this uid (or `--user "$(id -u)"` passed).
|
|
58
|
+
# Naming the number here is what makes that instruction possible to follow.
|
|
59
|
+
RUN useradd --system --create-home --uid 10001 cembedding
|
|
60
|
+
|
|
61
|
+
# The onnx extra, because on-device inference is the reason to run this next to
|
|
62
|
+
# the service that calls it; the extra is named rather than its contents listed,
|
|
63
|
+
# so the image cannot drift from what `pip install "cembedding[onnx]"` means.
|
|
64
|
+
COPY --from=build /wheels/*.whl /tmp/
|
|
65
|
+
RUN pip install --no-cache-dir "$(echo /tmp/*.whl)[onnx]" && rm -rf /tmp/*.whl
|
|
66
|
+
|
|
67
|
+
# 8401 is the server's own default REST port; it is repeated here so that
|
|
68
|
+
# changing one without the other cannot go unnoticed, and so EXPOSE below names
|
|
69
|
+
# a port something actually binds.
|
|
70
|
+
ENV EMBEDDING_HTTP_HOST=0.0.0.0 \
|
|
71
|
+
EMBEDDING_HTTP_PORT=8401 \
|
|
72
|
+
EMBEDDING_INDEX_DB_PATH=/data/embedding_index.db \
|
|
73
|
+
ONNX_MODEL_DIR=/data/model
|
|
74
|
+
|
|
75
|
+
# Created before the volume is declared, so a fresh named volume inherits this
|
|
76
|
+
# ownership instead of arriving as root-owned and unwritable.
|
|
77
|
+
RUN install -d -o cembedding -g cembedding /data
|
|
78
|
+
VOLUME ["/data"]
|
|
79
|
+
|
|
80
|
+
USER cembedding
|
|
81
|
+
WORKDIR /home/cembedding
|
|
82
|
+
EXPOSE 8401
|
|
83
|
+
|
|
84
|
+
# Liveness only, and deliberately not a claim about health: it asks whether the
|
|
85
|
+
# port is bound and the application answers HTTP. Any status counts, because an
|
|
86
|
+
# authenticated deployment answers 401 to an anonymous probe and a 401 is a
|
|
87
|
+
# served response; a GET on a POST-only route answers 405, which is one too.
|
|
88
|
+
# What the probe cannot tell you is whether the model finished loading -- that
|
|
89
|
+
# is what a first /embed call answers, and it needs a request body this must not
|
|
90
|
+
# invent. http.client rather than urllib: it returns the status instead of
|
|
91
|
+
# raising on 4xx, so the probe needs no exception handling, while a refused
|
|
92
|
+
# connection still raises and exits non-zero.
|
|
93
|
+
HEALTHCHECK --interval=30s --timeout=5s --start-period=30s --retries=3 \
|
|
94
|
+
CMD ["python", "-c", "import os,http.client;c=http.client.HTTPConnection('127.0.0.1',int(os.environ.get('EMBEDDING_HTTP_PORT','8401')),timeout=4);c.request('GET','/embed');print(c.getresponse().status)"]
|
|
95
|
+
|
|
96
|
+
LABEL org.opencontainers.image.title="CEmbedding" \
|
|
97
|
+
org.opencontainers.image.description="Local-first embedding server: /embed plus a persistent vector index (MCP)" \
|
|
98
|
+
org.opencontainers.image.source="https://github.com/Cloto-dev/CEmbedding" \
|
|
99
|
+
org.opencontainers.image.licenses="MIT"
|
|
100
|
+
|
|
101
|
+
# Why the command is not just `cembedding`: under the default stdio transport
|
|
102
|
+
# the MCP loop owns the foreground and the REST endpoint runs behind it, so the
|
|
103
|
+
# process shuts down when stdin reaches EOF. A container started without an
|
|
104
|
+
# interactive stdin gets EOF immediately -- the endpoint starts, logs that it
|
|
105
|
+
# started, and the container exits 0, which reads as a clean run rather than as
|
|
106
|
+
# a service that never served. Holding stdin open from a process the shell
|
|
107
|
+
# leaves behind keeps the REST surface up, and `exec` keeps the server itself as
|
|
108
|
+
# PID 1 so it receives the stop signal directly.
|
|
109
|
+
#
|
|
110
|
+
# Overriding this command (`docker run <image> cembedding-download-model ...`)
|
|
111
|
+
# is the intended way to run the one-shot tools, which want an ordinary exit.
|
|
112
|
+
CMD ["bash", "-c", "exec cembedding < <(sleep infinity)"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: cembedding
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: Local-first embedding server: vector generation + index/search over HTTP (ONNX on-device or API providers). The reference /embed server for CPersona.
|
|
5
5
|
Project-URL: Homepage, https://github.com/Cloto-dev/CEmbedding
|
|
6
6
|
Project-URL: Repository, https://github.com/Cloto-dev/CEmbedding
|
|
@@ -31,6 +31,7 @@ Provides-Extra: dev
|
|
|
31
31
|
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
32
32
|
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
33
33
|
Requires-Dist: ruff>=0.4.0; extra == 'dev'
|
|
34
|
+
Requires-Dist: tokenizers>=0.15.0; extra == 'dev'
|
|
34
35
|
Provides-Extra: mlx
|
|
35
36
|
Requires-Dist: mlx-embeddings>=0.1.0; extra == 'mlx'
|
|
36
37
|
Requires-Dist: mlx>=0.18.0; extra == 'mlx'
|
|
@@ -50,6 +51,7 @@ Description-Content-Type: text/markdown
|
|
|
50
51
|
|
|
51
52
|
Vector embeddings over a tiny HTTP contract.
|
|
52
53
|
On-device ONNX or any OpenAI-compatible API. The reference `/embed` server for [CPersona](https://github.com/Cloto-dev/CPersona).
|
|
54
|
+
Also available as the CEmbedding MCP embedding server (stdio and Streamable HTTP).
|
|
53
55
|
|
|
54
56
|
[](https://github.com/Cloto-dev/CEmbedding/blob/main/LICENSE)
|
|
55
57
|
[]()
|
|
@@ -74,6 +76,58 @@ Request: { "texts": ["string", ...] } # non-empty array, max 10
|
|
|
74
76
|
Response: { "embeddings": [[float, ...], ...], "dimensions": <int> }
|
|
75
77
|
```
|
|
76
78
|
|
|
79
|
+
### Where the vector stops seeing a text
|
|
80
|
+
|
|
81
|
+
A model embeds only the first `window` tokens of a text; the rest is stored by the
|
|
82
|
+
caller but invisible to vector search. How many characters that is depends on the
|
|
83
|
+
text — for one window it varies by more than a factor of two — so the server reports
|
|
84
|
+
it instead of leaving each client to guess.
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
POST /embed { "texts": [...], "token_info": true } # adds "token_info" to the response above
|
|
88
|
+
POST /count_tokens { "texts": [...] } # the same report, without running the model
|
|
89
|
+
Response entry: { "count": <int>, "window": <int>, "truncated": <bool>, "window_end_char": <int> }
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
- `count` and `window` both include the tokenizer's special tokens.
|
|
93
|
+
- `window_end_char` is a character offset: `text[:window_end_char]` is what the vector
|
|
94
|
+
represents, and it equals `len(text)` when nothing was cut.
|
|
95
|
+
- `token_info` is `null` when the provider cannot see its own tokens (`api_openai`,
|
|
96
|
+
`mlx_bge_m3`). Read that as unknown, never as "fits".
|
|
97
|
+
- Without `"token_info": true`, `/embed` answers exactly as it did before the field existed.
|
|
98
|
+
- The counting tokenizer loads on the first request that needs it (about 29 MiB resident
|
|
99
|
+
for jina-v5-nano), so a server that is never asked pays nothing.
|
|
100
|
+
|
|
101
|
+
### Which backend produced a vector
|
|
102
|
+
|
|
103
|
+
A caller stores vectors and comes back later to ask whether a stored one may still be
|
|
104
|
+
compared with a fresh one. Over `/embed` it cannot tell: it posts texts and the server
|
|
105
|
+
picks the model, so a client that falls back to a configured default reads two different
|
|
106
|
+
models as one. `/capabilities` answers what actually ran.
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
GET /capabilities
|
|
110
|
+
Response: { "identity": { "provider": ..., "model": ..., "dimensions": <int>,
|
|
111
|
+
"window": <int>, "pooling": ..., "normalized": <bool>,
|
|
112
|
+
"digests": { "graph": ..., "tokenizer": ..., "weights": ... } },
|
|
113
|
+
"incomplete": [ ... ],
|
|
114
|
+
"fingerprint": "1:<hex>" | null }
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
- `fingerprint` is the one value to store beside a vector. Two vectors may be compared
|
|
118
|
+
when their fingerprints are equal.
|
|
119
|
+
- It covers everything that moves the numbers: the graph and tokenizer contents, the
|
|
120
|
+
width, the truncation window, the pooling, and the provider. Two precisions of one
|
|
121
|
+
model fingerprint differently; a configured model name cannot tell them apart.
|
|
122
|
+
- `incomplete` names the components this deployment could not establish, and `fingerprint`
|
|
123
|
+
is then `null` — never a shorter fingerprint over the part it knew. A remote API
|
|
124
|
+
(`api_openai`) and the MLX provider report at least their digests as missing, because
|
|
125
|
+
the files that would be hashed are not this process's to read.
|
|
126
|
+
- **`null` means unknown, not unchanged.** A caller that receives it keeps whatever it
|
|
127
|
+
did before this endpoint existed; it must not read a matching default as a matching model.
|
|
128
|
+
- The digest of a model graph is computed once per file state and cached, so the first
|
|
129
|
+
call after a restart pays for reading it and later calls do not.
|
|
130
|
+
|
|
77
131
|
Point any client (e.g. CPersona's `CPERSONA_EMBEDDING_URL` / generic `EMBEDDING_HTTP_URL`) at `http://127.0.0.1:8401/embed`.
|
|
78
132
|
|
|
79
133
|
## Quick Start (on-device ONNX)
|
|
@@ -111,6 +165,40 @@ curl -s http://127.0.0.1:8401/embed \
|
|
|
111
165
|
-d '{"texts":["hello world"]}' | head -c 200
|
|
112
166
|
```
|
|
113
167
|
|
|
168
|
+
## Run it in a container
|
|
169
|
+
|
|
170
|
+
No image is published: build it from this repository, at the revision you mean to run.
|
|
171
|
+
|
|
172
|
+
```bash
|
|
173
|
+
docker build -t cembedding .
|
|
174
|
+
|
|
175
|
+
# Fill the volume once. Left to itself the server downloads the weights on the
|
|
176
|
+
# first request instead -- with the port already accepting connections it cannot
|
|
177
|
+
# yet answer, and no progress visible to whoever is waiting on it.
|
|
178
|
+
docker run --rm -v cembedding-data:/data cembedding \
|
|
179
|
+
cembedding-download-model --model jina-v5-nano
|
|
180
|
+
|
|
181
|
+
docker run -d --name cembedding -p 8401:8401 -v cembedding-data:/data \
|
|
182
|
+
-e EMBEDDING_PROVIDER=onnx_jina_v5_nano \
|
|
183
|
+
-e CEMBEDDING_AUTH_TOKEN="$(openssl rand -hex 32)" \
|
|
184
|
+
cembedding
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
The image sets `EMBEDDING_HTTP_HOST=0.0.0.0`, because inside a container the
|
|
188
|
+
server's default binds the container's own loopback: a published port then
|
|
189
|
+
forwards to a socket nothing is listening on, and the connection is refused in a
|
|
190
|
+
way that reads like a crash. That is a reachability decision and not a security
|
|
191
|
+
one — see [Authentication](#authentication-v062), and set a token whenever the
|
|
192
|
+
port is published.
|
|
193
|
+
|
|
194
|
+
`ONNX_MODEL_DIR` is `/data/model` in the image, so the download command above and
|
|
195
|
+
the server look in the same place. One model per volume: the variable names a
|
|
196
|
+
directory, not a collection.
|
|
197
|
+
|
|
198
|
+
The model and the index live on the `/data` volume, which is what survives the
|
|
199
|
+
container. A bind-mounted host directory has to be writable by uid 10001 (the
|
|
200
|
+
image's user), or the run needs `--user "$(id -u)"`.
|
|
201
|
+
|
|
114
202
|
## Providers
|
|
115
203
|
|
|
116
204
|
Set `EMBEDDING_PROVIDER`:
|
|
@@ -148,6 +236,7 @@ Vectors already indexed with one precision stay usable with another (the mixed-p
|
|
|
148
236
|
|---------|---------|-------------|
|
|
149
237
|
| `EMBEDDING_PROVIDER` | `api_openai` | Provider (see table above) |
|
|
150
238
|
| `EMBEDDING_HTTP_PORT` | `8401` | HTTP port for `/embed` |
|
|
239
|
+
| `EMBEDDING_HTTP_HOST` | `127.0.0.1` | Address `/embed` binds to. Loopback is right for a single host; a container has to bind an address its peers can reach (see [Run it in a container](#run-it-in-a-container)). Moving it decides nothing about who may call — a token does |
|
|
151
240
|
| `EMBEDDING_INDEX_ENABLED` | `true` | Enable the persistent vector index endpoints (`/index`, `/search`, `/remove`, `/purge`) |
|
|
152
241
|
| `EMBEDDING_INDEX_DB_PATH` | `data/embedding_index.db` | SQLite file backing the vector index |
|
|
153
242
|
| `EMBEDDING_SEARCH_BACKEND` | `numpy` | `/search` matmul backend. `numpy` (Accelerate BLAS) or `mlx` (Apple-GPU resident matrix; falls back to numpy when mlx is absent) |
|
|
@@ -192,9 +281,9 @@ cembedding-sidecar build --db data/embedding_index.db # write one now
|
|
|
192
281
|
|
|
193
282
|
## Authentication (v0.6.2)
|
|
194
283
|
|
|
195
|
-
Both HTTP surfaces — the REST endpoints (`/embed`, `/
|
|
196
|
-
`/remove`, `/purge`) and the Streamable HTTP MCP transport — accept
|
|
197
|
-
bearer token:
|
|
284
|
+
Both HTTP surfaces — the REST endpoints (`/embed`, `/count_tokens`, `/capabilities`,
|
|
285
|
+
`/index`, `/search`, `/remove`, `/purge`) and the Streamable HTTP MCP transport — accept
|
|
286
|
+
an inbound bearer token:
|
|
198
287
|
|
|
199
288
|
```bash
|
|
200
289
|
CEMBEDDING_AUTH_TOKEN=$(openssl rand -hex 32)
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
Vector embeddings over a tiny HTTP contract.
|
|
8
8
|
On-device ONNX or any OpenAI-compatible API. The reference `/embed` server for [CPersona](https://github.com/Cloto-dev/CPersona).
|
|
9
|
+
Also available as the CEmbedding MCP embedding server (stdio and Streamable HTTP).
|
|
9
10
|
|
|
10
11
|
[](https://github.com/Cloto-dev/CEmbedding/blob/main/LICENSE)
|
|
11
12
|
[]()
|
|
@@ -30,6 +31,58 @@ Request: { "texts": ["string", ...] } # non-empty array, max 10
|
|
|
30
31
|
Response: { "embeddings": [[float, ...], ...], "dimensions": <int> }
|
|
31
32
|
```
|
|
32
33
|
|
|
34
|
+
### Where the vector stops seeing a text
|
|
35
|
+
|
|
36
|
+
A model embeds only the first `window` tokens of a text; the rest is stored by the
|
|
37
|
+
caller but invisible to vector search. How many characters that is depends on the
|
|
38
|
+
text — for one window it varies by more than a factor of two — so the server reports
|
|
39
|
+
it instead of leaving each client to guess.
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
POST /embed { "texts": [...], "token_info": true } # adds "token_info" to the response above
|
|
43
|
+
POST /count_tokens { "texts": [...] } # the same report, without running the model
|
|
44
|
+
Response entry: { "count": <int>, "window": <int>, "truncated": <bool>, "window_end_char": <int> }
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
- `count` and `window` both include the tokenizer's special tokens.
|
|
48
|
+
- `window_end_char` is a character offset: `text[:window_end_char]` is what the vector
|
|
49
|
+
represents, and it equals `len(text)` when nothing was cut.
|
|
50
|
+
- `token_info` is `null` when the provider cannot see its own tokens (`api_openai`,
|
|
51
|
+
`mlx_bge_m3`). Read that as unknown, never as "fits".
|
|
52
|
+
- Without `"token_info": true`, `/embed` answers exactly as it did before the field existed.
|
|
53
|
+
- The counting tokenizer loads on the first request that needs it (about 29 MiB resident
|
|
54
|
+
for jina-v5-nano), so a server that is never asked pays nothing.
|
|
55
|
+
|
|
56
|
+
### Which backend produced a vector
|
|
57
|
+
|
|
58
|
+
A caller stores vectors and comes back later to ask whether a stored one may still be
|
|
59
|
+
compared with a fresh one. Over `/embed` it cannot tell: it posts texts and the server
|
|
60
|
+
picks the model, so a client that falls back to a configured default reads two different
|
|
61
|
+
models as one. `/capabilities` answers what actually ran.
|
|
62
|
+
|
|
63
|
+
```
|
|
64
|
+
GET /capabilities
|
|
65
|
+
Response: { "identity": { "provider": ..., "model": ..., "dimensions": <int>,
|
|
66
|
+
"window": <int>, "pooling": ..., "normalized": <bool>,
|
|
67
|
+
"digests": { "graph": ..., "tokenizer": ..., "weights": ... } },
|
|
68
|
+
"incomplete": [ ... ],
|
|
69
|
+
"fingerprint": "1:<hex>" | null }
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- `fingerprint` is the one value to store beside a vector. Two vectors may be compared
|
|
73
|
+
when their fingerprints are equal.
|
|
74
|
+
- It covers everything that moves the numbers: the graph and tokenizer contents, the
|
|
75
|
+
width, the truncation window, the pooling, and the provider. Two precisions of one
|
|
76
|
+
model fingerprint differently; a configured model name cannot tell them apart.
|
|
77
|
+
- `incomplete` names the components this deployment could not establish, and `fingerprint`
|
|
78
|
+
is then `null` — never a shorter fingerprint over the part it knew. A remote API
|
|
79
|
+
(`api_openai`) and the MLX provider report at least their digests as missing, because
|
|
80
|
+
the files that would be hashed are not this process's to read.
|
|
81
|
+
- **`null` means unknown, not unchanged.** A caller that receives it keeps whatever it
|
|
82
|
+
did before this endpoint existed; it must not read a matching default as a matching model.
|
|
83
|
+
- The digest of a model graph is computed once per file state and cached, so the first
|
|
84
|
+
call after a restart pays for reading it and later calls do not.
|
|
85
|
+
|
|
33
86
|
Point any client (e.g. CPersona's `CPERSONA_EMBEDDING_URL` / generic `EMBEDDING_HTTP_URL`) at `http://127.0.0.1:8401/embed`.
|
|
34
87
|
|
|
35
88
|
## Quick Start (on-device ONNX)
|
|
@@ -67,6 +120,40 @@ curl -s http://127.0.0.1:8401/embed \
|
|
|
67
120
|
-d '{"texts":["hello world"]}' | head -c 200
|
|
68
121
|
```
|
|
69
122
|
|
|
123
|
+
## Run it in a container
|
|
124
|
+
|
|
125
|
+
No image is published: build it from this repository, at the revision you mean to run.
|
|
126
|
+
|
|
127
|
+
```bash
|
|
128
|
+
docker build -t cembedding .
|
|
129
|
+
|
|
130
|
+
# Fill the volume once. Left to itself the server downloads the weights on the
|
|
131
|
+
# first request instead -- with the port already accepting connections it cannot
|
|
132
|
+
# yet answer, and no progress visible to whoever is waiting on it.
|
|
133
|
+
docker run --rm -v cembedding-data:/data cembedding \
|
|
134
|
+
cembedding-download-model --model jina-v5-nano
|
|
135
|
+
|
|
136
|
+
docker run -d --name cembedding -p 8401:8401 -v cembedding-data:/data \
|
|
137
|
+
-e EMBEDDING_PROVIDER=onnx_jina_v5_nano \
|
|
138
|
+
-e CEMBEDDING_AUTH_TOKEN="$(openssl rand -hex 32)" \
|
|
139
|
+
cembedding
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
The image sets `EMBEDDING_HTTP_HOST=0.0.0.0`, because inside a container the
|
|
143
|
+
server's default binds the container's own loopback: a published port then
|
|
144
|
+
forwards to a socket nothing is listening on, and the connection is refused in a
|
|
145
|
+
way that reads like a crash. That is a reachability decision and not a security
|
|
146
|
+
one — see [Authentication](#authentication-v062), and set a token whenever the
|
|
147
|
+
port is published.
|
|
148
|
+
|
|
149
|
+
`ONNX_MODEL_DIR` is `/data/model` in the image, so the download command above and
|
|
150
|
+
the server look in the same place. One model per volume: the variable names a
|
|
151
|
+
directory, not a collection.
|
|
152
|
+
|
|
153
|
+
The model and the index live on the `/data` volume, which is what survives the
|
|
154
|
+
container. A bind-mounted host directory has to be writable by uid 10001 (the
|
|
155
|
+
image's user), or the run needs `--user "$(id -u)"`.
|
|
156
|
+
|
|
70
157
|
## Providers
|
|
71
158
|
|
|
72
159
|
Set `EMBEDDING_PROVIDER`:
|
|
@@ -104,6 +191,7 @@ Vectors already indexed with one precision stay usable with another (the mixed-p
|
|
|
104
191
|
|---------|---------|-------------|
|
|
105
192
|
| `EMBEDDING_PROVIDER` | `api_openai` | Provider (see table above) |
|
|
106
193
|
| `EMBEDDING_HTTP_PORT` | `8401` | HTTP port for `/embed` |
|
|
194
|
+
| `EMBEDDING_HTTP_HOST` | `127.0.0.1` | Address `/embed` binds to. Loopback is right for a single host; a container has to bind an address its peers can reach (see [Run it in a container](#run-it-in-a-container)). Moving it decides nothing about who may call — a token does |
|
|
107
195
|
| `EMBEDDING_INDEX_ENABLED` | `true` | Enable the persistent vector index endpoints (`/index`, `/search`, `/remove`, `/purge`) |
|
|
108
196
|
| `EMBEDDING_INDEX_DB_PATH` | `data/embedding_index.db` | SQLite file backing the vector index |
|
|
109
197
|
| `EMBEDDING_SEARCH_BACKEND` | `numpy` | `/search` matmul backend. `numpy` (Accelerate BLAS) or `mlx` (Apple-GPU resident matrix; falls back to numpy when mlx is absent) |
|
|
@@ -148,9 +236,9 @@ cembedding-sidecar build --db data/embedding_index.db # write one now
|
|
|
148
236
|
|
|
149
237
|
## Authentication (v0.6.2)
|
|
150
238
|
|
|
151
|
-
Both HTTP surfaces — the REST endpoints (`/embed`, `/
|
|
152
|
-
`/remove`, `/purge`) and the Streamable HTTP MCP transport — accept
|
|
153
|
-
bearer token:
|
|
239
|
+
Both HTTP surfaces — the REST endpoints (`/embed`, `/count_tokens`, `/capabilities`,
|
|
240
|
+
`/index`, `/search`, `/remove`, `/purge`) and the Streamable HTTP MCP transport — accept
|
|
241
|
+
an inbound bearer token:
|
|
154
242
|
|
|
155
243
|
```bash
|
|
156
244
|
CEMBEDDING_AUTH_TOKEN=$(openssl rand -hex 32)
|