2024-02-21 23:58:21 +00:00
|
|
|
"""**Embeddings** interface."""
|
2023-11-20 21:09:30 +00:00
|
|
|
from abc import ABC, abstractmethod
|
|
|
|
from typing import List
|
|
|
|
|
2023-12-29 20:34:03 +00:00
|
|
|
from langchain_core.runnables.config import run_in_executor
|
|
|
|
|
2023-11-20 21:09:30 +00:00
|
|
|
|
|
|
|
class Embeddings(ABC):
|
|
|
|
"""Interface for embedding models."""
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def embed_documents(self, texts: List[str]) -> List[List[float]]:
|
|
|
|
"""Embed search docs."""
|
|
|
|
|
|
|
|
@abstractmethod
|
|
|
|
def embed_query(self, text: str) -> List[float]:
|
|
|
|
"""Embed query text."""
|
|
|
|
|
|
|
|
async def aembed_documents(self, texts: List[str]) -> List[List[float]]:
|
|
|
|
"""Asynchronous Embed search docs."""
|
2023-12-29 20:34:03 +00:00
|
|
|
return await run_in_executor(None, self.embed_documents, texts)
|
2023-11-20 21:09:30 +00:00
|
|
|
|
|
|
|
async def aembed_query(self, text: str) -> List[float]:
|
|
|
|
"""Asynchronous Embed query text."""
|
2023-12-29 20:34:03 +00:00
|
|
|
return await run_in_executor(None, self.embed_query, text)
|