# LLMListwiseRerank

> **Class** in `langchain_classic`

📖 [View in docs](https://reference.langchain.com/python/langchain-classic/retrievers/document_compressors/listwise_rerank/LLMListwiseRerank)

Document compressor that uses `Zero-Shot Listwise Document Reranking`.

Adapted from: https://arxiv.org/pdf/2305.02156.pdf

`LLMListwiseRerank` uses a language model to rerank a list of documents based on
their relevance to a query.

!!! note
    Requires that underlying model implement `with_structured_output`.

## Signature

```python
LLMListwiseRerank()
```

## Description

**Example usage:**

```python
from langchain_classic.retrievers.document_compressors.listwise_rerank import (
    LLMListwiseRerank,
)
from langchain_core.documents import Document
from langchain_openai import ChatOpenAI

documents = [
    Document("Sally is my friend from school"),
    Document("Steve is my friend from home"),
    Document("I didn't always like yogurt"),
    Document("I wonder why it's called football"),
    Document("Where's waldo"),
]

reranker = LLMListwiseRerank.from_llm(
    llm=ChatOpenAI(model="gpt-3.5-turbo"), top_n=3
)
compressed_docs = reranker.compress_documents(documents, "Who is steve")
assert len(compressed_docs) == 3
assert "Steve" in compressed_docs[0].page_content
```

## Extends

- `BaseDocumentCompressor`

## Properties

- `reranker`
- `top_n`
- `model_config`

## Methods

- [`compress_documents()`](https://reference.langchain.com/python/langchain-classic/retrievers/document_compressors/listwise_rerank/LLMListwiseRerank/compress_documents)
- [`from_llm()`](https://reference.langchain.com/python/langchain-classic/retrievers/document_compressors/listwise_rerank/LLMListwiseRerank/from_llm)

---

[View source on GitHub](https://github.com/langchain-ai/langchain/blob/fb6ab993a73180538f6cca876b3c85d46c08845f/libs/langchain/langchain_classic/retrievers/document_compressors/listwise_rerank.py#L40)