Browse OOP reference
Paradigms in practice

How does object-oriented design apply to AI engineering?

On this page

Put a small contract around a changing provider boundary. An embedding client can return vectors plus the model identifier that produced them. Validate dimensions and keep the identifier with the index. Swapping in an adapter with the same method signature can silently invalidate retrieval if its vector space changes.

Worked example

Python
from dataclasses import dataclass

@dataclass(frozen=True)
class Embedding:
    model: str
    vector: tuple[float, ...]

def compatible(left, right):
    return (left.model == right.model
            and len(left.vector) == len(right.vector))

saved = Embedding("encoder-a-v1", (0.2, 0.7))
query = Embedding("encoder-b-v1", (0.2, 0.7))
assert not compatible(saved, query)

Anthropic on composable AI systems

Explore class relationships in the OOP Playground

What is object-oriented programming?What is information hiding?What is object-oriented design?

All OOP questions

Search ObjectFAQ