Skip to content

Commit a6bbe00

Browse files
author
Krish Patel
committed
feat: expansion program — wrappers, adapters, gate, telemetry, playbooks
Phase 1 (B1/B2/E): README restructured, CHANGELOG, aecp.toml config, playbooks (ada-002→te3-small/large), when-reembedding-is-impossible doc Phase 2 (A1/A2/A3): LlamaIndex query wrapper, OpenAI client shim, opt-in local telemetry (AECP_TELEMETRY=local) Phase 3 (C1/C2/C3): Pinecone shadow-namespace adapter, Qdrant checkpointed in-place adapter, LlamaIndex storage-context migration Phase 4 (D): Gate CLI (retention table, bootstrap CIs, exit codes), HTML gate report, GitHub Actions composite gate action, --queries-only Phase 5 (B3): Doctor CLI (inspect store, suggest playbooks), Report CLI (wrapper usage summary, graduation commands) Phase 6: Shared test fakes (FakeEmbedder, FakeOpenAIClient, etc.), 89 tests passing, ruff clean (B008 excluded — standard typer pattern)
1 parent 0f821e2 commit a6bbe00

28 files changed

Lines changed: 2675 additions & 136 deletions
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
name: "AECP Gate"
2+
description: "Run AECP quality gate on embedding config changes"
3+
4+
inputs:
5+
mapping-path:
6+
description: "Path to .aecp mapping file"
7+
required: true
8+
source-vectors:
9+
description: "Path to source embedding NPY"
10+
required: true
11+
target-vectors:
12+
description: "Path to target embedding NPY"
13+
required: true
14+
format:
15+
description: "Output format: json, md, html"
16+
required: false
17+
default: "md"
18+
fail-on-warn:
19+
description: "Exit 1 on WARN (not just FAIL)"
20+
required: false
21+
default: "false"
22+
23+
runs:
24+
using: "composite"
25+
steps:
26+
- name: Install AECP
27+
shell: bash
28+
run: pip install aecp
29+
30+
- name: Run gate
31+
shell: bash
32+
run: |
33+
set +e
34+
aecp gate \
35+
--mapping ${{ inputs.mapping-path }} \
36+
--source-vectors ${{ inputs.source-vectors }} \
37+
--target-vectors ${{ inputs.target-vectors }} \
38+
--format ${{ inputs.format }} \
39+
-o gate-report.${{ inputs.format }}
40+
EXIT_CODE=$?
41+
42+
if [ "${{ inputs.fail-on-warn }}" = "true" ] && [ $EXIT_CODE -ne 0 ]; then
43+
echo "::error::AECP gate did not PASS (exit code $EXIT_CODE)"
44+
exit 1
45+
elif [ $EXIT_CODE -eq 1 ]; then
46+
echo "::warning::AECP gate returned WARN — migration may reduce quality"
47+
exit 0
48+
fi
49+
exit $EXIT_CODE
50+
51+
- name: Upload gate report
52+
if: always()
53+
uses: actions/upload-artifact@v4
54+
with:
55+
name: gate-report
56+
path: gate-report.*

‎aecp-python/CHANGELOG.md‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Changelog
2+
3+
All notable changes to AECP will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
- LlamaIndex query-time wrapper (`aecp.wrappers.llamaindex`)
12+
- OpenAI client shim (`aecp.wrappers.openai_shim`)
13+
- Shared test fakes (`tests/fakes.py`)
14+
- Deprecation playbooks (`docs/playbooks/`)
15+
- `aecp doctor` CLI command
16+
- `aecp gate` CLI command with retention table, bootstrap CIs, and exit codes
17+
- Self-contained HTML gate report
18+
- GitHub Actions composite action for gate
19+
- `aecp.toml` configuration file for gate thresholds
20+
- `aecp calibrate --queries-only` mode
21+
- Pinecone adapter (shadow-namespace strategy)
22+
- Qdrant adapter promoted to `VectorStoreAdapter`
23+
- LlamaIndex storage-context migration path
24+
- `docs/when-reembedding-is-impossible.md`
25+
- Wrapper telemetry (opt-in, local-only JSONL)
26+
- `aecp report --from-wrapper` command
27+
28+
### Changed
29+
- README restructured: problem → wrapper quickstart → gate → migration → adapters → claims → prior art
30+
31+
## [0.2.0] - 2026-07-19
32+
33+
### Added
34+
- Score recalibration (isotonic regression) for reliable similarity thresholds
35+
- Confidence scoring with adaptive P33/P67 margins
36+
- ChromaDB adapter: serve-mode `AECPChromaFunction` and offline `migrate_collection()`
37+
- LangChain adapter: `AECPEmbeddings` drop-in wrapper
38+
- Qdrant vector store (`QdrantStore`)
39+
- Provider implementations: OpenAI, Voyage, Cohere, Gemini, Sentence Transformers
40+
- Cached embedding provider (content-addressed disk cache)
41+
- CLI commands: `plan`, `calibrate`, `transform`, `inspect`
42+
- `MigrationManifest` for resumable migrations
43+
- `QueryAdapter` serve mode (zero-corpus-write migration)
44+
- `csls_scores` hubness correction
45+
- `merge_results` for progressive migration
46+
- Built-in calibration corpus (`aecp-calib-v1`)
47+
- Binary `.aecp` format with versioned header
48+
49+
### Changed
50+
- MLP adapter is non-default; Ridge is the recommended adapter (0.866 vs 0.719 retention)
51+
52+
### Deprecated
53+
- Cross-encoder reranking (NULL RESULT: -10.7pts due to domain mismatch)
54+
55+
## [0.1.0] - 2026-02-04
56+
57+
### Added
58+
- Initial release
59+
- Ridge, Procrustes, LowRank, ResidualMLP mapping algorithms
60+
- Quality gate with isotonic regression model
61+
- BEIR SciFact benchmark results

‎aecp-python/README.md‎

Lines changed: 82 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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.
1513
Optional 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
9956
from aecp.adapters.langchain import AECPEmbeddings
10057
from langchain_openai import OpenAIEmbeddings
10158

102-
mapping = Mapping.load("ada002_to_te3.aecp")
59+
mapping = Mapping.load("mapping.aecp")
10360
base = OpenAIEmbeddings(model="text-embedding-3-small")
10461
ae = AECPEmbeddings(mapping, base)
10562

106-
# Works with any LangChain vector store
10763
from langchain_chroma import Chroma
10864
db = Chroma.from_documents(docs, embedding=ae)
10965
results = 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-
211181
1. Embed K texts with source and target models → matrices X, Y
212182
2. Fit ridge map Y = [X | 1] W (handles unequal dims)
213183
3. Hold out 10% to estimate quality

0 commit comments

Comments
 (0)