From 00c96ec15047fd778544282150cc0a7dc1821bb9 Mon Sep 17 00:00:00 2001 From: Jithin James <jamesjithin97@gmail.com> Date: Wed, 21 Jun 2023 21:59:31 +0530 Subject: [PATCH] Fix: use "generation" as default response_mode for EmptyIndex (#6534) * ignore pyrightconfig.json * use "generation" as default response_mode for EmptyIndex --- .gitignore | 5 ++++- llama_index/indices/empty/base.py | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 217cb9a7c3..9eac2c42f8 100644 --- a/.gitignore +++ b/.gitignore @@ -143,4 +143,7 @@ modules/ # pipenv Pipfile -Pipfile.lock \ No newline at end of file +Pipfile.lock + +# pyright +pyrightconfig.json diff --git a/llama_index/indices/empty/base.py b/llama_index/indices/empty/base.py index ca84f46cd0..07dee2679d 100644 --- a/llama_index/indices/empty/base.py +++ b/llama_index/indices/empty/base.py @@ -11,6 +11,7 @@ from llama_index.data_structs.data_structs import EmptyIndexStruct from llama_index.data_structs.node import Node from llama_index.indices.base import BaseIndex 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.storage.docstore.types import RefDocInfo @@ -48,6 +49,15 @@ class EmptyIndex(BaseIndex[EmptyIndexStruct]): 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: """Build the index from documents. -- GitLab