Merge #48 into develop from fix/othername-name
[fix]Fix the data structure + implement memory dashboard display * fix/othername-name: (18 commits squashed) - [fix]Fix the issue with the display of the user's memory list - [fix]Ensure the six dimensions of emotional expression - [fix]Fix the issue with the display of the user's memory list - [fix]Ensure the six dimensions of emotional expression - Merge branch 'fix/othername-name' of codeup.aliyun.com:redbearai/python/redbear-mem-open into fix/othername-name - [fix]Restore the display of memory types - [fix]Fix the issue with the display of the user's memory list - [fix]Ensure the six dimensions of emotional expression - [fix]Restore the display of memory types - Merge branch 'fix/othername-name' of codeup.aliyun.com:redbearai/python/redbear-mem-open into fix/othername-name - [updated]Update the title of the "analytics/node_statistics" log - [fix]Fix the data structure + implement memory dashboard display - [fix]Fix the issue with the display of the user's memory list - [fix]Restore the display of memory types - [fix]Fix the issue with the display of the user's memory list - [fix]Restore the display of memory types - [fix]Fix the data structure + implement memory dashboard display - Merge branch 'fix/othername-name' of codeup.aliyun.com:redbearai/python/redbear-mem-open into fix/othername-name Signed-off-by: 乐力齐 <accounts_690c7b0af9007d7e338af636@mail.teambition.com> Reviewed-by: aliyun6762716068 <accounts_68cb7c6b61f5dcc4200d6251@mail.teambition.com> Merged-by: aliyun6762716068 <accounts_68cb7c6b61f5dcc4200d6251@mail.teambition.com> CR-link: https://codeup.aliyun.com/redbearai/python/redbear-mem-open/change/48
This commit is contained in:
@@ -192,7 +192,9 @@ async def get_node_statistics_api(
|
||||
# 调用新的记忆类型统计函数
|
||||
result = await analytics_memory_types(db, end_user_id)
|
||||
|
||||
api_logger.info(f"成功获取记忆类型统计: end_user_id={end_user_id}, 感知记忆={result.get('感知记忆', 0)}")
|
||||
# 计算总数用于日志
|
||||
total_count = sum(item["count"] for item in result)
|
||||
api_logger.info(f"成功获取记忆类型统计: end_user_id={end_user_id}, 总记忆数={total_count}, 类型数={len(result)}")
|
||||
return success(data=result, msg="查询成功")
|
||||
except Exception as e:
|
||||
api_logger.error(f"记忆类型查询失败: end_user_id={end_user_id}, error={str(e)}")
|
||||
|
||||
@@ -298,10 +298,10 @@ async def get_workspace_total_memory_count(
|
||||
details.append({
|
||||
"end_user_id": end_user_id_str,
|
||||
"count": host_total,
|
||||
"name": host.name # 添加 name 字段
|
||||
"name": host.other_name # 使用 other_name 字段
|
||||
})
|
||||
|
||||
business_logger.debug(f"EndUser {end_user_id_str} ({host.name}) 记忆数: {host_total}")
|
||||
business_logger.debug(f"EndUser {end_user_id_str} ({host.other_name}) 记忆数: {host_total}")
|
||||
|
||||
except Exception as e:
|
||||
business_logger.warning(f"获取 end_user {host.id} 记忆数失败: {str(e)}")
|
||||
@@ -309,7 +309,7 @@ async def get_workspace_total_memory_count(
|
||||
details.append({
|
||||
"end_user_id": str(host.id),
|
||||
"count": 0,
|
||||
"name": host.name # 添加 name 字段
|
||||
"name": host.other_name # 使用 other_name 字段
|
||||
})
|
||||
|
||||
result = {
|
||||
|
||||
@@ -537,35 +537,43 @@ async def analytics_node_statistics(
|
||||
async def analytics_memory_types(
|
||||
db: Session,
|
||||
end_user_id: Optional[str] = None
|
||||
) -> Dict[str, Any]:
|
||||
) -> List[Dict[str, Any]]:
|
||||
"""
|
||||
统计8种记忆类型的数量
|
||||
统计8种记忆类型的数量和百分比
|
||||
|
||||
计算规则:
|
||||
1. 感知记忆 = statement + entity
|
||||
2. 工作记忆 = chunk + entity
|
||||
3. 短期记忆 = chunk
|
||||
4. 长期记忆 = entity
|
||||
5. 显性记忆 = 1/2 * entity
|
||||
6. 隐形记忆 = 1/3 * entity
|
||||
7. 情绪记忆 = statement
|
||||
8. 情景记忆 = memory_summary
|
||||
1. 感知记忆 (PERCEPTUAL_MEMORY) = statement + entity
|
||||
2. 工作记忆 (WORKING_MEMORY) = chunk + entity
|
||||
3. 短期记忆 (SHORT_TERM_MEMORY) = chunk
|
||||
4. 长期记忆 (LONG_TERM_MEMORY) = entity
|
||||
5. 显性记忆 (EXPLICIT_MEMORY) = 1/2 * entity
|
||||
6. 隐性记忆 (IMPLICIT_MEMORY) = 1/3 * entity
|
||||
7. 情绪记忆 (EMOTIONAL_MEMORY) = statement
|
||||
8. 情景记忆 (EPISODIC_MEMORY) = memory_summary
|
||||
|
||||
Args:
|
||||
db: 数据库会话
|
||||
end_user_id: 可选的终端用户ID (UUID),用于过滤特定用户的节点
|
||||
|
||||
Returns:
|
||||
{
|
||||
"感知记忆": int,
|
||||
"工作记忆": int,
|
||||
"短期记忆": int,
|
||||
"长期记忆": int,
|
||||
"显性记忆": int,
|
||||
"隐形记忆": int,
|
||||
"情绪记忆": int,
|
||||
"情景记忆": int
|
||||
}
|
||||
[
|
||||
{
|
||||
"type": str, # 记忆类型枚举值 (如 PERCEPTUAL_MEMORY, WORKING_MEMORY 等)
|
||||
"count": int, # 该类型的数量
|
||||
"percentage": float # 该类型在所有记忆中的占比
|
||||
},
|
||||
...
|
||||
]
|
||||
|
||||
记忆类型枚举值:
|
||||
- PERCEPTUAL_MEMORY: 感知记忆
|
||||
- WORKING_MEMORY: 工作记忆
|
||||
- SHORT_TERM_MEMORY: 短期记忆
|
||||
- LONG_TERM_MEMORY: 长期记忆
|
||||
- EXPLICIT_MEMORY: 显性记忆
|
||||
- IMPLICIT_MEMORY: 隐性记忆
|
||||
- EMOTIONAL_MEMORY: 情绪记忆
|
||||
- EPISODIC_MEMORY: 情景记忆
|
||||
"""
|
||||
# 定义需要查询的节点类型
|
||||
node_types = {
|
||||
@@ -604,18 +612,31 @@ async def analytics_memory_types(
|
||||
chunk_count = node_counts.get("Chunk", 0)
|
||||
memory_summary_count = node_counts.get("MemorySummary", 0)
|
||||
|
||||
# 按规则计算8种记忆类型
|
||||
memory_types = {
|
||||
"感知记忆": statement_count + entity_count,
|
||||
"工作记忆": chunk_count + entity_count,
|
||||
"短期记忆": chunk_count,
|
||||
"长期记忆": entity_count,
|
||||
"显性记忆": entity_count // 2, # 1/2 entity,使用整除
|
||||
"隐形记忆": entity_count // 3, # 1/3 entity,使用整除
|
||||
"情绪记忆": statement_count,
|
||||
"情景记忆": memory_summary_count
|
||||
# 按规则计算8种记忆类型的数量(使用英文枚举作为key)
|
||||
memory_counts = {
|
||||
"PERCEPTUAL_MEMORY": statement_count + entity_count, # 感知记忆
|
||||
"WORKING_MEMORY": chunk_count + entity_count, # 工作记忆
|
||||
"SHORT_TERM_MEMORY": chunk_count, # 短期记忆
|
||||
"LONG_TERM_MEMORY": entity_count, # 长期记忆
|
||||
"EXPLICIT_MEMORY": entity_count // 2, # 显性记忆 (1/2 entity)
|
||||
"IMPLICIT_MEMORY": entity_count // 3, # 隐性记忆 (1/3 entity)
|
||||
"EMOTIONAL_MEMORY": statement_count, # 情绪记忆
|
||||
"EPISODIC_MEMORY": memory_summary_count # 情景记忆
|
||||
}
|
||||
|
||||
# 计算总数
|
||||
total = sum(memory_counts.values())
|
||||
|
||||
# 构建返回数据,包含 type、count 和 percentage
|
||||
memory_types = []
|
||||
for memory_type, count in memory_counts.items():
|
||||
percentage = round((count / total * 100), 2) if total > 0 else 0.0
|
||||
memory_types.append({
|
||||
"type": memory_type,
|
||||
"count": count,
|
||||
"percentage": percentage
|
||||
})
|
||||
|
||||
return memory_types
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user