fix(memory): add coalesce defaults for activation_value and related node properties

- Add coalesce fallbacks for importance_score, activation_value, and
access_count in statement, entity, weak entity, strong entity, and
memory summary MERGE queries to prevent null values on new nodes
- Set activation_value default to coalesce(importance_score, 0.5) for
consistency with the forgetting/activation scoring logic
- Suppress Neo4j UNRECOGNIZED property key notifications in driver init
since missing keys like last_access_time and activation_value are
expected for newly created nodes
This commit is contained in:
lanceyq
2026-04-17 13:54:12 +08:00
parent 643f69bb90
commit 34387e1f23
2 changed files with 17 additions and 3 deletions

View File

@@ -9,12 +9,15 @@ Classes:
"""
from typing import Any, List, Dict
import logging
from neo4j import AsyncGraphDatabase, basic_auth
from neo4j.time import DateTime as Neo4jDateTime, Date as Neo4jDate, Time as Neo4jTime, Duration as Neo4jDuration
from app.core.config import settings
logger = logging.getLogger(__name__)
def _convert_neo4j_types(value: Any) -> Any:
"""递归将 neo4j 原生时间类型转为 Python 原生类型 / ISO 字符串,确保可被 json.dumps 序列化。"""
@@ -67,7 +70,12 @@ class Neo4jConnector:
)
self.driver = AsyncGraphDatabase.driver(
uri,
auth=basic_auth(username, password)
auth=basic_auth(username, password),
# 抑制属性键不存在的 UNRECOGNIZED 分类通知警告(如 01N52
# last_access_time 等属性在节点被检索命中后才写入,
# activation_value 在新节点创建后可能尚未被计算,
# 全新数据库或清空数据后这些属性键不存在是正常业务行为
notifications_disabled_classifications=["UNRECOGNIZED"],
)
async def close(self):