Find answers from the community

Updated last year

how does LongContextReorder actually

At a glance

The post asks how the LongContextReorder feature works, specifically how the relevancy of each document is measured to enable reordering. A community member responds that it does not actually reorder based on relevancy, but rather shuffles the input by alternating the order of the sorted nodes. They explain that this is a similar feature to one released by Haystack, and someone wanted to add it to llama-index, but the community member notes that this is "definitely not a scientifically proven method". Another community member simply thanks the first for the clarification.

how does LongContextReorder actually work? How is the relevancy of each document measured so it can be reordered by relevancy?
L
l
2 comments
It's not reordering based on relevancy

It's just shuffling the input

Plain Text
    def _postprocess_nodes(
        self,
        nodes: List[NodeWithScore],
        query_bundle: Optional[QueryBundle] = None,
    ) -> List[NodeWithScore]:
        """Postprocess nodes."""
        reordered_nodes: List[NodeWithScore] = []
        ordered_nodes: List[NodeWithScore] = sorted(
            nodes, key=lambda x: x.score if x.score is not None else 0
        )
        for i, node in enumerate(ordered_nodes):
            if i % 2 == 0:
                reordered_nodes.insert(0, node)
            else:
                reordered_nodes.append(node)
        return reordered_nodes


haystack released a very similar feature, and someone wanted to add it to llama-index πŸ€·β€β™‚οΈ Definitely not a scientifically proven method
thanks for the clarification.
Add a reply
Sign up and join the conversation on Discord