LostInTheMiddleRanker
Reorder documents to place the most relevant ones at the beginning and end of the list.
Key Features
- Addresses the "lost in the middle" problem where LLMs struggle to use information from the middle of long contexts.
- Places the most relevant documents at the start and end of the list for better LLM attention.
- Configurable
top_kto control the number of documents returned. - Complements semantic similarity rankers in multi-stage retrieval pipelines.
- Improves answer quality for pipelines passing many documents to an LLM.
Configuration
- Drag the
LostInTheMiddleRankercomponent onto the canvas from the Component Library. - Click the component to open the configuration panel.
- Configure the parameters as needed.
Connections
LostInTheMiddleRanker receives a query string and a documents list — typically from a retriever or another ranker. It outputs a reordered documents list. Connect its output to ChatPromptBuilder or AnswerBuilder to pass the reordered documents to an LLM.
Usage Example
components:
LostInTheMiddleRanker:
type: haystack.components.rankers.lost_in_the_middle.LostInTheMiddleRanker
init_parameters:
top_k: 10
word_count_threshold:
Parameters
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| documents | List[Document] | A list of documents to reorder. |
Outputs
| Parameter | Type | Default | Description |
|---|---|---|---|
| documents | List[Document] | Documents reordered so the most relevant ones appear at the beginning and end of the list. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
| top_k | Optional[int] | None | The maximum number of documents to return. If None, returns all documents. |
| word_count_threshold | Optional[int] | None | The maximum total number of words across all documents. If the threshold is exceeded, the remaining documents are discarded. |
Run Method Parameters
These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.
| Parameter | Type | Default | Description |
|---|---|---|---|
| documents | List[Document] | A list of documents to reorder. |
Was this page helpful?