forked from langchain-ai/langchain
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
core[minor]: move document compressor base (langchain-ai#17910)
- Loading branch information
Showing
4 changed files
with
41 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from __future__ import annotations | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import Optional, Sequence | ||
|
||
from langchain_core.callbacks import Callbacks | ||
from langchain_core.documents import Document | ||
from langchain_core.pydantic_v1 import BaseModel | ||
from langchain_core.runnables import run_in_executor | ||
|
||
|
||
class BaseDocumentCompressor(BaseModel, ABC): | ||
"""Base class for document compressors.""" | ||
|
||
@abstractmethod | ||
def compress_documents( | ||
self, | ||
documents: Sequence[Document], | ||
query: str, | ||
callbacks: Optional[Callbacks] = None, | ||
) -> Sequence[Document]: | ||
"""Compress retrieved documents given the query context.""" | ||
|
||
async def acompress_documents( | ||
self, | ||
documents: Sequence[Document], | ||
query: str, | ||
callbacks: Optional[Callbacks] = None, | ||
) -> Sequence[Document]: | ||
"""Compress retrieved documents given the query context.""" | ||
return await run_in_executor( | ||
None, self.compress_documents, documents, query, callbacks | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 5 additions & 28 deletions
33
libs/langchain/langchain/retrievers/document_compressors/base.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters