Files
markitect-main/markitect/llm/embedding_adapter.py
tegwick 267368eb60 feat(llm): add embedding adapter with cache and similarity utils (S1.3)
Add OpenAI-compatible embedding support (works with both OpenAI and
OpenRouter), file-based embedding cache with content-digest invalidation,
and pure-Python cosine similarity utilities for downstream redundancy
detection.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 01:22:21 +01:00

35 lines
962 B
Python

"""
Abstract base class for embedding adapters.
Embedding adapters convert text into float vectors. This is a separate
hierarchy from :class:`LLMAdapter` (text generation) because the API
contract is fundamentally different: text in, float vectors out.
"""
from abc import ABC, abstractmethod
class EmbeddingAdapter(ABC):
"""Base class for all embedding adapters."""
@abstractmethod
def embed(self, texts: list[str]) -> list[list[float]]:
"""Embed a batch of texts into vectors.
Args:
texts: One or more strings to embed.
Returns:
A list of embedding vectors, one per input text,
in the same order as *texts*.
"""
@abstractmethod
def validate(self) -> bool:
"""Check that the adapter is configured correctly.
Returns:
``True`` if the adapter has a valid configuration
(e.g. API key present), ``False`` otherwise.
"""