Versioning Models, Prompts, Data, and Tools › Compatibility: constraints across components

Michael BrenndoerferDecember 2, 20263 min read
Language AI HandbookAll chapters
Part 64 of 67Compound AI System Design
Chapter 489Versioning Models, Prompts, Data, and Tools › Compatibility: constraints across components
Reading section 5 of 14 · Compatibility: constraints across components · 3 minSection 5 of 14 · 3 min

Section 5 of 14 · 3 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

A type check can confirm that the embedder and index fields are both present. Compatibility checks inspect the relationship between them. A 1024-coordinate query cannot be compared by ordinary dot product to a 768-coordinate index vector. Two equally sized vectors can be compared numerically, but a query produced in an unrelated embedding space can still retrieve irrelevant results.

The fixture checks the query dimension and the exact embedder identity expected by the index. The metadata is simulated. A production registry needs recorded, trustworthy metadata tied to the referenced artifacts.

PythonIn [10]
CollapseExpand
# Fake "metadata" attached to provider-tagged components, as a provider registry would supply.
REGISTRY = {
    "gpt-x-2025-06-01": {"tokenizer": "tok-v5", "max_context": 128_000},
    "hf:e5-base-v2@sha:ab12": {"dim": 768, "tokenizer": "tok-v5"},
    "hf:e5-large-v2@sha:cd34": {"dim": 1024, "tokenizer": "tok-v5"},
    "pinecone://kb-v7": {"dim": 768, "embedder": "hf:e5-base-v2@sha:ab12"},
}


def check_embedding_matches_index(m: Manifest) -> str | None:
    emb = REGISTRY[m.components["embed.kb"].identity]["dim"]
    idx = REGISTRY[m.components["index.kb"].identity]["dim"]
    if emb != idx:
        return f"embed.kb dim={emb} but index.kb dim={idx}"
    return None


def check_index_embedder_consistent(m: Manifest) -> str | None:
    idx_embedder = REGISTRY[m.components["index.kb"].identity]["embedder"]
    if idx_embedder != m.components["embed.kb"].identity:
        return f"index built with {idx_embedder}, querying with {m.components['embed.kb'].identity}"
    return None


CONSTRAINTS = [check_embedding_matches_index, check_index_embedder_consistent]


def releasable(m: Manifest) -> tuple[bool, list[str]]:
    if m.compatibility_policy != "embedding-index-v1":
        return False, [f"unknown compatibility policy {m.compatibility_policy}"]
    try:
        violations = [v for fn in CONSTRAINTS if (v := fn(m)) is not None]
    except KeyError as exc:
        return False, [f"unregistered component or metadata: {exc}"]
    return (not violations, violations)

The compatibility registry resolves the two synthetic metadata records before registration. Its keys identify the declared artifacts. This example checks two relationships. Additional constraints can be added under a new policy version.

PythonIn [11]
CollapseExpand
ok, errors = releasable(base_manifest)
print("Stable release:", ok, "| Violations:", errors)

bad_manifest = replace(
    base_manifest,
    revision=2,
    parent=manifest_id(base_manifest),
    components={
        **base_manifest.components,
        "embed.kb": ComponentRef(
            key="embed.kb",
            version="e5-large-v2",
            identity="hf:e5-large-v2@sha:cd34",
            source="provider-tag",
        ),
    },
)
ConsoleOut [11]
CollapseExpand
Stable release: True | Violations: []
PythonIn [12]
CollapseExpand
def register(store: dict[str, bytes], manifest: Manifest) -> str:
    ok, issues = releasable(manifest)
    if not ok:
        raise ValueError("; ".join(issues))
    encoding = canonical_bytes(manifest)
    mid = manifest_id(manifest)
    if store.setdefault(mid, encoding) != encoding:
        raise ValueError("manifest digest collision")
    return mid


registry: dict[str, bytes] = {}
stable_id = register(registry, base_manifest)
try:
    register(registry, bad_manifest)
except ValueError as err:
    print("Blocked release:", err)
ConsoleOut [12]
CollapseExpand
Blocked release: embed.kb dim=1024 but index.kb dim=768; index built with hf:e5-base-v2@sha:ab12, querying with hf:e5-large-v2@sha:cd34

The 1024-coordinate candidate fails both checks. The identity check also catches an equally sized but incompatible embedding model. A readable violation names the component and values involved so an operator can see which bundle needs correction.

What constraints cannot catch

These predicates cover known structural requirements. Evaluation-Driven Development measures behavior that the declared schema cannot capture, such as whether the prompt helps the model select the intended tool on representative cases.

Test the compatibility boundary with an equally sized but independently produced embedding. The sample adds a third synthetic embedder to the local metadata registry. Fixing the vector size gives only one of the two compatibility conditions.

PythonIn [13]
CollapseExpand
same_size_embedder = "other-embedding-space-v1"
REGISTRY[same_size_embedder] = {"dim": 768}
wrong_space = replace(
    base_manifest,
    components={
        **base_manifest.components,
        "embed.kb": ComponentRef(
            key="embed.kb",
            version="different-768",
            identity=same_size_embedder,
            source="provider-tag",
        ),
    },
)
assert check_embedding_matches_index(wrong_space) is None
print(releasable(wrong_space))
ConsoleOut [13]
CollapseExpand
(False, ['index built with hf:e5-base-v2@sha:ab12, querying with other-embedding-space-v1'])

This test exercises the difference between a shape constraint and an identity constraint. In a deployment whose two encoders are deliberately paired, for example a trained query encoder and a separate document encoder, replace the exact equality here with a record of the declared compatible pair. A code-level equality check is appropriate for the same-encoder fixture, while the compatibility rule should reflect how the index was trained and assembled.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy