core: docstrings documents (#23506)

Added missed docstrings. Formatted docstrings to the consistent form.
This commit is contained in:
Leonid Ganeline 2024-07-16 07:43:54 -07:00 committed by GitHub
parent 77dd327282
commit 5fcf2ef7ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 57 additions and 11 deletions

View File

@ -32,7 +32,16 @@ class BaseDocumentCompressor(BaseModel, ABC):
query: str,
callbacks: Optional[Callbacks] = None,
) -> Sequence[Document]:
"""Compress retrieved documents given the query context."""
"""Compress retrieved documents given the query context.
Args:
documents: The retrieved documents.
query: The query context.
callbacks: Optional callbacks to run during compression.
Returns:
The compressed documents.
"""
async def acompress_documents(
self,
@ -40,7 +49,16 @@ class BaseDocumentCompressor(BaseModel, ABC):
query: str,
callbacks: Optional[Callbacks] = None,
) -> Sequence[Document]:
"""Compress retrieved documents given the query context."""
"""Async compress retrieved documents given the query context.
Args:
documents: The retrieved documents.
query: The query context.
callbacks: Optional callbacks to run during compression.
Returns:
The compressed documents.
"""
return await run_in_executor(
None, self.compress_documents, documents, query, callbacks
)

View File

@ -10,9 +10,9 @@ if TYPE_CHECKING:
class BaseDocumentTransformer(ABC):
"""Abstract base class for document transformation systems.
"""Abstract base class for document transformation.
A document transformation system takes a sequence of Documents and returns a
A document transformation takes a sequence of Documents and returns a
sequence of transformed Documents.
Example:
@ -55,7 +55,7 @@ class BaseDocumentTransformer(ABC):
documents: A sequence of Documents to be transformed.
Returns:
A list of transformed Documents.
A sequence of transformed Documents.
"""
async def atransform_documents(
@ -67,7 +67,7 @@ class BaseDocumentTransformer(ABC):
documents: A sequence of Documents to be transformed.
Returns:
A list of transformed Documents.
A sequence of transformed Documents.
"""
return await run_in_executor(
None, self.transform_documents, documents, **kwargs

View File

@ -7,7 +7,7 @@ from langchain_core.runnables.config import run_in_executor
class Embeddings(ABC):
"""An interface for embedding models.
"""Interface for embedding models.
This is an interface meant for implementing text embedding models.
@ -36,16 +36,44 @@ class Embeddings(ABC):
@abstractmethod
def embed_documents(self, texts: List[str]) -> List[List[float]]:
"""Embed search docs."""
"""Embed search docs.
Args:
texts: List of text to embed.
Returns:
List of embeddings.
"""
@abstractmethod
def embed_query(self, text: str) -> List[float]:
"""Embed query text."""
"""Embed query text.
Args:
text: Text to embed.
Returns:
Embedding.
"""
async def aembed_documents(self, texts: List[str]) -> List[List[float]]:
"""Asynchronous Embed search docs."""
"""Asynchronous Embed search docs.
Args:
texts: List of text to embed.
Returns:
List of embeddings.
"""
return await run_in_executor(None, self.embed_documents, texts)
async def aembed_query(self, text: str) -> List[float]:
"""Asynchronous Embed query text."""
"""Asynchronous Embed query text.
Args:
text: Text to embed.
Returns:
Embedding.
"""
return await run_in_executor(None, self.embed_query, text)