concept
Embedding model contracts
Local teaching gate for a reviewed compatible retrieval profile, revision, metric, dimension and role; equal dimensions alone do not establish compatibility.
Formal Syntax & Structure
artificial-intelligence syntaxartificial-intelligence
compatible(query_record, document_record)Working Example
Example Snippetartificial-intelligence
import math
def compatible(query, document): # Application-owned metadata, not trusted fields from a document. fields = ("space", "revision", "dimension", "metric", "profile") if any(query.get(k) != document.get(k) for k in fields): return False if any(not isinstance(query.get(k), str) or not query[k] for k in ("space", "revision", "profile")): return False d = query.get("dimension") if type(d) is not int or not 1 <= d <= 1024: return False if type(document.get("dimension")) is not int: return False if query.get("metric") != "cosine": return False if query.get("role") != "query" or document.get("role") != "document": return False for record in (query, document): v = record.get("vector") if (not isinstance(v, list) or len(v) != d or any(type(x) not in (int, float) or not -1000 <= x <= 1000 for x in v) or not any(v)): return False return True
q = dict(space="demo", revision="r1", dimension=2, metric="cosine", profile="retrieval-v1", role="query", vector=[1, 0])d = dict(q, role="document", vector=[1, 1])print(compatible(q, d))print(compatible(q, dict(d, revision="r2")))print(compatible(q, dict(d, vector=[0, 0])))