From 9969191d0db835abcc6d030baa3c6f08d973bcaf Mon Sep 17 00:00:00 2001 From: devteamaegis Date: Wed, 3 Jun 2026 17:06:33 -0400 Subject: [PATCH] fix(rerankers): guard against empty vector_results in RRFReranker.rerank_multivector (#3467) ## What's broken Calling `RRFReranker().rerank_multivector([])` crashes with `IndexError: list index out of range` because the method accesses `vector_results[0]` for the type-homogeneity check before verifying the list is non-empty. The `all()` call passes vacuously on an empty iterable so the crash hits the next lines. ```python from lancedb.rerankers import RRFReranker RRFReranker().rerank_multivector([]) # IndexError: list index out of range ``` ## Why it happens The type check uses `vector_results[0]` as the reference type but never guards against an empty list. `all(...)` short-circuits to `True` when the iterable is empty, so the bad index access on the lines that follow is never reached by the existing guard logic. ## Fix Add an explicit empty-list check before any indexing. --- python/python/lancedb/rerankers/rrf.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/python/python/lancedb/rerankers/rrf.py b/python/python/lancedb/rerankers/rrf.py index f512d7a8c..6d5b9a2ba 100644 --- a/python/python/lancedb/rerankers/rrf.py +++ b/python/python/lancedb/rerankers/rrf.py @@ -82,6 +82,9 @@ class RRFReranker(Reranker): results from multiple vector searches as it doesn't support reranking vector results individually. """ + if not vector_results: + raise ValueError("vector_results must not be empty") + # Make sure all elements are of the same type if not all(isinstance(v, type(vector_results[0])) for v in vector_results): raise ValueError(