Fix return metadata when searching for DingoDB (#12937)

This commit is contained in:
Hech
2023-11-06 23:35:36 +08:00
committed by GitHub
parent ada3d2cbd1
commit 8fe6bcc662
2 changed files with 19 additions and 6 deletions

View File

@@ -66,7 +66,11 @@ class Dingo(VectorStore):
self._text_key = text_key
self._client = dingo_client
if index_name is not None and index_name not in dingo_client.get_index():
if (
index_name is not None
and index_name not in dingo_client.get_index()
and index_name.upper() not in dingo_client.get_index()
):
if self_id is True:
dingo_client.create_index(
index_name, dimension=dimension, auto_id=False
@@ -177,8 +181,9 @@ class Dingo(VectorStore):
id = res["id"]
score = res["distance"]
text = metadatas[self._text_key]["fields"][0]["data"]
metadata = {"id": id, "text": text, "score": score}
for meta_key in metadatas.keys():
metadata[meta_key] = metadatas[meta_key]["fields"][0]["data"]
docs.append((Document(page_content=text, metadata=metadata), score))
return docs
@@ -318,12 +323,20 @@ class Dingo(VectorStore):
except ValueError as e:
raise ValueError(f"Dingo failed to connect: {e}")
if kwargs is not None and kwargs.get("self_id") is True:
if index_name not in dingo_client.get_index():
if (
index_name is not None
and index_name not in dingo_client.get_index()
and index_name.upper() not in dingo_client.get_index()
):
dingo_client.create_index(
index_name, dimension=dimension, auto_id=False
)
else:
if index_name not in dingo_client.get_index():
if (
index_name is not None
and index_name not in dingo_client.get_index()
and index_name.upper() not in dingo_client.get_index()
):
dingo_client.create_index(index_name, dimension=dimension)
# Embed and create the documents