Merge branch 'refs/heads/develop' into fix/memory_bug_fix
This commit is contained in:
@@ -81,7 +81,7 @@ class DataConfigRepository:
|
||||
n.description AS description,
|
||||
n.entity_type AS entity_type,
|
||||
n.name AS name,
|
||||
n.fact_summary AS fact_summary,
|
||||
COALESCE(n.fact_summary, '') AS fact_summary,
|
||||
n.group_id AS group_id,
|
||||
n.apply_id AS apply_id,
|
||||
n.user_id AS user_id,
|
||||
@@ -115,7 +115,7 @@ class DataConfigRepository:
|
||||
description: n.description,
|
||||
entity_type: n.entity_type,
|
||||
name: n.name,
|
||||
fact_summary: n.fact_summary,
|
||||
fact_summary: COALESCE(n.fact_summary, ''),
|
||||
id: n.id
|
||||
} AS sourceNode,
|
||||
{
|
||||
@@ -132,7 +132,7 @@ class DataConfigRepository:
|
||||
description: m.description,
|
||||
entity_type: m.entity_type,
|
||||
name: m.name,
|
||||
fact_summary: m.fact_summary,
|
||||
fact_summary: COALESCE(m.fact_summary, ''),
|
||||
id: m.id
|
||||
} AS targetNode
|
||||
"""
|
||||
|
||||
@@ -25,7 +25,7 @@ class MemoryIncrementRepository:
|
||||
MemoryIncrement,
|
||||
func.row_number().over(
|
||||
partition_by=func.date(MemoryIncrement.created_at), # 按日期分区
|
||||
order_by=MemoryIncrement.created_at.desc() # 按时间戳升序排序
|
||||
order_by=MemoryIncrement.created_at.desc() # 按时间戳降序排序,取每天最新的
|
||||
).label('row_num')
|
||||
)
|
||||
.filter(MemoryIncrement.workspace_id == workspace_id)
|
||||
@@ -34,14 +34,24 @@ class MemoryIncrementRepository:
|
||||
|
||||
memory_increment_alias = aliased(MemoryIncrement, subquery)
|
||||
|
||||
memory_increments = (
|
||||
# 先取最近的limit条记录的子查询
|
||||
recent_records_subquery = (
|
||||
self.db.query(memory_increment_alias)
|
||||
.filter(subquery.c.row_num == 1) # 只取每个日期的第一条(最新的)
|
||||
.order_by(memory_increment_alias.created_at.asc()) # 按时间戳降序排序
|
||||
.order_by(memory_increment_alias.created_at.desc()) # 按时间戳降序排序,取最近的
|
||||
.limit(limit)
|
||||
.subquery()
|
||||
)
|
||||
|
||||
# 在外层按升序排列(从旧到新)
|
||||
recent_alias = aliased(MemoryIncrement, recent_records_subquery)
|
||||
memory_increments = (
|
||||
self.db.query(recent_alias)
|
||||
.order_by(recent_alias.created_at.asc()) # 按时间戳升序排序
|
||||
.all()
|
||||
)
|
||||
db_logger.info(f"成功查询工作空间 {workspace_id} 下的内存增量")
|
||||
|
||||
db_logger.info(f"成功查询工作空间 {workspace_id} 下的内存增量,返回最近 {len(memory_increments)} 条记录")
|
||||
return memory_increments
|
||||
except Exception as e:
|
||||
db_logger.error(f"查询工作空间 {workspace_id} 下内存增量时出错: {str(e)}")
|
||||
|
||||
@@ -332,7 +332,7 @@ RETURN e.id AS id,
|
||||
e.description AS description,
|
||||
e.aliases AS aliases,
|
||||
e.name_embedding AS name_embedding,
|
||||
e.fact_summary AS fact_summary,
|
||||
COALESCE(e.fact_summary, '') AS fact_summary,
|
||||
e.connect_strength AS connect_strength,
|
||||
collect(DISTINCT s.id) AS statement_ids,
|
||||
collect(DISTINCT c.id) AS chunk_ids,
|
||||
|
||||
Reference in New Issue
Block a user