run-llama/llama_index · error · ValueError

EmptyIndex only supports response_mode=generation.

Error message

EmptyIndex only supports response_mode=generation.

What it means

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.

Source

Thrown at llama-index-core/llama_index/core/indices/empty/base.py:59

            nodes=None,
            index_struct=index_struct or EmptyIndexStruct(),
            **kwargs,
        )

    def as_retriever(self, **kwargs: Any) -> BaseRetriever:
        # NOTE: lazy import
        from llama_index.core.indices.empty.retrievers import EmptyIndexRetriever

        return EmptyIndexRetriever(self)

    def as_query_engine(
        self, llm: Optional[LLMType] = None, **kwargs: Any
    ) -> BaseQueryEngine:
        if "response_mode" not in kwargs:
            kwargs["response_mode"] = "generation"
        else:
            if kwargs["response_mode"] != "generation":
                raise ValueError("EmptyIndex only supports response_mode=generation.")

        return super().as_query_engine(llm=llm, **kwargs)

    def _build_index_from_nodes(
        self, nodes: Sequence[BaseNode], **build_kwargs: Any
    ) -> EmptyIndexStruct:
        """
        Build the index from documents.

        Args:
            documents (List[BaseDocument]): A list of documents.

        Returns:
            IndexList: The created summary index.

        """
        del nodes  # Unused
        return EmptyIndexStruct()

View on GitHub (pinned to afd0fef371)

Solutions

  1. Drop response_mode from the kwargs passed to EmptyIndex.as_query_engine — 'generation' is already the default and the only valid value.
  2. 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.
  3. Switch to a SummaryIndex (with at least one node) if you need 'compact' or 'tree_summarize' behavior.

Example fix

// before
query_engine = empty_index.as_query_engine(response_mode="compact")

// after
query_engine = empty_index.as_query_engine()  # defaults to response_mode="generation"
Defensive patterns

Strategy: validation

Validate before calling

from llama_index.core.indices.empty import EmptyIndex

if isinstance(index, EmptyIndex):
    kwargs.pop("response_mode", None)  # only 'generation' is legal
query_engine = index.as_query_engine(**kwargs)

Type guard

from llama_index.core.indices.empty import EmptyIndex

def is_empty_index(index: object) -> bool:
    return isinstance(index, EmptyIndex)

Try / catch

try:
    engine = empty_index.as_query_engine(**kwargs)
except ValueError as e:
    if "response_mode" in str(e):
        kwargs.pop("response_mode", None)
        engine = empty_index.as_query_engine(**kwargs)
    else:
        raise

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of run-llama/llama_index@afd0fef371 (2026-08-15). Data as JSON: /api/errors/0ab9055b5be28a16. Report an issue: GitHub.