embedstamp 0.1.4__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.
- embedstamp-0.1.4/LICENSE +21 -0
- embedstamp-0.1.4/PKG-INFO +399 -0
- embedstamp-0.1.4/README.md +376 -0
- embedstamp-0.1.4/pyproject.toml +53 -0
- embedstamp-0.1.4/pyproject.toml.orig +44 -0
- embedstamp-0.1.4/src/embedstamp/__init__.py +95 -0
- embedstamp-0.1.4/src/embedstamp/_vectors.py +49 -0
- embedstamp-0.1.4/src/embedstamp/cli.py +317 -0
- embedstamp-0.1.4/src/embedstamp/data/demo_corpus.txt +160 -0
- embedstamp-0.1.4/src/embedstamp/data/demo_queries.txt +16 -0
- embedstamp-0.1.4/src/embedstamp/demo.py +103 -0
- embedstamp-0.1.4/src/embedstamp/embedders/__init__.py +48 -0
- embedstamp-0.1.4/src/embedstamp/embedders/fake.py +83 -0
- embedstamp-0.1.4/src/embedstamp/embedders/fastembed.py +28 -0
- embedstamp-0.1.4/src/embedstamp/errors.py +65 -0
- embedstamp-0.1.4/src/embedstamp/fingerprint.py +179 -0
- embedstamp-0.1.4/src/embedstamp/guard.py +83 -0
- embedstamp-0.1.4/src/embedstamp/i18n.py +54 -0
- embedstamp-0.1.4/src/embedstamp/locales/en.json +99 -0
- embedstamp-0.1.4/src/embedstamp/locales/ko.json +99 -0
- embedstamp-0.1.4/src/embedstamp/migrate.py +175 -0
- embedstamp-0.1.4/src/embedstamp/probes.py +38 -0
- embedstamp-0.1.4/src/embedstamp/py.typed +0 -0
- embedstamp-0.1.4/src/embedstamp/stores/__init__.py +93 -0
- embedstamp-0.1.4/src/embedstamp/stores/chroma.py +165 -0
- embedstamp-0.1.4/src/embedstamp/stores/local.py +158 -0
- embedstamp-0.1.4/src/embedstamp/stores/sidecar.py +31 -0
- embedstamp-0.1.4/src/embedstamp/verify.py +119 -0
embedstamp-0.1.4/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LeeGyeongPil
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: embedstamp
|
|
3
|
+
Version: 0.1.4
|
|
4
|
+
Summary: Stamp a vector index with its embedding model's fingerprint, detect silent model swaps at query time, and re-embed safely.
|
|
5
|
+
Keywords: embeddings,rag,vector-database,chroma,fingerprint,migration
|
|
6
|
+
Author: LeeGyeongPil
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Typing :: Typed
|
|
14
|
+
Requires-Dist: numpy>=2.0
|
|
15
|
+
Requires-Dist: chromadb>=1.5.9 ; extra == 'chroma'
|
|
16
|
+
Requires-Dist: fastembed>=0.9.1 ; extra == 'fastembed'
|
|
17
|
+
Requires-Python: >=3.12
|
|
18
|
+
Project-URL: Homepage, https://github.com/LeeGyeongPil/embedstamp
|
|
19
|
+
Project-URL: Issues, https://github.com/LeeGyeongPil/embedstamp/issues
|
|
20
|
+
Provides-Extra: chroma
|
|
21
|
+
Provides-Extra: fastembed
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# embedstamp
|
|
25
|
+
|
|
26
|
+
**English** | [한국어](https://github.com/LeeGyeongPil/embedstamp/blob/v0.1.4/README.ko.md)
|
|
27
|
+
|
|
28
|
+
Stamp a vector index with its embedding model's fingerprint (name, dimension, normalisation, and the vectors of eight fixed probe sentences). Later, check whether the embedder you are about to query with is still the one that built the index, and re-embed safely when it is not. Pure Python, `numpy` is the only required dependency, and it works with any store (Chroma has built-in support).
|
|
29
|
+
|
|
30
|
+

|
|
31
|
+
|
|
32
|
+
*The offline practice demo (mock embedders). Run it yourself with one command, see [Quick start](#quick-start).*
|
|
33
|
+
|
|
34
|
+
## Why
|
|
35
|
+
|
|
36
|
+
If you replace the embedding model behind a RAG index with another model of the **same dimension**, nothing fails. In an experiment (Chroma 1.5.9, 200 documents, 13 fixed queries), querying a MiniLM-built index with bge vectors raised no error and the top-10 overlap with the right results fell to 0.554 on average and 0.2 at worst (2026-11-27, measured on one machine, results vary with the data). Only a different dimension raised an error. A model name check is not enough either: adding a query prefix to the same model moved the probe cosine to 0.903.
|
|
37
|
+
|
|
38
|
+
embedstamp stores a small fingerprint next to the index and compares a fresh one against it:
|
|
39
|
+
|
|
40
|
+
| status | meaning | what to do |
|
|
41
|
+
|---|---|---|
|
|
42
|
+
| `same` | probe cosine >= 0.999 | go on |
|
|
43
|
+
| `drift` | 0.9 <= min cosine < 0.999 (re-quantised, prefix changed), or a static field changed (model name, prefix, norm, normalisation) while the cosine is still >= 0.9 | queries work, results may shift |
|
|
44
|
+
| `different` | min probe cosine < 0.9, or the dimension or the probe set changed | stop, or `migrate` |
|
|
45
|
+
|
|
46
|
+
The thresholds are changeable (`Thresholds`). The reason codes (`model_name_changed`, `probe_cosine_low`, ...) say why. A rename alone is only `drift`; if you want it blocked, use `Guard(..., allow_drift=False)`.
|
|
47
|
+
|
|
48
|
+
## Install
|
|
49
|
+
|
|
50
|
+
```bash
|
|
51
|
+
pip install embedstamp # or: uv add embedstamp
|
|
52
|
+
pip install "embedstamp[chroma]" # Chroma collection support
|
|
53
|
+
pip install "embedstamp[fastembed]" # fastembed embedder adapter
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Not on the package index yet? Install straight from GitHub: `uv add git+https://github.com/LeeGyeongPil/embedstamp`.
|
|
57
|
+
|
|
58
|
+
Requires Python 3.12+ (install uv with `curl -LsSf https://astral.sh/uv/install.sh | sh` if needed). One runtime dependency: `numpy`. Chroma (`chromadb>=1.5.9`) and `fastembed>=0.9.1` are optional extras.
|
|
59
|
+
|
|
60
|
+
## Quick start
|
|
61
|
+
|
|
62
|
+
Run the full flow offline in one command. It uses fake embedders (the "practice mock": no model, no network, so the numbers are not those of real models):
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
git clone https://github.com/LeeGyeongPil/embedstamp && cd embedstamp
|
|
66
|
+
uv sync
|
|
67
|
+
uv run embedstamp --lang en demo
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```text
|
|
71
|
+
[practice mock] Fake embedders, no model and no network. The numbers are not those of real models.
|
|
72
|
+
1/5 Build a 160-document index with model fake:a (384 dims) and stamp it.
|
|
73
|
+
fingerprint: model=fake:a dim=384 digest=b24a77a0ad1d
|
|
74
|
+
2/5 Swap the embedder to fake:b (384 dims, like before) and run 16 fixed queries.
|
|
75
|
+
No error was raised. Results simply changed.
|
|
76
|
+
overlap@10 with the original results: 0.05 (the original model against itself: 1.00)
|
|
77
|
+
3/5 Check the index fingerprint with the new embedder.
|
|
78
|
+
status: different min_cos=-0.05 mean_cos=0.01
|
|
79
|
+
reasons: model_name_changed, probe_cosine_low
|
|
80
|
+
A Guard would raise EmbeddingMismatchError before the first query.
|
|
81
|
+
4/5 Re-embed every document with fake:b into a green collection (migrate).
|
|
82
|
+
docs=160 embedded=160 skipped=0 green=demo__green
|
|
83
|
+
self-recall@10=1.00
|
|
84
|
+
overlap@10 between old and new results=1.00
|
|
85
|
+
5/5 Switch names so the green collection goes live.
|
|
86
|
+
switched: demo now serves fake:b; old data kept as demo__blue_20261126
|
|
87
|
+
status: same min_cos=1.00 mean_cos=1.00
|
|
88
|
+
Done. The same flow works on Chroma with ChromaStore; see the README.
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The suffix of `demo__blue_20261126` is the UTC date of the run (`<name>__blue_<YYYYMMDD>`), so your output shows your own date. It can differ from your local calendar date: a run in Korea on the morning of 2026-11-27 still prints `20261126`.
|
|
92
|
+
|
|
93
|
+
Two different overlaps appear above. Step 2 compares the old index queried with the **new** model against the right results (0.05: wrong vectors against a stale index). Step 4 compares "old model on the old index" with "new model on the freshly re-embedded green index" (1.00 here only because the mock `fake:b` is built like `fake:a`; with real models it is lower, which is the point of reading that number).
|
|
94
|
+
|
|
95
|
+
The same idea in your own code, 6 lines:
|
|
96
|
+
|
|
97
|
+
```python
|
|
98
|
+
from embedstamp import FakeEmbedder, stamp, verify
|
|
99
|
+
|
|
100
|
+
old = FakeEmbedder("fake:a") # stand-in for your real embedding function
|
|
101
|
+
fp = stamp(old, model="fake:a") # stamp once, when you build the index
|
|
102
|
+
new = FakeEmbedder("fake:b") # later: someone swaps the model (same 384 dims)
|
|
103
|
+
v = verify(fp, new, model="fake:b")
|
|
104
|
+
print(v.status, v.reasons)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
```text
|
|
108
|
+
different ('model_name_changed', 'probe_cosine_low')
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
An embedder is any callable `list[str] -> array of shape (n, dim)`. Swap `FakeEmbedder` for your own function, or for `resolve_embedder("fastembed:BAAI/bge-small-en-v1.5")` (needs the `fastembed` extra; the first use downloads the model, about 167 MB for the two models used in `examples/chroma_guard.py`).
|
|
112
|
+
|
|
113
|
+
## Core concepts
|
|
114
|
+
|
|
115
|
+
```mermaid
|
|
116
|
+
flowchart LR
|
|
117
|
+
A[Build index] -->|stamp| B[(Index + fingerprint)]
|
|
118
|
+
C[Current embedder] -->|embed 8 probe sentences| D{verify}
|
|
119
|
+
B --> D
|
|
120
|
+
D -->|same| E[Query]
|
|
121
|
+
D -->|drift| F[Query + warning]
|
|
122
|
+
D -->|different| G[Guard raises]
|
|
123
|
+
G --> H[migrate to green]
|
|
124
|
+
H -->|self-recall, overlap| I[switch names]
|
|
125
|
+
I --> B
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
- **Fingerprint** — model name, dimension, dtype, whether vectors are normalised, mean norm, prefixes, and the vectors of 8 fixed probe sentences (English, Korean, numbers, code). Stored as JSON: about 10 KB by default (8 x 384), about 2 KB with `compact=True` (a 32-dimension summary, less precise).
|
|
129
|
+
- **Probe cosine** — embed the same 8 sentences again and compare with the stored vectors. The minimum cosine decides `same` / `drift` / `different`. Cosine is blind to scaling, so the mean norm is recorded separately (`norm_changed`).
|
|
130
|
+
- **Guard** — wraps an embedder, checks once (the result is cached), and only then embeds. A different model raises `EmbeddingMismatchError` before the query runs, or just warns (`on_mismatch="warn"`).
|
|
131
|
+
- **Blue/green migration** — `migrate()` re-embeds every document into a new green collection, reports self-recall@k and top-k overlap, and switches names only when you ask (`switch=True`). The old data stays as `<name>__blue_<date>`. A crashed run can be repeated: ids already in green are not embedded again.
|
|
132
|
+
|
|
133
|
+
## API
|
|
134
|
+
|
|
135
|
+
| Name | What it does | Main arguments | Returns |
|
|
136
|
+
|---|---|---|---|
|
|
137
|
+
| `stamp(embed, ...)` | Embed the probe sentences and build the fingerprint | `model` (required), `doc_prefix`, `query_prefix`, `probes`, `compact`, `extra` | `Fingerprint` |
|
|
138
|
+
| `verify(stored, embed, ...)` | Compare an embedder with a stored fingerprint | `model` (required), `doc_prefix`, `query_prefix`, `thresholds`, `probes` | `Verdict` (`status`, `min_cos`, `mean_cos`, `reasons`, `stored`, `current`, `compatible`) |
|
|
139
|
+
| `Thresholds` | Cut-offs | `same=0.999`, `drift=0.9`, `norm_rel_tol=0.01` | frozen dataclass |
|
|
140
|
+
| `Guard(store, embed, ...)` | Check once, then embed documents or queries | `model` (required), `doc_prefix`, `query_prefix`, `on_mismatch="raise"\|"warn"`, `allow_drift=True`, `thresholds` | object with `check()`, `embed_documents(texts)`, `embed_query(text)` |
|
|
141
|
+
| `migrate(source, new_embed, ...)` | Blue/green re-embedding with a quality report | `new_model` (required), `target_name`, `old_embed`, `queries`, `k=10`, `batch_size=64`, `switch=False`, `min_self_recall=0.9`, `compact`, `progress` | `MigrationReport` (`n_docs`, `n_embedded`, `n_skipped`, `k`, `self_recall_at_k`, `overlap_at_k`, `green_name`, `built_name`, `blue_name`, `switched`, `status_after_switch`, `verdict_after_switch`, `fingerprint`, `seconds`). `built_name` is the name green was built under (for example `docs__green`); after a switch `green_name` becomes the original name. `verdict_after_switch` is the full `Verdict` measured right after the switch (`None` when not switched). |
|
|
142
|
+
| `overlap_at_k(a, b, k)` | Share of common ids in two top-k lists | two id lists, `k` | `float` |
|
|
143
|
+
| `Fingerprint` | The stored record | `to_json()`, `from_json(text)` | dataclass |
|
|
144
|
+
| `SidecarStore(path)` | Fingerprint in a JSON file next to any index | file path | store with `load()`, `save(fp)` |
|
|
145
|
+
| `LocalIndex(path)` | Small brute-force cosine index in a directory (demos, tests, small corpora) | directory | store with `add`, `query`, `count`, ... and migration support |
|
|
146
|
+
| `ChromaStore(collection)` / `ChromaStore.open(db_dir, name)` | Fingerprint in the Chroma collection metadata key `embedstamp`, other metadata keys are kept (`hnsw:*` keys move to the collection configuration, see [Limits](#limits-and-roadmap)) | collection or path + name of an existing collection | migratable store (extra `chroma`) |
|
|
147
|
+
| `FastEmbedEmbedder(model)` | Embedder backed by a fastembed model, what `resolve_embedder("fastembed:<model>")` returns | fastembed model name | callable (extra `fastembed`) |
|
|
148
|
+
| `FakeEmbedder(model, dim=384, noise=0.0, scale=1.0, prefix="")` | Practice-mock embedder | see names | callable, counts `calls`, `texts_embedded` |
|
|
149
|
+
| `resolve_embedder(spec)` / `resolve_store(spec)` | Turn spec strings (`fake:a`, `fastembed:<model>`, `local://dir`, `sidecar://file`, `chroma://db/collection`) into objects | spec string | `(embedder, model_name)` / store |
|
|
150
|
+
|
|
151
|
+
Every name above is importable from the top level, for example `from embedstamp import ChromaStore`. The two that need an extra are loaded only when you first use them: `ChromaStore` (also at `embedstamp.stores.chroma`) needs `chroma`, and `FastEmbedEmbedder` (also at `embedstamp.embedders.fastembed`) needs `fastembed`. Without the extra you get an `ImportError` that names the install command. `import embedstamp` alone never loads chromadb or fastembed.
|
|
152
|
+
|
|
153
|
+
Exceptions (all subclass `EmbedstampError`): `EmbeddingMismatchError` (has `.verdict`), `FingerprintNotFoundError`, `FingerprintTooLargeError`, `SwitchRefusedError` (has `.report`).
|
|
154
|
+
|
|
155
|
+
Verdict reason codes: `dim_changed`, `model_name_changed`, `doc_prefix_changed`, `query_prefix_changed`, `norm_changed`, `normalization_changed`, `probe_cosine_low`, `probe_cosine_drift`, `probe_set_changed`.
|
|
156
|
+
|
|
157
|
+
## Usage examples
|
|
158
|
+
|
|
159
|
+
### 1. Same, drift, different, and a blocked query
|
|
160
|
+
|
|
161
|
+
`examples/quickstart.py` (offline):
|
|
162
|
+
|
|
163
|
+
```bash
|
|
164
|
+
uv run python examples/quickstart.py
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
```text
|
|
168
|
+
same -> same min_cos=1.0000 reasons=[]
|
|
169
|
+
drift -> drift min_cos=0.9945 reasons=['probe_cosine_drift']
|
|
170
|
+
different -> different min_cos=-0.0517 reasons=['model_name_changed', 'probe_cosine_low']
|
|
171
|
+
EmbeddingMismatchError caught: different (model_name_changed, probe_cosine_low)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+

|
|
175
|
+
|
|
176
|
+
*Three verdicts for three embedders, then `Guard` blocks the query.*
|
|
177
|
+
|
|
178
|
+
### 2. Chroma collection with a Guard
|
|
179
|
+
|
|
180
|
+
Vectors are added directly (`embedding_function=None`), which is exactly the case where Chroma's own configuration check has nothing to compare. `examples/chroma_guard.py --mock` (needs the `chroma` extra; in a clone `uv run --extra chroma` installs it):
|
|
181
|
+
|
|
182
|
+
```bash
|
|
183
|
+
uv run --extra chroma python examples/chroma_guard.py --mock
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
```text
|
|
187
|
+
same model : same
|
|
188
|
+
swapped model: EmbeddingMismatchError caught -> different ('model_name_changed', 'probe_cosine_low')
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Without `--mock` the script uses two real fastembed models and downloads them on the first run (about 167 MB, see [Troubleshooting](#troubleshooting) if it hangs). Install the extra first:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
uv sync --extra chroma --extra fastembed # in a clone
|
|
195
|
+
pip install "embedstamp[chroma,fastembed]" # in your own project
|
|
196
|
+
uv run --extra chroma --extra fastembed python examples/chroma_guard.py
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
The core of it in your own code. Vectors go in directly, the fingerprint goes into the collection metadata, and the `Guard` checks before the first query:
|
|
200
|
+
|
|
201
|
+
```python
|
|
202
|
+
import chromadb
|
|
203
|
+
from embedstamp import ChromaStore, FakeEmbedder, Guard, stamp
|
|
204
|
+
|
|
205
|
+
embed = FakeEmbedder("fake:a")
|
|
206
|
+
docs = ["Reset your password in settings.", "Invoices are due in thirty days."]
|
|
207
|
+
|
|
208
|
+
client = chromadb.PersistentClient(path="chroma_db")
|
|
209
|
+
collection = client.get_or_create_collection("docs", embedding_function=None)
|
|
210
|
+
collection.add(ids=["1", "2"], documents=docs, embeddings=embed(docs).tolist())
|
|
211
|
+
|
|
212
|
+
store = ChromaStore(collection)
|
|
213
|
+
store.save(stamp(embed, model="fake:a")) # stamp once, when you build the collection
|
|
214
|
+
|
|
215
|
+
guard = Guard(store, embed, model="fake:a")
|
|
216
|
+
print(guard.check().status)
|
|
217
|
+
query_vector = guard.embed_query("forgot my login") # raises if the model was swapped
|
|
218
|
+
print(query_vector.shape)
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
```text
|
|
222
|
+
same
|
|
223
|
+
(384,)
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
Later you can reopen the same collection with `ChromaStore.open("chroma_db", "docs")`, or point the CLI at it with `--store chroma://chroma_db/docs`.
|
|
227
|
+
|
|
228
|
+
### 3. Re-embed into a green collection, then switch
|
|
229
|
+
|
|
230
|
+
`examples/migrate_local.py` (offline):
|
|
231
|
+
|
|
232
|
+
```bash
|
|
233
|
+
uv run python examples/migrate_local.py
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
```text
|
|
237
|
+
embedded=40 skipped=0 self_recall@10=1.00
|
|
238
|
+
switched=True status_after_switch=same
|
|
239
|
+
live model: fake:b
|
|
240
|
+
query ok: (384,)
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
`switch=True` is refused (`SwitchRefusedError`, exit code 13 in the CLI) when self-recall@k is below `min_self_recall`. Run without `switch` first, read the report, then switch.
|
|
244
|
+
|
|
245
|
+
### 4. The command line
|
|
246
|
+
|
|
247
|
+
In the cloned repository (the Quick start flow) run the CLI through `uv run embedstamp ...`. After `pip install embedstamp` the `embedstamp` command is on your PATH, so drop the `uv run`.
|
|
248
|
+
|
|
249
|
+
Stamp and check any store spec. The exit code tells scripts what happened (0 same, 10 drift, 11 different, 12 no fingerprint, 13 switch refused):
|
|
250
|
+
|
|
251
|
+
```bash
|
|
252
|
+
uv run embedstamp --lang en stamp --store local://idx --embedder fake:a
|
|
253
|
+
uv run embedstamp --lang en check --store local://idx --embedder fake:b
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
```text
|
|
257
|
+
Stamped local://idx: model=fake:a dim=384 digest=b24a77a0ad1d (10093 bytes)
|
|
258
|
+
status: different min_cos=-0.0517 mean_cos=0.0061
|
|
259
|
+
stored model: fake:a current model: fake:b
|
|
260
|
+
reasons:
|
|
261
|
+
- model_name_changed: model name changed
|
|
262
|
+
- probe_cosine_low: probe sentences point in unrelated directions
|
|
263
|
+
The embedder does not match the index. Use the original model or run `embedstamp migrate`.
|
|
264
|
+
```
|
|
265
|
+
|
|
266
|
+

|
|
267
|
+
|
|
268
|
+
*`check` returns exit code 11 for `different`, so a CI job can fail on it.*
|
|
269
|
+
|
|
270
|
+
More commands: `embedstamp show --store ...` prints the stored fingerprint (add `--json`), `embedstamp check ... --json` prints `status`, `min_cos`, `reasons`, and `embedstamp migrate --store ... --to <embedder> [--from <old embedder>] [--queries file] [--switch]` runs the blue/green flow. Run `embedstamp <command> --help` for every option.
|
|
271
|
+
|
|
272
|
+
#### Migrating from the command line
|
|
273
|
+
|
|
274
|
+
`migrate` moves the documents of an index that already has them. `stamp` above only wrote a fingerprint, so `idx` is empty and the CLI says so (exit code 1):
|
|
275
|
+
|
|
276
|
+
```bash
|
|
277
|
+
uv run embedstamp --lang en migrate --store local://idx --to fake:b
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
```text
|
|
281
|
+
error: local://idx has no documents, so there is nothing to re-embed. migrate copies the documents of an existing index; `embedstamp stamp` only writes the fingerprint and the CLI cannot add documents. Add them with your vector store or LocalIndex.add(...) first (see examples/migrate_local.py), or point --store at a filled index such as chroma://<db_dir>/<collection>.
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
The CLI cannot add documents. Fill a small local index `kb` with 30 documents in Python first (any filled Chroma collection, `chroma://<db_dir>/<collection>`, works the same way):
|
|
285
|
+
|
|
286
|
+
```bash
|
|
287
|
+
uv run python -c '
|
|
288
|
+
from embedstamp import FakeEmbedder, LocalIndex, stamp
|
|
289
|
+
docs = [f"document {i} about topic {i % 7}" for i in range(30)]
|
|
290
|
+
emb = FakeEmbedder("fake:a")
|
|
291
|
+
kb = LocalIndex("kb")
|
|
292
|
+
kb.add([f"d{i}" for i in range(30)], docs, emb(docs))
|
|
293
|
+
kb.save(stamp(emb, model="fake:a"))
|
|
294
|
+
'
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Then re-embed into green without switching, read the report, and switch:
|
|
298
|
+
|
|
299
|
+
```bash
|
|
300
|
+
uv run embedstamp --lang en migrate --store local://kb --to fake:b --from fake:a
|
|
301
|
+
uv run embedstamp --lang en migrate --store local://kb --to fake:b --switch
|
|
302
|
+
uv run embedstamp --lang en check --store local://kb --embedder fake:b
|
|
303
|
+
```
|
|
304
|
+
|
|
305
|
+
```text
|
|
306
|
+
Re-embedding local://kb with fake:b ...
|
|
307
|
+
30/30 documents
|
|
308
|
+
docs=30 embedded=30 skipped=0 green=kb__green
|
|
309
|
+
self-recall@10=1.00
|
|
310
|
+
overlap@10 between old and new results=1.00
|
|
311
|
+
Not switched; kb__green is ready. Re-run with --switch to make it live.
|
|
312
|
+
Re-embedding local://kb with fake:b ...
|
|
313
|
+
30/30 documents
|
|
314
|
+
docs=30 embedded=0 skipped=30 green=kb__green
|
|
315
|
+
Every document was already in kb__green from an earlier run; nothing was re-embedded.
|
|
316
|
+
self-recall@10=1.00
|
|
317
|
+
switched: kb now serves fake:b; old data kept as kb__blue_20261126
|
|
318
|
+
status: same min_cos=1.0000 mean_cos=1.0000
|
|
319
|
+
status: same min_cos=1.0000 mean_cos=1.0000
|
|
320
|
+
stored model: fake:b current model: fake:b
|
|
321
|
+
The embedder matches the index.
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
- The first run fills `kb__green` and stops. `--from fake:a` adds the old-versus-new `overlap@10` line.
|
|
325
|
+
- The second run finds every document already in green (`skipped=30`, `embedded=0`), so it re-embeds nothing, checks self-recall again and switches. The last line is the fingerprint check measured right after the switch.
|
|
326
|
+
- `kb` now serves `fake:b`. The old data stays in `kb__blue_<UTC date>`; delete it yourself when you no longer need it.
|
|
327
|
+
|
|
328
|
+
## Settings and language
|
|
329
|
+
|
|
330
|
+
CLI output is in English or Korean. Priority: `--lang en|ko` > `EMBEDSTAMP_LANG` > `LC_ALL` > `LC_MESSAGES` > `LANG` (anything that does not start with `ko` falls back to English). Verdict codes and library exception messages are always English.
|
|
331
|
+
|
|
332
|
+
| Variable | Used for |
|
|
333
|
+
|---|---|
|
|
334
|
+
| `EMBEDSTAMP_LANG` | CLI language `en` or `ko` |
|
|
335
|
+
| `FASTEMBED_CACHE_PATH` | Where fastembed keeps downloaded models |
|
|
336
|
+
| `HF_HUB_OFFLINE=1` | Run offline after the models are downloaded |
|
|
337
|
+
| `HF_HUB_DISABLE_XET=1` | Download models on networks that block the Xet CDN |
|
|
338
|
+
| `EMBEDSTAMP_REAL=1` | Also run the tests that use real fastembed models |
|
|
339
|
+
|
|
340
|
+
## When to use it
|
|
341
|
+
|
|
342
|
+
- A local or small-team RAG index, an agent memory, or a Chroma collection that you re-open later, possibly with a different embedder config, library version or quantisation.
|
|
343
|
+
- You want a pre-query check, a measurable migration report, and a scriptable exit code, independent of the vector database.
|
|
344
|
+
- Different tool is better when: you only need Chroma's own embedding-function configuration for collections created through its embedding functions (see the [Chroma docs](https://docs.trychroma.com/docs/collections/configure)); you need a hosted vector database to re-embed for you (see your database's own migration guide, for example [Qdrant](https://qdrant.tech/documentation/tutorials-operations/embedding-model-migration/) or [Weaviate](https://docs.weaviate.io/weaviate/tutorials/vectorizer-migration)).
|
|
345
|
+
|
|
346
|
+
embedstamp does not detect changes in your documents, and it does not replace evaluation: the probe cosine says "same model", not "good retrieval".
|
|
347
|
+
|
|
348
|
+
## Troubleshooting
|
|
349
|
+
|
|
350
|
+
| Symptom | Cause | Fix |
|
|
351
|
+
|---|---|---|
|
|
352
|
+
| `FingerprintNotFoundError` / CLI exit 12 | The index was never stamped | Stamp it while you still know which model built it: `stamp(embed, model=...)` then `store.save(fp)` |
|
|
353
|
+
| `drift` after a harmless change | Quantisation, a different runtime or a changed prefix | Check `reasons`; raise `Thresholds(drift=...)` only if you accept the shift |
|
|
354
|
+
| `norm_changed` although cosine is 1.0 | Vectors are scaled differently (normalisation switched on or off) | Re-embed, or use the same normalisation setting |
|
|
355
|
+
| `FingerprintTooLargeError` | The store's metadata limit is smaller than the fingerprint | `stamp(..., compact=True)` (about 2 KB) |
|
|
356
|
+
| `ImportError: ChromaStore needs the optional dependency 'chromadb'` | The `chroma` extra is missing | `pip install "embedstamp[chroma]"` (in a clone: `uv sync --extra chroma`) |
|
|
357
|
+
| `ModuleNotFoundError: No module named 'chromadb'` from `examples/chroma_guard.py` in a clone | `uv sync` installs the core only; the example imports `chromadb` itself | `uv run --extra chroma python examples/chroma_guard.py --mock` |
|
|
358
|
+
| `ImportError: FastEmbedEmbedder needs the optional dependency 'fastembed'`, or `chroma_guard.py` without `--mock` fails | The `fastembed` extra is missing (`uv sync` alone does not install it) | `pip install "embedstamp[fastembed]"` (in a clone: `uv sync --extra fastembed`) |
|
|
359
|
+
| `embedstamp: command not found` in a clone | The command lives in the project's virtual environment | `uv run embedstamp ...` |
|
|
360
|
+
| `migrate` says `has no documents, so there is nothing to re-embed` (exit 1) | The index was only stamped; `stamp` writes no documents | Add documents with your vector store or `LocalIndex.add(...)`, or point `--store` at a filled index (see [Migrating from the command line](#migrating-from-the-command-line)) |
|
|
361
|
+
| Real-model download hangs | Xet CDN is blocked | `HF_HUB_DISABLE_XET=1` |
|
|
362
|
+
|
|
363
|
+
## Limits and roadmap
|
|
364
|
+
|
|
365
|
+
- Switching a Chroma collection takes two renames, so it is not atomic. If the second one fails, `switch_to` rolls the first one back.
|
|
366
|
+
- After `ChromaStore` saves a fingerprint, the `hnsw:*` keys no longer show in `collection.metadata`; the distance function stays in the collection configuration.
|
|
367
|
+
- Mock numbers (`fake:a`, `fake:b`) are not those of real models.
|
|
368
|
+
- The test that uses real fastembed models is skipped by default (`EMBEDSTAMP_REAL=1`).
|
|
369
|
+
- Planned: M2 adds Qdrant, LanceDB, an Ollama embedder and content-hash incremental re-embedding; M3 adds pgvector and LangChain / LlamaIndex helpers. None of these exist yet.
|
|
370
|
+
|
|
371
|
+
## Related
|
|
372
|
+
|
|
373
|
+
- [vecdiff](https://pypi.org/project/vecdiff/) compares two index snapshots after the fact (neighbour stability, statistics). It complements the `migrate` report; it does not stamp an index or guard queries.
|
|
374
|
+
- Chroma's [embedding function configuration](https://docs.trychroma.com/docs/collections/configure) raises a conflict when a different embedding function class is passed. It compares the class name only, and it has nothing to compare when vectors are added directly.
|
|
375
|
+
- LanceDB's [embedding registry](https://docs.lancedb.com/embedding) stores the embedding function in the table schema, for LanceDB only.
|
|
376
|
+
|
|
377
|
+
(Checked 2026-11-27.)
|
|
378
|
+
|
|
379
|
+
## Version and compatibility
|
|
380
|
+
|
|
381
|
+
- Follows [SemVer](https://semver.org/). While 0.x, minor versions may change the API; changes are listed in [CHANGELOG.md](https://github.com/LeeGyeongPil/embedstamp/blob/v0.1.4/CHANGELOG.md).
|
|
382
|
+
- Tested with Python 3.12, numpy 2.5.5, chromadb 1.5.9, fastembed 0.9.1 (onnxruntime 1.32.0).
|
|
383
|
+
- The fingerprint JSON has a `schema` field for future changes.
|
|
384
|
+
|
|
385
|
+
## Development
|
|
386
|
+
|
|
387
|
+
```bash
|
|
388
|
+
uv sync
|
|
389
|
+
uv run pytest -q # core: numpy only, the Chroma tests are skipped
|
|
390
|
+
uv run --extra chroma pytest -q # everything, including the Chroma integration tests
|
|
391
|
+
```
|
|
392
|
+
|
|
393
|
+
Both should finish with no failures. The real-model test is skipped unless you ask for it: `EMBEDSTAMP_REAL=1 uv run --extra fastembed pytest -q -m real` (downloads about 167 MB once).
|
|
394
|
+
|
|
395
|
+
CI runs the core job on every push and pull request: the core tests, `embedstamp demo` and the quickstart example. The Chroma tests run in a separate `extras` job that you start by hand (Actions → ci → Run workflow).
|
|
396
|
+
|
|
397
|
+
## License
|
|
398
|
+
|
|
399
|
+
MIT.
|