11# aecp
22
3- Migrate a vector database to a new embedding model without re-embedding the corpus. Fits a ridge regression map from ~ 2K calibration texts; 87-91% retrieval retention measured on BEIR.
4-
5- Use cases: ada-002 to text-embedding-3 migration, changing embedding models in Qdrant/pgvector/ChromaDB, replacing a deprecated embedding provider, or switching from a hosted API to local models.
3+ Embedding providers deprecate models constantly — ada-002 is gone, text-embedding-3 is next. When that happens, you either re-embed your entire corpus (expensive, slow, risky) or get stuck on a dead model. AECP lets you switch without re-embedding: fit a lightweight linear transform from ~ 2K calibration texts, apply it to stored vectors, and gate the migration on measured retrieval retention. 87-91% retention on BEIR benchmarks.
64
75## Install
86
@@ -15,168 +13,128 @@ Python >= 3.10. Core deps: numpy, scikit-learn, typer, rich.
1513Optional extras:
1614- ` pip install aecp[chroma] ` — ChromaDB adapter
1715- ` pip install aecp[langchain] ` — LangChain embeddings shim
16+ - ` pip install aecp[llamaindex] ` — LlamaIndex query wrapper
1817- ` pip install aecp[sentence-transformers] ` — local model support
1918- ` pip install aecp[qdrant] ` — Qdrant store adapter
19+ - ` pip install aecp[openai] ` — OpenAI client shim
2020- ` pip install aecp[all] ` — everything above
2121
22- ## Quickstart
23-
24- ``` python
25- import numpy as np
26- from aecp import RidgeMapping
27-
28- # Paired calibration embeddings (K texts embedded with both models)
29- rng = np.random.default_rng(0 )
30- K, d_src, d_tgt = 500 , 32 , 48
31- X = rng.normal(size = (K, d_src))
32- Y = X @ rng.normal(size = (d_src, d_tgt))
33-
34- m = RidgeMapping(alpha = " auto" , seed = 0 )
35- m.fit(X, Y)
36- m.save(" mapping.aecp" )
37-
38- Z = m.transform(X[:10 ]) # (10, d_tgt), L2-normalized
39- ```
40-
41- ## CLI
42-
43- ``` bash
44- aecp plan --source-model text-embedding-ada-002 \
45- --target-model text-embedding-3-large \
46- --corpus-size 1000000
47-
48- aecp calibrate --source-vectors X.npy --target-vectors Y.npy -o map.aecp
49- aecp transform --mapping map.aecp --source-dir ./old_store --target-dir ./new_store
50- aecp inspect map.aecp
51- ```
52-
53- ## Serve mode (zero corpus writes)
54-
55- For vector database migration without touching stored data: map new-model queries into legacy space. No re-embedding, instant rollback:
56-
57- ``` python
58- from aecp.serve import QueryAdapter
59-
60- qa = QueryAdapter.load(" mapping.aecp" )
61- legacy_vec = qa.map_query(new_model_embed(query))
62- results = qdrant.search(collection = " docs" , vector = legacy_vec)
63- ```
64-
65- ## Vector DB adapters (v0.2)
22+ ## 5-minute trial: query-time wrapper
6623
67- ### ChromaDB
24+ Zero writes to your vector store. Map new-model queries into legacy space on-the-fly. Fully reversible.
6825
69- ** Serve mode ** — drop-in ` EmbeddingFunction ` :
26+ ### LlamaIndex
7027
7128``` python
72- from aecp.adapters.chroma import AECPChromaFunction
73- from aecp.mapping.base import Mapping
29+ from aecp.wrappers.llamaindex import AECPEmbedding
30+ from aecp.mapping.registry import load_mapping
7431
75- mapping = Mapping.load(" ada002_to_te3.aecp" )
76- ef = AECPChromaFunction(mapping, new_model_embedder = my_embed_fn)
77- col = client.get_collection(" docs" , embedding_function = ef)
78- results = col.query(query_texts = [" ..." ], n_results = 10 )
32+ mapping = load_mapping(" mapping.aecp" )
33+ wrapper = AECPEmbedding(
34+ new_model_embedder = your_llamaindex_embedder,
35+ transform_artifact_path = " mapping.aecp" ,
36+ )
37+ # Use wrapper anywhere LlamaIndex expects a BaseEmbedding
38+ # Queries are mapped; document embeddings raise AECPWrapperUsageError
7939```
8040
81- ** Offline migration ** — transform stored vectors:
41+ ### OpenAI client
8242
8343``` python
84- from aecp.adapters.chroma import migrate_collection
44+ import openai
45+ from aecp.wrappers.openai_shim import AECPOpenAI
8546
86- report = migrate_collection(
87- client, " docs" , mapping,
88- new_collection = " docs_v2" ,
89- batch_size = 1000 ,
90- )
91- print (f " Migrated { report.rows_processed} rows, recall@10= { report.sampled_recall_at_10:.3f } " )
47+ client = openai.OpenAI()
48+ shim = AECPOpenAI(client, " mapping.aecp" )
49+ response = shim.embeddings.create(input = [" query text" ], model = " text-embedding-3-small" )
50+ # response.data[0].embedding is now in legacy-model space
9251```
9352
9453### LangChain
9554
96- Drop-in ` Embeddings ` shim:
97-
9855``` python
9956from aecp.adapters.langchain import AECPEmbeddings
10057from langchain_openai import OpenAIEmbeddings
10158
102- mapping = Mapping.load(" ada002_to_te3 .aecp" )
59+ mapping = Mapping.load(" mapping .aecp" )
10360base = OpenAIEmbeddings(model = " text-embedding-3-small" )
10461ae = AECPEmbeddings(mapping, base)
10562
106- # Works with any LangChain vector store
10763from langchain_chroma import Chroma
10864db = Chroma.from_documents(docs, embedding = ae)
10965results = db.similarity_search(" query" , k = 10 )
11066```
11167
112- ## Score recalibration (v0.2)
113-
114- Isotonic regression maps cross-space scores to ceiling-equivalent scores. Built into the mapping file; no extra steps:
68+ ## Quality gate
11569
116- ``` python
117- m = RidgeMapping(alpha = " auto" , seed = 0 ).fit(X, Y)
118- m.fit_recalibrator(X_heldout, Y_heldout) # optional
119- m.save(" mapping.aecp" ) # recalibrator saved alongside mapping
70+ Before migrating anything, verify the transform preserves retrieval quality:
12071
121- # At serve time
122- qa = QueryAdapter.load(" mapping.aecp" )
123- calibrated_scores = qa.recalibrate_scores(raw_scores)
72+ ``` bash
73+ aecp gate --mapping mapping.aecp \
74+ --source-vectors X_sample.npy \
75+ --target-vectors Y_sample.npy
12476```
12577
126- ## Confidence scoring (v0.2)
78+ Output: retention table (Recall@1/5/10, MRR), bootstrap confidence intervals, per-metric pass/fail, and a one-line verdict. Exit code 0 for PASS, 1 for WARN/FAIL — use it in CI.
12779
128- Per-query confidence flags with adaptive percentile-based margins:
80+ ## Full migration
12981
130- ``` python
131- from aecp.reranking import ConfidenceScorer
82+ ``` bash
83+ # 1. Plan cost
84+ aecp plan --source-model ada-002 --target-model te3-large --corpus-size 1000000
85+
86+ # 2. Calibrate
87+ aecp calibrate --source-vectors X.npy --target-vectors Y.npy -o mapping.aecp
13288
133- scorer = ConfidenceScorer(margin_high = 0.955 , margin_low = 0.637 )
134- result = scorer.score(query_vector, top_scores)
135- print (result.flag) # "high", "medium", or "low"
89+ # 3. Gate
90+ aecp gate --mapping mapping.aecp --source-vectors X.npy --target-vectors Y.npy
91+
92+ # 4. Migrate
93+ aecp transform --mapping mapping.aecp --source-dir ./old_store --target-dir ./new_store
13694```
13795
138- ## Results
96+ ### Serve mode (zero corpus writes)
13997
140- All numbers from ` benchmarks/results/ ` , verified by ` benchmarks/audit_configs.py ` .
98+ Map queries on-the-fly without touching stored data:
14199
142- ### Score recalibration agreement (bge-large→e5-large, same-dim)
100+ ``` python
101+ from aecp.serve import QueryAdapter
143102
144- | Threshold | Raw recall | + Recalibration | Δ |
145- | -----------| -----------| -----------------| ---|
146- | τ ≤ 0.75 | 100% | 100% | 0 |
147- | τ = 0.80 | 12% | 17% | +4.7% |
103+ qa = QueryAdapter.load(" mapping.aecp" )
104+ legacy_vec = qa.map_query(new_model_embed(query))
105+ ```
148106
149- ### Score recalibration agreement (MiniLM→bge-large, rectangular)
107+ ## Adapter status
150108
151- | Threshold | Raw recall | + Recalibration | Δ |
152- | -----------| -----------| -----------------| ---|
153- | τ = 0.60 | 78% | 100% | +22% |
154- | τ = 0.70 | 27% | 67% | +40% |
155- | τ = 0.80 | 8% | 19% | +11% |
109+ | Store | Serve mode | Offline migration | Status |
110+ | -------| -----------| -------------------| --------|
111+ | ChromaDB | ` AECPChromaFunction ` | ` migrate_collection() ` | Supported |
112+ | LangChain | ` AECPEmbeddings ` | via store adapter | Supported |
113+ | LlamaIndex | ` AECPEmbedding ` wrapper | via store adapter | Query wrapper |
114+ | OpenAI | ` AECPOpenAI ` shim | N/A | Query shim |
115+ | Qdrant | ` QdrantStore ` | checkpointed in-place | Supported |
116+ | Pinecone | — | shadow-namespace | Planned |
156117
157- ### Confidence flags (predictive across both pairs)
118+ ## Claims policy
158119
159- | Pair | High-conf R@10 | Low-conf R@10 | Gap |
160- | ------| ---------------| ---------------| -----|
161- | bge→e5 | 0.955 | 0.637 | 0.318 |
162- | MiniLM→bge | 0.875 | 0.651 | 0.224 |
120+ Every quantitative claim in this README or docs references a committed artifact in ` benchmarks/results/ ` and a row in ` aecp-python/CLAIMS.md ` . No exceptions. If a number isn't in CLAIMS.md, it isn't a claim.
163121
164122### Adapter comparison (SciFact, MiniLM→bge-large, K=3840, 3 seeds)
165123
166124| Adapter | nDCG@10 retention | Notes |
167125| ---------| ------------------| -------|
168- | Ridge | 0.871 +/- 0.006 | Default. Fast, stable. |
169- | LowRank | 0.862 +/- 0.010 | Compressed matrix. ~ 1% worse. |
170- | MLP | 0.729 +/- 0.008 | No tuning. Linear wins. |
126+ | Ridge | 0.871 ± 0.006 | Default. Fast, stable. |
127+ | LowRank | 0.862 ± 0.010 | Compressed matrix. ~ 1% worse. |
128+ | MLP | 0.729 ± 0.008 | No tuning. Linear wins. |
171129
172130### K-sweep (all adapters averaged, SciFact, 3 seeds)
173131
174132| K | nDCG@10 retention | Gate |
175133| ---| ------------------| ------|
176- | 500 | 0.667 +/- 0.039 | WARN |
177- | 1000 | 0.732 +/- 0.056 | WARN |
178- | 2000 | 0.788 +/- 0.054 | PASS |
179- | 4000 | 0.817 +/- 0.064 | PASS |
134+ | 500 | 0.667 ± 0.039 | WARN |
135+ | 1000 | 0.732 ± 0.056 | WARN |
136+ | 2000 | 0.788 ± 0.054 | PASS |
137+ | 4000 | 0.817 ± 0.064 | PASS |
180138
181139### Same-dim pair (bge-large→e5-large, 1024→1024)
182140
@@ -187,7 +145,21 @@ All numbers from `benchmarks/results/`, verified by `benchmarks/audit_configs.py
187145| Ceiling (full re-embed) | 0.722 |
188146| Retention | 0.908 |
189147
190- Same dimension != same space. e5 models require "query: "/"passage: " prefixes; without them ceiling drops to 0.36.
148+ Same dimension ≠ same space. e5 models require "query: "/"passage: " prefixes; without them ceiling drops to 0.36.
149+
150+ ### Confidence flags (predictive across both pairs)
151+
152+ | Pair | High-conf R@10 | Low-conf R@10 | Gap |
153+ | ------| ---------------| ---------------| -----|
154+ | bge→e5 | 0.955 | 0.637 | 0.318 |
155+ | MiniLM→bge | 0.875 | 0.651 | 0.224 |
156+
157+ ### Score recalibration (MiniLM→bge, rectangular)
158+
159+ | Threshold | Raw recall | + Recalibration | Δ |
160+ | -----------| -----------| -----------------| ---|
161+ | τ = 0.60 | 78% | 100% | +22% |
162+ | τ = 0.70 | 27% | 67% | +40% |
191163
192164## When NOT to use AECP
193165
@@ -206,8 +178,6 @@ Same dimension != same space. e5 models require "query: "/"passage: " prefixes;
206178
207179## How it works
208180
209- AECP solves embedding migration (changing your vector database's embedding model) with ridge regression:
210-
2111811 . Embed K texts with source and target models → matrices X, Y
2121822 . Fit ridge map Y = [ X | 1] W (handles unequal dims)
2131833 . Hold out 10% to estimate quality
0 commit comments