Skip to content

feat(eval): support memos api mode#116

Merged
CaralHsi merged 38 commits intoMemTensor:devfrom
Duguce:dev
Jul 24, 2025
Merged

feat(eval): support memos api mode#116
CaralHsi merged 38 commits intoMemTensor:devfrom
Duguce:dev

Conversation

@Duguce
Copy link
Contributor

@Duguce Duguce commented Jul 17, 2025

Description

Summary: fix some bugs, such as search top k

Fix: #(issue)

Reviewer: @hush-cd

Checklist:

  • I have performed a self-review of my own code | 我已自行检查了自己的代码
  • I have commented my code in hard-to-understand areas | 我已在难以理解的地方对代码进行了注释
  • I have added tests that prove my fix is effective or that my feature works | 我已添加测试以证明我的修复有效或功能正常
  • I have added necessary documentation (if applicable) | 我已添加必要的文档(如果适用)
  • I have linked the issue to this PR (if applicable) | 我已将 issue 链接到此 PR(如果适用)
  • I have mentioned the person who will review this PR | 我已提及将审查此 PR 的人

Copilot AI review requested due to automatic review settings July 17, 2025 10:40

This comment was marked as outdated.

@Duguce Duguce changed the title fix(eval): fix search top k feat(eval): support memos api mode Jul 20, 2025
@Duguce
Copy link
Contributor Author

Duguce commented Jul 21, 2025

@hush-cd can you help me review this pr? thanks!!!

@Duguce Duguce requested a review from Copilot July 21, 2025 02:11
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for a new "memos-api" mode to the evaluation framework, enabling testing of MemOS functionality through API calls instead of just local mode. The changes expand the evaluation capabilities to include both local and API-based testing scenarios.

  • Introduces new MemOSAPI client for HTTP-based communication with MemOS services
  • Updates all evaluation scripts to support "memos-api" mode alongside existing modes
  • Fixes search functionality by implementing proper top_k parameter handling

