embedding.py 631 B

123456789101112131415161718192021
  1. from abc import ABC, abstractmethod
  2. class Embeddings(ABC):
  3. """Interface for embedding models."""
  4. @abstractmethod
  5. def embed_documents(self, texts: list[str]) -> list[list[float]]:
  6. """Embed search docs."""
  7. @abstractmethod
  8. def embed_query(self, text: str) -> list[float]:
  9. """Embed query text."""
  10. async def aembed_documents(self, texts: list[str]) -> list[list[float]]:
  11. """Asynchronous Embed search docs."""
  12. raise NotImplementedError
  13. async def aembed_query(self, text: str) -> list[float]:
  14. """Asynchronous Embed query text."""
  15. raise NotImplementedError