Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Release

on:
push:
tags:
- 'v*'

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install package
working-directory: aecp-python
run: pip install -e ".[dev]"
- name: Run release tests
working-directory: aecp-python
run: python -m pytest tests/test_release.py -v --tb=short
- name: Run full test suite
working-directory: aecp-python
run: python -m pytest tests/ -q --tb=short

publish:
needs: test
runs-on: ubuntu-latest
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install build tools
run: pip install build twine
- name: Build package
working-directory: aecp-python
run: python -m build
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
packages-dir: aecp-python/dist/
8 changes: 4 additions & 4 deletions aecp-python/CLAIMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ pointing at a committed file under `benchmarks/results/`.

| Claim text (exact or paraphrase) | Where used | Artifact path | Verified | Notes |
|----------------------------------|------------|---------------|----------|-------|
| SciFact MiniLM→bge-large nDCG@10 retention ≈ 0.871 ± 0.006 (K=4000, Ridge adapter, 3 seeds) | `aecp-python/README.md` | `benchmarks/results/beir_scifact_*__ridge__k4000__seed{0,1,2}__*.json` | 2026-07-21 | Floor=0.0, ceiling=0.735, AECP=0.634–0.646. |
| LowRank adapter nDCG@10 retention ≈ 0.857 ± 0.009 (K=4000, 3 seeds) | same | `benchmarks/results/beir_scifact_*__lowrank__k4000__seed{0,1,2}__*.json` | 2026-07-21 | Phase 2 adapter sweep. |
| MLP adapter nDCG@10 retention ≈ 0.727 ± 0.007 (K=4000, 3 seeds) | same | `benchmarks/results/beir_scifact_*__mlp__k4000__seed{0,1,2}__*.json` | 2026-07-21 | No hyperparameter tuning. |
| SciFact MiniLM→bge-large nDCG@10 retention ≈ 0.871 ± 0.006 (K=4000, Ridge adapter, 3 seeds) | `aecp-python/README.md` | `benchmarks/results/beir_scifact_*__ridge__k4000__seed{0,1,2}__*.json` | 2026-07-21 | Floor=0.0, ceiling=0.735, AECP=0.634–0.646. Actual: 0.872, 0.863, 0.879. |
| LowRank adapter nDCG@10 retention ≈ 0.857 ± 0.009 (K=4000, 3 seeds) | same | `benchmarks/results/beir_scifact_*__lowrank__k4000__seed{0,1,2}__*.json` | 2026-07-21 | Phase 2 adapter sweep. Actual: 0.867, 0.846, 0.858. |
| MLP adapter nDCG@10 retention ≈ 0.727 ± 0.007 (K=4000, 3 seeds) | same | `benchmarks/results/beir_scifact_*__mlp__k4000__seed{0,1,2}__*.json` | 2026-07-21 | No hyperparameter tuning. Actual: 0.736, 0.724, 0.721. |
| K-sweep (ridge only): K=500 0.704±0.004, K=1000 0.781±0.008, K=2000 0.818±0.007, K=4000 0.871±0.006 | same | `benchmarks/results/beir_scifact_*__ridge__k{500,1000,2000,4000}__*.json` | 2026-07-21 | Ridge-only K-sweep. Monotonic improvement with K. |
| K-sweep (all adapters avg): K=500 0.671±0.041, K=1000 0.735±0.058, K=2000 0.785±0.052, K=4000 0.832±0.061 | same | `benchmarks/results/beir_scifact_*__k{500,1000,2000,4000}__*.json` | 2026-07-21 | All adapters averaged across 3 seeds. |
| Floor nDCG@10 = 0.0 when dims differ (384≠1024) | same | same | 2026-07-21 | Raw cross-space vectors cannot be queried. |
| Ceiling (full re-embed) nDCG@10 ≈ 0.735 | same | same | 2026-07-21 | Quality upper bound for this model pair. |
| Same-dim pair (bge-large→e5-large, 1024→1024): floor=0.0, AECP≈0.667, ceiling=0.722, retention=0.923±0.010 | `aecp-python/README.md` | `benchmarks/results/beir_scifact_*__BAAI_bge-large-en-v1.5__to__intfloat_e5-large-v2__ridge__k2000__seed{0,1,2}__*.json` | 2026-07-21 | With e5 prefixes. Without prefixes, ceiling=0.355 and retention=0.95 (broken). |
| Same-dim pair (bge-large→e5-large, 1024→1024): floor=0.0, AECP≈0.667, ceiling=0.722, retention=0.923±0.010 | `aecp-python/README.md` | `benchmarks/results/beir_scifact_*__BAAI_bge-large-en-v1.5__to__intfloat_e5-large-v2__ridge__k2000__seed{0,1,2}__*.json` | 2026-07-21 | Actual: 0.908, 0.930, 0.931. With e5 prefixes. Without prefixes, ceiling=0.355 and retention=0.95 (broken). |
| Gate model trained on local pairs only (no API model pairs) | `aecp-python/src/aecp/quality/gate_model_v1.json` | `benchmarks/results/gate_lopo.json` | — | Gate model valid for local model pairs. API pair performance may differ. |
| WS-A: bge→e5 raw scores agree at 100% for τ≤0.75; recalibration helps at τ=0.80 (+4.7% agreement, +2.36pt recall) | `README.md` | `benchmarks/results/ws_a_bge_to_e5_recall_tables.json` | — | MAE=0.095, margin compression=0.83x. |
| WS-A: MiniLM→bge rectangular pair — raw scores severely compressed (mean 0.157 vs ceiling 0.521, MAE=0.364). Recalibration essential. | `README.md` | `benchmarks/results/ws_a_minilm_to_bge_recall_tables.json` | — | τ=0.60 goes 78%→100% (+22%), τ=0.70 goes 27%→67% (+40%). |
Expand Down
3 changes: 2 additions & 1 deletion aecp-python/src/aecp/adapters/chroma.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,10 @@ def migrate_collection(
mapped_list = mapped.tolist()

# Add AECP metadata to each row
for meta in metadatas:
for i, meta in enumerate(metadatas):
if meta is None:
meta = {}
metadatas[i] = meta
meta["aecp_mapping_id"] = _hash_mapping(mapping)
meta["aecp_format_version"] = 1
meta["aecp_source_collection"] = collection_name
Expand Down
30 changes: 24 additions & 6 deletions aecp-python/src/aecp/stores/qdrant_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,26 @@ def write_vectors(
*,
batch_size: int = 1024,
) -> int:
"""Write records to Qdrant."""
"""Write records to Qdrant.

Accepts either:
- ``Iterator[list[VectorRecord]]``: lazily yields batches
- ``list[VectorRecord]``: flat list treated as a single batch
"""
QdrantClient, Distance, PointStruct, VectorParams = _require_qdrant()

# Get dimensions from first record
first_batch = next(iter(records))
# Normalize both input forms into an iterator of batches
if isinstance(records, list):

def _flat_batches() -> Iterator[list[VectorRecord]]:
yield records

batches: Iterator[list[VectorRecord]] = _flat_batches()
else:
batches = records

# Lazily peek at first batch to get dimensions
first_batch = next(batches, None)
if not first_batch:
return 0
dims = len(first_batch[0].vector)
Expand All @@ -119,9 +134,12 @@ def write_vectors(
)

total = 0
# Process first batch + remaining
all_batches = [first_batch] + list(records)
for batch in all_batches:

def _all_batches() -> Iterator[list[VectorRecord]]:
yield first_batch
yield from batches # lazy — no materialization

for batch in _all_batches():
if not batch:
continue
points = [
Expand Down
183 changes: 183 additions & 0 deletions aecp-python/tests/test_release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
"""Release validation tests — run before PyPI publish.

These tests verify the package is importable, the CLI works,
core functionality is intact, and the version is consistent.
They should pass on a clean install without optional deps.
"""

from __future__ import annotations

import shutil
import subprocess
import sys
from pathlib import Path

import numpy as np
import pytest


class TestPackageImport:
"""Verify the package imports cleanly."""

def test_import_aecp(self):
import aecp

assert aecp.__version__ == "0.2.0"

def test_import_mapping(self):
from aecp.mapping.linear import RidgeMapping

assert RidgeMapping.mapping_type == "ridge"

def test_import_gate(self):
from aecp.quality.gate import GateVerdict

assert GateVerdict.PASS.value == "PASS"

def test_import_serve(self):
from aecp.serve import QueryAdapter

assert QueryAdapter is not None

def test_import_migrate(self):
from aecp.migrate import migrate_store

assert callable(migrate_store)

def test_import_stores(self):
from aecp.stores.numpy_files import NumpyFileStore

assert NumpyFileStore is not None


class TestCoreFunctionality:
"""Verify core features work end-to-end."""

def test_ridge_fit_transform(self):
from aecp.mapping.linear import RidgeMapping

rng = np.random.default_rng(42)
X = rng.normal(size=(200, 8))
W = rng.normal(size=(8, 12))
Y = X @ W
m = RidgeMapping(alpha="auto", seed=0)
m.fit(X, Y)
Z = m.transform(X[:10])
assert Z.shape == (10, 12)
assert np.isfinite(Z).all()

def test_save_load_roundtrip(self, tmp_path):
from aecp.mapping.linear import RidgeMapping

rng = np.random.default_rng(42)
X = rng.normal(size=(200, 8))
W = rng.normal(size=(8, 12))
Y = X @ W
m = RidgeMapping(alpha="auto", seed=0)
m.fit(X, Y)
path = tmp_path / "test.aecp"
m.save(path)
loaded = RidgeMapping.load(path)
Z1 = m.transform(X[:5])
Z2 = loaded.transform(X[:5])
np.testing.assert_allclose(Z1, Z2, atol=1e-6)

def test_quality_gate(self):
from aecp.mapping.linear import RidgeMapping
from aecp.quality.gate import QualityGate

rng = np.random.default_rng(42)
X = rng.normal(size=(200, 8))
W = rng.normal(size=(8, 12))
Y = X @ W
m = RidgeMapping(alpha="auto", seed=0)
m.fit(X, Y)
gate = QualityGate()
report = gate.evaluate(m, X[:50], Y[:50])
assert report.verdict.value in ("PASS", "WARN", "FAIL")
assert 0.0 <= report.predicted_retention <= 1.0

def test_numpy_store_roundtrip(self, tmp_path):
from aecp.stores.numpy_files import NumpyFileStore

vecs = np.random.randn(10, 8)
texts = [f"doc {i}" for i in range(10)]
store = NumpyFileStore.from_arrays(tmp_path / "store", vecs, texts=texts)
assert store.count() == 10
loaded = list(store.iter_vectors(batch_size=5))
assert len(loaded) == 2

def test_migration_manifest(self, tmp_path):
from aecp.mapping.linear import RidgeMapping
from aecp.migrate import migrate_store
from aecp.stores.numpy_files import NumpyFileStore

rng = np.random.default_rng(42)
X = rng.normal(size=(200, 8))
W = rng.normal(size=(8, 12))
Y = X @ W
m = RidgeMapping(alpha="auto", seed=0).fit(X, Y)

source = NumpyFileStore.from_arrays(
tmp_path / "src", X[:50], texts=[f"doc {i}" for i in range(50)]
)
target = NumpyFileStore(tmp_path / "tgt", create=True)

manifest = migrate_store(source, target, m, batch_size=20)
assert manifest.migrated_vectors == 50


def _aecp_bin() -> str | None:
"""Find the aecp CLI script next to the current Python interpreter."""
aecp = Path(sys.executable).parent / "aecp"
if aecp.exists():
return str(aecp)
return shutil.which("aecp")


def _run_aecp(*args: str) -> subprocess.CompletedProcess[str]:
bin_path = _aecp_bin()
if bin_path is None:
pytest.skip("aecp CLI not installed")
return subprocess.run([bin_path, *args], capture_output=True, text=True, timeout=10)


class TestCLI:
"""Verify CLI entry points work."""

def test_cli_version(self):
result = _run_aecp("version")
assert result.returncode == 0
assert "0.2.0" in result.stdout

def test_cli_help(self):
result = _run_aecp("--help")
assert result.returncode == 0
assert "aecp" in result.stdout.lower()

def test_cli_plan(self):
result = _run_aecp(
"plan",
"--source-model",
"all-MiniLM-L6-v2",
"--target-model",
"bge-large",
"--corpus-size",
"10000",
)
assert result.returncode == 0
assert "10,000" in result.stdout


class TestVersionConsistency:
"""Verify version is consistent across the package."""

def test_version_in_pyproject(self):
pyproject = Path(__file__).parent.parent / "pyproject.toml"
content = pyproject.read_text()
assert 'version = "0.2.0"' in content

def test_version_in_init(self):
init = Path(__file__).parent.parent / "src" / "aecp" / "__init__.py"
content = init.read_text()
assert "0.2.0" in content
Loading