langchain_community.document_transformers.long_context_reorder.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 if the input data cannot be parsed to form a valid model.

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