{"record":{"id":"0ab9055b5be28a16","repo":"run-llama/llama_index","slug":"emptyindex-only-supports-response-mode-generation","errorCode":null,"errorMessage":"EmptyIndex only supports response_mode=generation.","messagePattern":"EmptyIndex only supports response_mode=generation\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"llama-index-core/llama_index/core/indices/empty/base.py","lineNumber":59,"sourceCode":"            nodes=None,\n            index_struct=index_struct or EmptyIndexStruct(),\n            **kwargs,\n        )\n\n    def as_retriever(self, **kwargs: Any) -> BaseRetriever:\n        # NOTE: lazy import\n        from llama_index.core.indices.empty.retrievers import EmptyIndexRetriever\n\n        return EmptyIndexRetriever(self)\n\n    def as_query_engine(\n        self, llm: Optional[LLMType] = None, **kwargs: Any\n    ) -> BaseQueryEngine:\n        if \"response_mode\" not in kwargs:\n            kwargs[\"response_mode\"] = \"generation\"\n        else:\n            if kwargs[\"response_mode\"] != \"generation\":\n                raise ValueError(\"EmptyIndex only supports response_mode=generation.\")\n\n        return super().as_query_engine(llm=llm, **kwargs)\n\n    def _build_index_from_nodes(\n        self, nodes: Sequence[BaseNode], **build_kwargs: Any\n    ) -> EmptyIndexStruct:\n        \"\"\"\n        Build the index from documents.\n\n        Args:\n            documents (List[BaseDocument]): A list of documents.\n\n        Returns:\n            IndexList: The created summary index.\n\n        \"\"\"\n        del nodes  # Unused\n        return EmptyIndexStruct()","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/run-llama/llama_index/blob/afd0fef371831f9bda13e5af7167cf4e981278ab/llama-index-core/llama_index/core/indices/empty/base.py#L41-L77","documentation":"EmptyIndex is a placeholder index containing no documents; its only supported retrieval strategy is to hand the query straight to the LLM (response_mode='generation'). as_query_engine() defaults response_mode to 'generation', but if you explicitly pass any other value ('compact', 'tree_summarize', 'no_text', etc.) it raises ValueError, because those modes need retrieved nodes and EmptyIndex has none.","triggerScenarios":"Calling EmptyIndex(...).as_query_engine(response_mode='compact') (or any mode other than 'generation'); piping a shared kwargs dict of engine settings into an empty index's as_query_engine; conditionally building a SummaryIndex or EmptyIndex and reusing the same response_mode kwarg for both.","commonSituations":"Apps that fall back to an EmptyIndex chat engine when no documents are loaded, but forward the same response_mode used for a SummaryIndex; config-driven engines where response_mode comes from YAML/env and is applied to every index type.","solutions":["Drop response_mode from the kwargs passed to EmptyIndex.as_query_engine — 'generation' is already the default and the only valid value.","If you share a config across index types, conditionally strip/override response_mode: kwargs.pop('response_mode', None) or force kwargs['response_mode']='generation' when the index is an EmptyIndex.","Switch to a SummaryIndex (with at least one node) if you need 'compact' or 'tree_summarize' behavior."],"exampleFix":"// before\nquery_engine = empty_index.as_query_engine(response_mode=\"compact\")\n\n// after\nquery_engine = empty_index.as_query_engine()  # defaults to response_mode=\"generation\"","handlingStrategy":"validation","validationCode":"from llama_index.core.indices.empty import EmptyIndex\n\nif isinstance(index, EmptyIndex):\n    kwargs.pop(\"response_mode\", None)  # only 'generation' is legal\nquery_engine = index.as_query_engine(**kwargs)","typeGuard":"from llama_index.core.indices.empty import EmptyIndex\n\ndef is_empty_index(index: object) -> bool:\n    return isinstance(index, EmptyIndex)","tryCatchPattern":"try:\n    engine = empty_index.as_query_engine(**kwargs)\nexcept ValueError as e:\n    if \"response_mode\" in str(e):\n        kwargs.pop(\"response_mode\", None)\n        engine = empty_index.as_query_engine(**kwargs)\n    else:\n        raise","preventionTips":["Never forward a shared response_mode config into an EmptyIndex; default it to 'generation'.","Centralize engine construction in one factory so index-type-specific constraints are applied in one place.","Add a unit test asserting as_query_engine works for every index type your config supports."],"tags":["llama-index","empty-index","query-engine","configuration"],"backgroundTag":null,"analyzedSha":"afd0fef371831f9bda13e5af7167cf4e981278ab","analyzedAt":"2026-08-15T05:42:58.429Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}