mirror of
https://github.com/hwchase17/langchain
synced 2024-10-31 15:20:26 +00:00
d32e511826
Changes: - remove langchain_core/schema since no clear distinction b/n schema and non-schema modules - make every module that doesn't end in -y plural - where easy have 1-2 classes per file - no more than one level of nesting in directories - only import from top level core modules in langchain
28 lines
839 B
Python
28 lines
839 B
Python
import asyncio
|
|
from abc import ABC, abstractmethod
|
|
from typing import List
|
|
|
|
|
|
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."""
|
|
return await asyncio.get_running_loop().run_in_executor(
|
|
None, self.embed_documents, texts
|
|
)
|
|
|
|
async def aembed_query(self, text: str) -> List[float]:
|
|
"""Asynchronous Embed query text."""
|
|
return await asyncio.get_running_loop().run_in_executor(
|
|
None, self.embed_query, text
|
|
)
|