From 113ae59f84c587c14d644a1aa620b61cd09b90cd Mon Sep 17 00:00:00 2001 From: lanceyq <1982376970@qq.com> Date: Fri, 17 Apr 2026 17:33:17 +0800 Subject: [PATCH 1/2] refactor(memory): insert new metadata values at list head for recency ordering Change list.append() to list.insert(0, ...) in extract_user_metadata_task so that newly extracted user metadata values appear at the front of each field list, maintaining a newest-first ordering. --- api/app/tasks.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/api/app/tasks.py b/api/app/tasks.py index 6d2e07a3..8bbbdc6e 100644 --- a/api/app/tasks.py +++ b/api/app/tasks.py @@ -3160,7 +3160,8 @@ def extract_user_metadata_task( if action == "set": if value not in current_list: - current_list.append(value) + # 新值插入列表头部,保证按时间从新到旧排序 + current_list.insert(0, value) target[leaf] = current_list logger.info(f"[CELERY METADATA] set {field_path} = {value}") @@ -3223,7 +3224,8 @@ def extract_user_metadata_task( leaf = parts[-1] current_list = target.get(leaf, []) if change.value not in current_list: - current_list.append(change.value) + # 新值插入列表头部,保证按时间从新到旧排序 + current_list.insert(0, change.value) target[leaf] = current_list if first_alias or initial_meta: From ecdad19f5408dc214aa992b2e8b4d02b3a137f9d Mon Sep 17 00:00:00 2001 From: lanceyq <1982376970@qq.com> Date: Fri, 17 Apr 2026 17:54:54 +0800 Subject: [PATCH 2/2] perf(memory): truncate profile list fields to 5 items in get_end_user_info response Limit role, domain, expertise, and interests arrays to MAX_PROFILE_LIST_SIZE (5) entries when returning end user info to reduce response payload size. --- api/app/services/user_memory_service.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/app/services/user_memory_service.py b/api/app/services/user_memory_service.py index fdc27115..4d120d8c 100644 --- a/api/app/services/user_memory_service.py +++ b/api/app/services/user_memory_service.py @@ -401,12 +401,21 @@ class UserMemoryService: # 构建响应数据(转换时间为毫秒时间戳) # 将 meta_data 中的 profile、knowledge_tags、behavioral_hints 平铺到顶层 meta = end_user_info_record.meta_data or {} + + # profile 列表字段截断:只返回前 MAX_PROFILE_LIST_SIZE 条(按时间从新到旧) + MAX_PROFILE_LIST_SIZE = 5 + profile = meta.get("profile") + if isinstance(profile, dict): + for key in ("role", "domain", "expertise", "interests"): + if isinstance(profile.get(key), list): + profile[key] = profile[key][:MAX_PROFILE_LIST_SIZE] + response_data = { "end_user_info_id": str(end_user_info_record.id), "end_user_id": str(end_user_info_record.end_user_id), "other_name": end_user_info_record.other_name, "aliases": end_user_info_record.aliases, - "profile": meta.get("profile"), + "profile": profile, "knowledge_tags": meta.get("knowledge_tags"), "behavioral_hints": meta.get("behavioral_hints"), "created_at": datetime_to_timestamp(end_user_info_record.created_at),