LostInTheMiddleRanker
Reorder documents so the most relevant ones appear at the beginning and end of the list, where LLMs tend to pay more attention.
Key Features
- Addresses the "lost in the middle" phenomenon where LLMs pay less attention to documents in the middle of a long context.
- Reorders documents so the most relevant ones appear at the beginning and end of the list.
- Works with any list of documents; no model inference required.
- Configurable number of documents to return via
top_k.
Configuration
- Drag the
LostInTheMiddleRankercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Set
top_kto control how many documents to return.
- Set
Connections
LostInTheMiddleRanker accepts a list of documents as input. Connect it after a retriever or DocumentJoiner in a query pipeline.
It outputs a reordered list of documents. Connect its documents output to ChatPromptBuilder or AnswerBuilder.
Source Code
To check this component's source code, open lost_in_the_middle.py in the Haystack repository.
Usage Examples
Basic Configuration
LostInTheMiddleRanker:
type: haystack.components.rankers.lost_in_the_middle.LostInTheMiddleRanker
init_parameters: {}
Parameters
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
documents | List[Document] | A list of documents to reorder. | |
top_k | Optional[int] | None | The maximum number of documents to return. |
Outputs
| Parameter | Type | Default | Description |
|---|---|---|---|
documents | List[Document] | Reordered list of documents with the most relevant ones at the beginning and end. |
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. |
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. | |
top_k | Optional[int] | None | The maximum number of documents to return. |
Was this page helpful?