From ce682f5a094b184936e60c4e70509d6204b4e4fa Mon Sep 17 00:00:00 2001 From: Jaskirat Singh Date: Tue, 27 Feb 2024 02:17:06 +0530 Subject: [PATCH] community: vectorstores.kdbai - Added support for when no docs are present (#18103) - **Description:** By default it expects a list but that's not the case in corner scenarios when there is no document ingested(use case: Bootstrap application). \ Hence added as check, if the instance is panda Dataframe instead of list then it will procced with return immediately. - **Issue:** NA - **Dependencies:** NA - **Twitter handle:** jaskiratsingh1 --------- Co-authored-by: Harrison Chase --- .../langchain_community/vectorstores/kdbai.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/libs/community/langchain_community/vectorstores/kdbai.py b/libs/community/langchain_community/vectorstores/kdbai.py index d996df12dfe..9b1310293b0 100644 --- a/libs/community/langchain_community/vectorstores/kdbai.py +++ b/libs/community/langchain_community/vectorstores/kdbai.py @@ -217,10 +217,12 @@ class KDBAI(VectorStore): """ if "n" in kwargs: k = kwargs.pop("n") - matches = self._table.search(vectors=[embedding], n=k, filter=filter, **kwargs)[ - 0 - ] - docs = [] + matches = self._table.search(vectors=[embedding], n=k, filter=filter, **kwargs) + docs: list = [] + if isinstance(matches, list): + matches = matches[0] + else: + return docs for row in matches.to_dict(orient="records"): text = row.pop("text") score = row.pop("__nn_distance")