Skip to content
Snippets Groups Projects
Unverified Commit 00c96ec1 authored by Jithin James's avatar Jithin James Committed by GitHub
Browse files

Fix: use "generation" as default response_mode for EmptyIndex (#6534)

* ignore pyrightconfig.json

* use "generation" as default response_mode for EmptyIndex
parent 90a0016f
No related branches found
No related tags found
No related merge requests found
...@@ -143,4 +143,7 @@ modules/ ...@@ -143,4 +143,7 @@ modules/
# pipenv # pipenv
Pipfile Pipfile
Pipfile.lock Pipfile.lock
\ No newline at end of file
# pyright
pyrightconfig.json
...@@ -11,6 +11,7 @@ from llama_index.data_structs.data_structs import EmptyIndexStruct ...@@ -11,6 +11,7 @@ from llama_index.data_structs.data_structs import EmptyIndexStruct
from llama_index.data_structs.node import Node from llama_index.data_structs.node import Node
from llama_index.indices.base import BaseIndex from llama_index.indices.base import BaseIndex
from llama_index.indices.base_retriever import BaseRetriever from llama_index.indices.base_retriever import BaseRetriever
from llama_index.indices.query.base import BaseQueryEngine
from llama_index.indices.service_context import ServiceContext from llama_index.indices.service_context import ServiceContext
from llama_index.storage.docstore.types import RefDocInfo from llama_index.storage.docstore.types import RefDocInfo
...@@ -48,6 +49,15 @@ class EmptyIndex(BaseIndex[EmptyIndexStruct]): ...@@ -48,6 +49,15 @@ class EmptyIndex(BaseIndex[EmptyIndexStruct]):
return EmptyIndexRetriever(self) return EmptyIndexRetriever(self)
def as_query_engine(self, **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(**kwargs)
def _build_index_from_nodes(self, nodes: Sequence[Node]) -> EmptyIndexStruct: def _build_index_from_nodes(self, nodes: Sequence[Node]) -> EmptyIndexStruct:
"""Build the index from documents. """Build the index from documents.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment