From 85008ff153bc39817a1acaa3aaaf03ffa57a0e23 Mon Sep 17 00:00:00 2001 From: limbo Date: Wed, 5 Jul 2023 00:48:56 +0800 Subject: [PATCH] Fix: Solve IndexError when no relevant documents are found in the vector db. (#59) --- embedchain/embedchain.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/embedchain/embedchain.py b/embedchain/embedchain.py index e2b8302c..25d68e5c 100644 --- a/embedchain/embedchain.py +++ b/embedchain/embedchain.py @@ -28,7 +28,7 @@ DB_DIR = os.path.join(ABS_PATH, "db") class EmbedChain: def __init__(self, db=None): """ - Initializes the EmbedChain instance, sets up a vector DB client and + Initializes the EmbedChain instance, sets up a vector DB client and creates a collection. :param db: The instance of the VectorDB subclass. @@ -181,7 +181,10 @@ class EmbedChain: n_results=1, ) result_formatted = self._format_result(result) - content = result_formatted[0][0].page_content + if result_formatted: + content = result_formatted[0][0].page_content + else: + content = "" return content def generate_prompt(self, input_query, context):