File size: 955 Bytes
5b7955a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
"""Abstract base class for all embedding providers."""

from abc import ABC, abstractmethod


class BaseEmbedder(ABC):
    """Interface every embedder must implement."""

    @abstractmethod
    def embed_query(self, text: str) -> list[float]:
        """Embed a single query string and return its vector."""
        ...

    @abstractmethod
    def embed_documents(self, texts: list[str]) -> list[list[float]]:
        """Embed a batch of document strings and return their vectors."""
        ...

    @property
    @abstractmethod
    def model_id(self) -> str:
        """Return the canonical model identifier."""
        ...

    # ── concrete helper ──────────────────────────────────────────────
    def get_dimension(self) -> int:
        """Return the dimensionality of the embedding vectors."""
        return len(self.embed_query("dimension test"))