File size: 1,421 Bytes
dc1b199
 
 
 
 
 
 
 
 
 
 
 
 
faa8fb3
dc1b199
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Abstract base class for all embedding clients."""

from abc import ABC, abstractmethod


class EmbeddingClient(ABC):
    """Interface for obtaining dense vector representations of text.

    Implementors must provide both single and batched variants.  The batched
    variant should be preferred for throughput when indexing many chunks.

    Example::

        client = MockEmbeddingClient()
        vector = client.get_embedding("hello world")
        vectors = client.get_embeddings(["hello", "world"])
    """

    @abstractmethod
    def get_embedding(self, text: str) -> list[float]:
        """Return the embedding vector for a single text string.

        Args:
            text: Input text (should be ≤ model token limit).

        Returns:
            Dense float vector of the model's output dimensionality.
        """
        ...

    @abstractmethod
    def get_embeddings(self, texts: list[str]) -> list[list[float]]:
        """Return embedding vectors for a batch of text strings.

        Args:
            texts: List of input strings.

        Returns:
            List of dense float vectors in the same order as ``texts``.
        """
        ...

    @property
    @abstractmethod
    def dimension(self) -> int:
        """The output dimensionality of the embedding model.

        Returns:
            Integer vector dimension (e.g. 1536 for text-embedding-3-small).
        """
        ...