From ca237e7d59b6b498cfb511b3b144d459212f01f0 Mon Sep 17 00:00:00 2001 From: Windpicker-owo <3431391539@qq.com> Date: Thu, 6 Nov 2025 18:36:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(storage):=20=E4=BF=AE=E5=A4=8D=20get=5Fnode?= =?UTF-8?q?=5Fby=5Fid=20=E5=87=BD=E6=95=B0=E4=B8=AD=E7=9A=84=20ids=20?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=A3=80=E6=9F=A5=E9=80=BB=E8=BE=91=EF=BC=8C?= =?UTF-8?q?=E9=81=BF=E5=85=8D=20numpy=20=E6=95=B0=E7=BB=84=E6=AD=A7?= =?UTF-8?q?=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/memory_graph/storage/vector_store.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/memory_graph/storage/vector_store.py b/src/memory_graph/storage/vector_store.py index d65b69d63..9d5b92695 100644 --- a/src/memory_graph/storage/vector_store.py +++ b/src/memory_graph/storage/vector_store.py @@ -209,7 +209,8 @@ class VectorStore: # 解析结果 import orjson similar_nodes = [] - if results["ids"] and results["ids"][0]: + # 修复:检查 ids 列表长度而不是直接判断真值(避免 numpy 数组歧义) + if results.get("ids") is not None and len(results["ids"]) > 0 and len(results["ids"][0]) > 0: for i, node_id in enumerate(results["ids"][0]): # ChromaDB 返回的是距离,需要转换为相似度 # 余弦距离: distance = 1 - similarity @@ -367,7 +368,8 @@ class VectorStore: try: result = self.collection.get(ids=[node_id], include=["metadatas", "embeddings"]) - if result and result["ids"]: + # 修复:检查 ids 列表长度而不是直接判断真值(避免 numpy 数组歧义) + if result and result.get("ids") is not None and len(result["ids"]) > 0: return { "id": result["ids"][0], "metadata": result["metadatas"][0] if result["metadatas"] else {},