{"record":{"id":"c574a6fa762c3ca7","repo":"pathwaycom/pathway","slug":"hybridindexfactory-requires-at-least-two-retriever","errorCode":null,"errorMessage":"HybridIndexFactory requires at least two retriever factories to be provided during initialization","messagePattern":"HybridIndexFactory requires at least two retriever factories to be provided during initialization","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/pathway/stdlib/indexing/hybrid_index.py","lineNumber":172,"sourceCode":"            )\n\n        return self._combine_results(\n            query_retriever, query_column.table, number_of_matches, as_of_now=True\n        )\n\n\nclass HybridIndexFactory(InnerIndexFactory):\n    \"\"\"\n    Factory for creating hybrid indices.\n\n    Args:\n        retriever_factories: list of factories of indices that will be used in the hybrid index\n        k: constant used for calculating ranking score.\n    \"\"\"\n\n    def __init__(self, retriever_factories: list[InnerIndexFactory], k: float = 60):\n        if len(retriever_factories) < 2:\n            raise ValueError(\n                \"HybridIndexFactory requires at least two retriever factories to be provided during initialization\"\n            )\n        self.retriever_factories = retriever_factories\n        self.k = k\n\n    def build_inner_index(\n        self,\n        data_column: pw.ColumnReference,\n        metadata_column: pw.ColumnExpression | None = None,\n    ) -> InnerIndex:\n        retrievers = [\n            retriever_factory.build_inner_index(data_column, metadata_column)\n            for retriever_factory in self.retriever_factories\n        ]\n        hybrid_index = HybridIndex(retrievers, self.k)\n        return hybrid_index\n","sourceCodeStart":154,"sourceCodeEnd":189,"githubUrl":"https://github.com/pathwaycom/pathway/blob/fa2f74a4649b7c5908690cf60137263d8d80de5f/python/pathway/stdlib/indexing/hybrid_index.py#L154-L189","documentation":"HybridIndexFactory is the declarative counterpart of HybridIndex: it takes a list of InnerIndexFactory objects and builds a HybridIndex from the indices they produce. Reciprocal Rank Fusion over fewer than two retriever factories is meaningless, so the constructor raises ValueError when retriever_factories has length < 2, mirroring the HybridIndex check.","triggerScenarios":"Constructing HybridIndexFactory(retriever_factories=[f]) or with an empty list — typically when the factory list comes from user configuration (which embedders/retrievers are enabled) and only one survives filtering.","commonSituations":"Declarative RAG pipelines (pw.xpacks.llm) assembling factories from a config file where one retriever is disabled; conditionally appending factories with a bug that skips all but one; passing a single factory while prototyping.","solutions":["Provide at least two factories, e.g. HybridIndexFactory(retriever_factories=[UsearchKnnFactory(...), TantivyBM25Factory(...)]).","If only one retriever type is wanted, use that factory directly instead of wrapping it in HybridIndexFactory.","Add a startup assertion len(retriever_factories) >= 2 in the config-loading code with a clear config error message."],"exampleFix":"# before\nfactory = HybridIndexFactory(retriever_factories=[UsearchKnnFactory(dimensions=384)])\n\n# after\nfactory = HybridIndexFactory(retriever_factories=[\n    UsearchKnnFactory(dimensions=384),\n    TantivyBM25Factory(),\n])","handlingStrategy":"validation","validationCode":"def build_hybrid_factory(factories, k=60):\n    if len(factories) >= 2:\n        return HybridIndexFactory(retriever_factories=factories, k=k)\n    if len(factories) == 1:\n        return factories[0]\n    raise ValueError(\"no retriever factories configured\")","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat factory lists parsed from user config as untrusted input: validate length and element types before constructing Pathway objects.","Keep a single config schema validator that runs at startup and reports all such misconfigurations at once."],"tags":["pathway","hybrid-index","rag","factory","validation"],"backgroundTag":null,"analyzedSha":"fa2f74a4649b7c5908690cf60137263d8d80de5f","analyzedAt":"2026-08-15T01:48:17.006Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}