Reviewed Changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
evaluation/scripts/utils/memos_api.py New MemOSAPI client implementation for HTTP-based MemOS operations
evaluation/scripts/utils/client.py Adds API mode support to memos_client function
evaluation/scripts/run_lme_eval.sh Updates evaluation script configuration and adds new pipeline steps
evaluation/scripts/longmemeval/*.py Updates all LongMemEval scripts to support memos-api mode
evaluation/scripts/locomo/*.py Updates all LoCoMo scripts to support memos-api mode

"""Register a user."""
url = f"{self.base_url}/users/register"
payload = json.dumps({"user_id": user_id})
response = requests.request("POST", url, data=payload, headers=self.headers)
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Use requests.post() instead of requests.request("POST", ...) for better readability and consistency with HTTP method naming conventions.

Suggested change
response = requests.request("POST", url, data=payload, headers=self.headers)
response = requests.post(url, data=payload, headers=self.headers)

Copilot uses AI. Check for mistakes.
url = f"{self.base_url}/add"
payload = json.dumps({"messages": messages, "user_id": user_id, "mem_cube_id": cube_id})

response = requests.request("POST", url, data=payload, headers=self.headers)
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Use requests.post() instead of requests.request("POST", ...) for better readability and consistency with HTTP method naming conventions.

Suggested change
response = requests.request("POST", url, data=payload, headers=self.headers)
response = requests.post(url, data=payload, headers=self.headers)

Copilot uses AI. Check for mistakes.
}
)

response = requests.request("POST", url, data=payload, headers=self.headers)
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Use requests.post() instead of requests.request("POST", ...) for better readability and consistency with HTTP method naming conventions.

Suggested change
response = requests.request("POST", url, data=payload, headers=self.headers)
response = requests.post(url, data=payload, headers=self.headers)

Copilot uses AI. Check for mistakes.
response = requests.request("POST", url, data=payload, headers=self.headers)
return response.text

def search(self, query: str, user_id: str | None = None, top_k: int = 10):
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The top_k parameter is not included in the API request payload, but it's used to slice the results locally. This may cause inconsistent behavior if the API returns fewer than top_k results or if server-side filtering would be more efficient.

Copilot uses AI. Check for mistakes.
Comment on lines +20 to +21
register_res = json.loads(self.user_register(user_id))
cube_id = register_res["data"]["mem_cube_id"]
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No error handling for JSON parsing failures. If user_register returns invalid JSON, this will raise an unhandled exception without a helpful error message.

Suggested change
register_res = json.loads(self.user_register(user_id))
cube_id = register_res["data"]["mem_cube_id"]
try:
register_res = json.loads(self.user_register(user_id))
cube_id = register_res["data"]["mem_cube_id"]
except json.JSONDecodeError as e:
raise ValueError(f"Failed to parse JSON response from user_register: {e}")

Copilot uses AI. Check for mistakes.
Comment on lines +42 to +44
result = json.loads(response.text)["data"]["text_mem"][0]["memories"]
text_memories = [item["memory"] for item in result][:top_k]
return text_memories
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No error handling for JSON parsing or key access failures. This could raise KeyError or json.JSONDecodeError without helpful context about the API response structure.

Suggested change
result = json.loads(response.text)["data"]["text_mem"][0]["memories"]
text_memories = [item["memory"] for item in result][:top_k]
return text_memories
try:
response_json = json.loads(response.text)
data = response_json.get("data", {})
text_mem = data.get("text_mem", [])
if not text_mem or not isinstance(text_mem, list) or "memories" not in text_mem[0]:
raise KeyError("Expected 'text_mem' to be a non-empty list with 'memories' key.")
result = text_mem[0]["memories"]
text_memories = [item.get("memory", "") for item in result][:top_k]
return text_memories
except json.JSONDecodeError as e:
raise ValueError(f"Failed to parse JSON response: {e}")
except (KeyError, IndexError) as e:
raise ValueError(f"Unexpected response structure: {e}")

Copilot uses AI. Check for mistakes.
type=str,
choices=["zep", "memos", "mem0", "mem0_graph", "langmem", "openai"],
choices=["zep", "memos", "mem0", "mem0_graph", "openai", "memos-api"],
help="Specify the memory framework (zep or memos or mem0 or mem0_graph)",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the help string to include "openai" and the newly added "memos-api" for consistency with the choices list.
Ensure corresponding updates are made in other relevant files where this argument is defined or documented to maintain coherence across the codebase.

speaker_2_memories=speaker_b_context,
)

print(query, context)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the print statements in multiple search functions necessary? Also, note that the zep_search function does not have a corresponding print statement.

@tangg555 tangg555 requested review from bestwyj and hush-cd July 24, 2025 03:23
@CaralHsi CaralHsi merged commit 3d90823 into MemTensor:dev Jul 24, 2025
20 checks passed
tangg555 pushed a commit to tangg555/MemOS that referenced this pull request Jul 29, 2025
* feat(eval): add eval dependencies

* feat(eval): add configs example

* docs(eval): update README.md

* feat(eval): remove the dependency (pydantic)

* feat(eval): add run locomo eval script

* fix(eval): delete about memos redundant search branches

* chore: fix format

* feat(eval): add openai memory on locomo - eval guide

* docs(eval): modify openai memory on locomo - eval guide

* feat(eval): add longmemeval evaluation pipeline

* chore(eval): formatter

* chore: update

* feat(eval): add configs example

* fix(eval): bugs about longmemeval

* fix(eval): search top k

* chore(eval): update

* feat(eval): support memos api mode

* feat(eval): add memobase; fix bugs about share db
tianxing02 pushed a commit to tianxing02/MemOS that referenced this pull request Feb 24, 2026
* feat(eval): add eval dependencies

* feat(eval): add configs example

* docs(eval): update README.md

* feat(eval): remove the dependency (pydantic)

* feat(eval): add run locomo eval script

* fix(eval): delete about memos redundant search branches

* chore: fix format

* feat(eval): add openai memory on locomo - eval guide

* docs(eval): modify openai memory on locomo - eval guide

* feat(eval): add longmemeval evaluation pipeline

* chore(eval): formatter

* chore: update

* feat(eval): add configs example

* fix(eval): bugs about longmemeval

* fix(eval): search top k

* chore(eval): update

* feat(eval): support memos api mode

* feat(eval): add memobase; fix bugs about share db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants