From 8fe6bcc66241a64dcfafabf7a275bf2ef49b4968 Mon Sep 17 00:00:00 2001 From: Hech <53417823+HeChangHaoGary@users.noreply.github.com> Date: Mon, 6 Nov 2023 23:35:36 +0800 Subject: [PATCH] Fix return metadata when searching for DingoDB (#12937) --- .../integrations/vectorstores/dingo.ipynb | 4 ++-- .../langchain/langchain/vectorstores/dingo.py | 21 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/docs/docs/integrations/vectorstores/dingo.ipynb b/docs/docs/integrations/vectorstores/dingo.ipynb index 05fc615f0b..28635072c3 100644 --- a/docs/docs/integrations/vectorstores/dingo.ipynb +++ b/docs/docs/integrations/vectorstores/dingo.ipynb @@ -104,11 +104,11 @@ "source": [ "from dingodb import DingoDB\n", "\n", - "index_name = \"langchain-demo\"\n", + "index_name = \"langchain_demo\"\n", "\n", "dingo_client = DingoDB(user=\"\", password=\"\", host=[\"127.0.0.1:13000\"])\n", "# First, check if our index already exists. If it doesn't, we create it\n", - "if index_name not in dingo_client.get_index():\n", + "if index_name not in dingo_client.get_index() and index_name.upper() not in dingo_client.get_index():\n", " # we create a new index, modify to your own\n", " dingo_client.create_index(\n", " index_name=index_name, dimension=1536, metric_type=\"cosine\", auto_id=False\n", diff --git a/libs/langchain/langchain/vectorstores/dingo.py b/libs/langchain/langchain/vectorstores/dingo.py index 21a433b8f1..e83a5161d3 100644 --- a/libs/langchain/langchain/vectorstores/dingo.py +++ b/libs/langchain/langchain/vectorstores/dingo.py @@ -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