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 <hw.chase.17@gmail.com>
This commit is contained in:
Jaskirat Singh 2024-02-27 02:17:06 +05:30 committed by GitHub
parent 9b8f6455b1
commit ce682f5a09
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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")