{"record":{"id":"fd493413f2c544a1","repo":"pathwaycom/pathway","slug":"hybridindex-requires-at-least-two-indices-to-be-pr","errorCode":null,"errorMessage":"HybridIndex requires at least two indices to be provided during initialization","messagePattern":"HybridIndex requires at least two indices to be provided during initialization","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/stdlib/indexing/hybrid_index.py","lineNumber":29,"sourceCode":"from pathway.stdlib.indexing.retrievers import InnerIndexFactory\n\n\nclass HybridIndex(InnerIndex):\n    \"\"\"\n    Hybrid Index that composes any number of other indices and combines them using\n    the Reciprocal Rank Fusion (RRF). It queries each index, and each retrieved row ``d`` is assigned\n    score ``1/(k+rank(d))``, which is then summed over all indices. ``HybridIndex`` returns\n    best rows from indexed data according to this score.\n\n    Args:\n        retrievers: list of indices to be used to compose the hybrid index.\n        k: constant used for calculating ranking score.\n\n    \"\"\"\n\n    def __init__(self, retrievers: list[InnerIndex], k: float = 60):\n        if len(retrievers) < 2:\n            raise ValueError(\n                \"HybridIndex requires at least two indices to be provided during initialization\"\n            )\n        self.retrievers = retrievers\n        self.k = k\n\n    def _combine_results(\n        self,\n        query_retriever: Callable[[InnerIndex], pw.Table],\n        query_table: pw.Table,\n        number_of_matches: pw.ColumnExpression | int,\n        *,\n        as_of_now: bool,\n    ) -> pw.Table:\n        @pw.udf(deterministic=True)\n        def enumerate_results(\n            results: list[tuple[pw.Pointer, float]]\n        ) -> list[tuple[int, pw.Pointer]]:\n            return [(i, x[0]) for i, x in enumerate(results, start=1)]","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/stdlib/indexing/hybrid_index.py#L11-L47","documentation":"HybridIndex combines multiple retrieval indices using Reciprocal Rank Fusion: each index is queried and each retrieved row gets score 1/(k+rank) summed over all indices. Combining requires at least two constituent retrievers — a single one adds nothing over using it directly. The constructor therefore raises ValueError when retrievers has fewer than two entries (including an empty list).","triggerScenarios":"Instantiating HybridIndex(retrievers=[single_index]) or HybridIndex(retrievers=[]); commonly when the retriever list is built dynamically from config (e.g. enabled retrievers in an RAG pipeline config) and only one ends up enabled.","commonSituations":"A configurable RAG setup where users toggle retrievers on/off in a YAML config and disable all but one; a list built by appending conditionally where a condition silently filters everything; refactoring from two hard-coded indices to a dynamic list.","solutions":["Pass at least two index objects, e.g. HybridIndex(retrievers=[bm25_index, knn_index]).","If only one retriever is available, skip HybridIndex entirely and use that retriever directly.","Validate the retriever list length against config before building the hybrid index and fail with a config-level message."],"exampleFix":"# before\nretrievers = [knn_index]  # bm25 disabled in config\nindex = HybridIndex(retrievers=retrievers)\n\n# after\nretrievers = [knn_index, bm25_index]\nindex = HybridIndex(retrievers=retrievers)\n# or, with a single retriever:\nindex = knn_index","handlingStrategy":"validation","validationCode":"def build_hybrid(retrievers, k=60):\n    if len(retrievers) >= 2:\n        return HybridIndex(retrievers=retrievers, k=k)\n    if len(retrievers) == 1:\n        return retrievers[0]\n    raise ValueError(\"no retrievers configured\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate retriever lists from config at load time: assert 2+ enabled retrievers or fall back to the single retriever directly.","Warn (not just error) when a config leaves exactly one retriever enabled, since it usually signals a misconfiguration."],"tags":["pathway","hybrid-index","rag","validation"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}