LongContextReorder#

class langchain_community.document_transformers.long_context_reorder.LongContextReorder[source]#

Bases: BaseDocumentTransformer, BaseModel

Reorder long context.

Lost in the middle: Performance degrades when models must access relevant information in the middle of long contexts. See: https://arxiv.org/abs//2307.03172

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

async atransform_documents(documents: Sequence[Document], **kwargs: Any) β†’ Sequence[Document][source]#

Asynchronously transform a list of documents.

Parameters:
  • documents (Sequence[Document]) – A sequence of Documents to be transformed.

  • kwargs (Any)

Returns:

A sequence of transformed Documents.

Return type:

Sequence[Document]

transform_documents(documents: Sequence[Document], **kwargs: Any) β†’ Sequence[Document][source]#

Reorders documents.

Parameters:
  • documents (Sequence[Document])

  • kwargs (Any)

Return type:

Sequence[Document]

Examples using LongContextReorder