mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-30 18:33:40 +00:00
Fix return metadata when searching for DingoDB (#12937)
This commit is contained in:
parent
ada3d2cbd1
commit
8fe6bcc662
@ -104,11 +104,11 @@
|
|||||||
"source": [
|
"source": [
|
||||||
"from dingodb import DingoDB\n",
|
"from dingodb import DingoDB\n",
|
||||||
"\n",
|
"\n",
|
||||||
"index_name = \"langchain-demo\"\n",
|
"index_name = \"langchain_demo\"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"dingo_client = DingoDB(user=\"\", password=\"\", host=[\"127.0.0.1:13000\"])\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",
|
"# 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",
|
" # we create a new index, modify to your own\n",
|
||||||
" dingo_client.create_index(\n",
|
" dingo_client.create_index(\n",
|
||||||
" index_name=index_name, dimension=1536, metric_type=\"cosine\", auto_id=False\n",
|
" index_name=index_name, dimension=1536, metric_type=\"cosine\", auto_id=False\n",
|
||||||
|
@ -66,7 +66,11 @@ class Dingo(VectorStore):
|
|||||||
self._text_key = text_key
|
self._text_key = text_key
|
||||||
self._client = dingo_client
|
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:
|
if self_id is True:
|
||||||
dingo_client.create_index(
|
dingo_client.create_index(
|
||||||
index_name, dimension=dimension, auto_id=False
|
index_name, dimension=dimension, auto_id=False
|
||||||
@ -177,8 +181,9 @@ class Dingo(VectorStore):
|
|||||||
id = res["id"]
|
id = res["id"]
|
||||||
score = res["distance"]
|
score = res["distance"]
|
||||||
text = metadatas[self._text_key]["fields"][0]["data"]
|
text = metadatas[self._text_key]["fields"][0]["data"]
|
||||||
|
|
||||||
metadata = {"id": id, "text": text, "score": score}
|
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))
|
docs.append((Document(page_content=text, metadata=metadata), score))
|
||||||
|
|
||||||
return docs
|
return docs
|
||||||
@ -318,12 +323,20 @@ class Dingo(VectorStore):
|
|||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
raise ValueError(f"Dingo failed to connect: {e}")
|
raise ValueError(f"Dingo failed to connect: {e}")
|
||||||
if kwargs is not None and kwargs.get("self_id") is True:
|
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(
|
dingo_client.create_index(
|
||||||
index_name, dimension=dimension, auto_id=False
|
index_name, dimension=dimension, auto_id=False
|
||||||
)
|
)
|
||||||
else:
|
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)
|
dingo_client.create_index(index_name, dimension=dimension)
|
||||||
|
|
||||||
# Embed and create the documents
|
# Embed and create the documents
|
||||||
|
Loading…
Reference in New Issue
Block a user