Skip to content

fix: Search_memories在默认dedup=mmr下调试用 info 日志打印完整 embedding 向量 #2103

Description

@Lilili-04

Pre-submission checklist | 提交前检查

  • I have searched existing issues and this hasn't been mentioned before | 我已搜索现有问题,确认此问题尚未被提及
  • I have read the project documentation and confirmed this issue doesn't already exist | 我已阅读项目文档并确认此问题尚未存在
  • This issue is specific to MemOS and not a general software issue | 该问题是针对 MemOS 的,而不是一般软件问题

Bug Description | 问题描述

src/memos/multi_mem_cube/single_cube.pySingleCubeView.search_memories(约 L89–134)中,搜索结果组装完成后会用 logger.info 直接打印整个 memories_result

# src/memos/multi_mem_cube/single_cube.py:132-133
self.logger.info(f"Search memories result: {memories_result}")
self.logger.info(f"Search {len(memories_result)} memories.")

搜索路径里,当 dedupmmrsim 时,format_memory_item(..., include_embedding=True)src/memos/api/handlers/formatters_handler.py)会保留每条 memory 的 metadata.embedding 高维向量。

APISearchRequest 的默认值是:

  • mode=fast
  • dedup=mmr

因此在默认配置下,每次 search 都会把完整 embedding 向量打进日志,带来:

  1. 日志暴涨:单条记忆通常是数百~上千维浮点数组,top_k 稍大时一次搜索可产生数 MB 日志。
  2. 噪声掩盖真正有用的信息:难以从日志中快速定位记忆 ID / 文本 / 分数等关键字段。
  3. 潜在隐私 / 合规风险:向量可能被用于近似还原语义内容,不宜无条件写入日志。

How to Reproduce | 如何重现

  1. 部署 MemOS API(含可写入的文本记忆),确认日志级别为 INFO
  2. 向已有记忆的用户发起一次默认参数搜索(无需显式设置 dedup),例如:
curl -X POST "http://localhost:8000/product/search" \
  -H "Content-Type: application/json" \
  -d '{
    "user_id": "<your_user_id>",
    "query": "test query",
    "top_k": 5
  }'
  1. 查看服务日志,定位类似输出:
Search memories result: {'text_mem': [{'cube_id': '...', 'memories': [{..., 'metadata': {'embedding': [0.0123, -0.0456, ...], ...}}]}], ...}
  1. (对照)将请求改为 "dedup": "no" 再搜索一次,日志中 embedding 应变为空列表 [],可确认向量内容来自 include_embedding=True 分支。

Environment | 环境信息

| MemOS 版本 | 2.0.23 |
| 相关代码 | src/memos/multi_mem_cube/single_cube.pySingleCubeView.search_memories L132–133 |
| 默认参数 | mode=fast, dedup=mmrAPISearchRequest) |

Additional Context | 其他信息

No response

Willingness to Implement | 实现意愿

  • I'm willing to implement this myself | 我愿意自己解决
  • I would like someone else to implement this | 我希望其他人来解决

Metadata

Metadata

Labels

ai:taskDispatched to AI coding agent | 已派发给 AI 编码任务ai:testingAI agent is running tests | AI 正在运行测试status:in-progressSomeone or AI is working on it | 人工或 AI 正在处理

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions