Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return metadata when searching for DingoDB #12937

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/docs/integrations/vectorstores/dingo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 17 additions & 4 deletions libs/langchain/langchain/vectorstores/dingo.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,11 @@ def __init__(
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
Expand Down Expand Up @@ -177,8 +181,9 @@ def similarity_search_with_score(
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
Expand Down Expand Up @@ -318,12 +323,20 @@ def from_texts(
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
Expand Down