Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async Support for LLMChainExtractor #3587

Closed
wants to merge 4 commits into from
Closed
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 18 additions & 8 deletions langchain/retrievers/document_compressors/chain_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,29 @@ def compress_documents(
self, documents: Sequence[Document], query: str
) -> Sequence[Document]:
"""Compress page content of raw documents."""
compressed_docs = []
for doc in documents:
_input = self.get_input(query, doc)
output = self.llm_chain.predict_and_parse(**_input)
if len(output) == 0:
continue
compressed_docs.append(Document(page_content=output, metadata=doc.metadata))
outputs = self.llm_chain.apply_and_parse(
[self.get_input(query, doc) for doc in documents]
)
compressed_docs = [
Document(page_content=output, metadata=doc.metadata)
for output, doc in zip(outputs, documents)
if len(output) > 0
]
return compressed_docs

async def acompress_documents(
self, documents: Sequence[Document], query: str
) -> Sequence[Document]:
raise NotImplementedError
"""Compress page content of raw documents."""
outputs = await self.llm_chain.aapply_and_parse(
jphme marked this conversation as resolved.
Show resolved Hide resolved
[self.get_input(query, doc) for doc in documents]
)
compressed_docs = [
Document(page_content=output, metadata=doc.metadata)
for output, doc in zip(outputs, documents)
if len(output) > 0
]
return compressed_docs

@classmethod
def from_llm(
Expand Down