fix(storage): 修复 get_node_by_id 函数中的 ids 列表检查逻辑,避免 numpy 数组歧义
This commit is contained in:
@@ -209,7 +209,8 @@ class VectorStore:
|
|||||||
# 解析结果
|
# 解析结果
|
||||||
import orjson
|
import orjson
|
||||||
similar_nodes = []
|
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]):
|
for i, node_id in enumerate(results["ids"][0]):
|
||||||
# ChromaDB 返回的是距离,需要转换为相似度
|
# ChromaDB 返回的是距离,需要转换为相似度
|
||||||
# 余弦距离: distance = 1 - similarity
|
# 余弦距离: distance = 1 - similarity
|
||||||
@@ -367,7 +368,8 @@ class VectorStore:
|
|||||||
try:
|
try:
|
||||||
result = self.collection.get(ids=[node_id], include=["metadatas", "embeddings"])
|
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 {
|
return {
|
||||||
"id": result["ids"][0],
|
"id": result["ids"][0],
|
||||||
"metadata": result["metadatas"][0] if result["metadatas"] else {},
|
"metadata": result["metadatas"][0] if result["metadatas"] else {},
|
||||||
|
|||||||
Reference in New Issue
Block a user