-
Notifications
You must be signed in to change notification settings - Fork 552
feat(eval): support memos api mode #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 32 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
4ef7418
feat(eval): add eval dependencies
Duguce ddad8c1
feat(eval): add configs example
Duguce d623791
docs(eval): update README.md
Duguce 3365de4
Merge branch 'MemTensor:dev' into dev
Duguce ed68e36
feat(eval): remove the dependency (pydantic)
Duguce 4e99031
Merge branch 'MemTensor:dev' into dev
Duguce 41368b9
feat(eval): add run locomo eval script
Duguce 9477539
Merge branch 'MemTensor:dev' into dev
Duguce 8cd9361
fix(eval): delete about memos redundant search branches
Duguce a900910
chore: fix format
Duguce 204bd27
Merge branch 'MemTensor:dev' into dev
Duguce 5d68ed9
Merge branch 'MemTensor:dev' into dev
Duguce 42e9366
feat(eval): add openai memory on locomo - eval guide
Duguce f3d1d5d
Merge branch 'dev' into dev
Duguce 9bada64
Merge branch 'MemTensor:dev' into dev
Duguce 7881029
docs(eval): modify openai memory on locomo - eval guide
Duguce dd2b2c5
Merge branch 'MemTensor:dev' into dev
Duguce 7a60c33
Merge branch 'MemTensor:dev' into dev
Duguce ed86648
Merge branch 'MemTensor:dev' into dev
Duguce aaab1ce
Merge branch 'MemTensor:dev' into dev
Duguce 710d4db
Merge branch 'MemTensor:dev' into dev
Duguce c98ded4
feat(eval): add longmemeval evaluation pipeline
Duguce 79a5bce
chore(eval): formatter
Duguce 37e2933
chore: update
Duguce 445c855
feat(eval): add configs example
Duguce 82e60b5
Merge branch 'MemTensor:dev' into dev
Duguce 09b5a72
fix(eval): bugs about longmemeval
Duguce efd2c0d
Merge branch 'MemTensor:dev' into dev
Duguce fc0005a
fix(eval): search top k
Duguce bf11ea7
chore(eval): update
Duguce 715b399
Merge branch 'MemTensor:dev' into dev
Duguce 0d0d037
feat(eval): support memos api mode
Duguce 54521c6
Merge branch 'MemTensor:dev' into dev
Duguce 1259729
Merge branch 'MemTensor:dev' into dev
Duguce 638973a
Merge branch 'MemTensor:dev' into dev
Duguce 284f8cc
Merge branch 'MemTensor:dev' into dev
Duguce 29c88aa
Merge branch 'dev' into dev
Duguce b391c90
feat(eval): add memobase; fix bugs about share db
Duguce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,23 @@ | ||
| import os | ||
| import sys | ||
|
|
||
|
|
||
| sys.path.insert( | ||
| 0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))) | ||
| ) | ||
| sys.path.insert( | ||
| 0, | ||
| os.path.join( | ||
| os.path.dirname( | ||
| os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
| ), | ||
| "evaluation", | ||
| "scripts", | ||
| ), | ||
| ) | ||
|
|
||
| import argparse | ||
| import json | ||
| import os | ||
|
|
||
| from collections import defaultdict | ||
| from concurrent.futures import ThreadPoolExecutor, as_completed | ||
|
|
@@ -11,7 +28,8 @@ | |
| from dotenv import load_dotenv | ||
| from mem0 import MemoryClient | ||
| from tqdm import tqdm | ||
| from utils import filter_memory_data | ||
| from utils.client import memos_client | ||
| from utils.memos_filters import filter_memory_data | ||
| from zep_cloud.client import Zep | ||
|
|
||
| from memos.configs.mem_os import MOSConfig | ||
|
|
@@ -191,6 +209,38 @@ def memos_search(client, query, conv_id, speaker_a, speaker_b, reversed_client=N | |
| return context, duration_ms | ||
|
|
||
|
|
||
| def memos_api_search( | ||
| client, query, conv_id, speaker_a, speaker_b, top_k, version, reversed_client=None | ||
| ): | ||
| start = time() | ||
| speaker_a_user_id = conv_id + "_speaker_a" | ||
| search_a_results = client.search( | ||
| query=query, user_id=f"{speaker_a_user_id.replace('_', '')}{version}", top_k=top_k | ||
| ) | ||
| speaker_a_context = "" | ||
| for item in search_a_results: | ||
| speaker_a_context += f"{item}\n" | ||
|
|
||
| speaker_b_user_id = conv_id + "_speaker_b" | ||
| search_b_results = reversed_client.search( | ||
| query=query, user_id=f"{speaker_b_user_id.replace('_', '')}{version}", top_k=top_k | ||
| ) | ||
| speaker_b_context = "" | ||
| for item in search_b_results: | ||
| speaker_b_context += f"{item}\n" | ||
|
|
||
| context = TEMPLATE_MEMOS.format( | ||
| speaker_1=speaker_a, | ||
| speaker_1_memories=speaker_a_context, | ||
| speaker_2=speaker_b, | ||
| speaker_2_memories=speaker_b_context, | ||
| ) | ||
|
|
||
| print(query, context) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are the |
||
| duration_ms = (time() - start) * 1000 | ||
| return context, duration_ms | ||
|
|
||
|
|
||
| def mem0_graph_search(client, query, speaker_a_user_id, speaker_b_user_id, top_k=20): | ||
| start = time() | ||
| search_speaker_a_results = client.search( | ||
|
|
@@ -297,7 +347,7 @@ def zep_search(client, query, group_id, top_k=20): | |
| return context, duration_ms | ||
|
|
||
|
|
||
| def search_query(client, query, metadata, frame, reversed_client=None, top_k=20): | ||
| def search_query(client, query, metadata, frame, version, reversed_client=None, top_k=20): | ||
| conv_id = metadata.get("conv_id") | ||
| speaker_a = metadata.get("speaker_a") | ||
| speaker_b = metadata.get("speaker_b") | ||
|
|
@@ -316,7 +366,11 @@ def search_query(client, query, metadata, frame, reversed_client=None, top_k=20) | |
| ) | ||
| elif frame == "memos": | ||
| context, duration_ms = memos_search( | ||
| client, query, conv_id, speaker_a, speaker_b, reversed_client | ||
| client, query, conv_id, speaker_a, speaker_b, version, reversed_client | ||
| ) | ||
| elif frame == "memos-api": | ||
| context, duration_ms = memos_api_search( | ||
| client, query, conv_id, speaker_a, speaker_b, top_k, version, reversed_client | ||
| ) | ||
| return context, duration_ms | ||
|
|
||
|
|
@@ -364,6 +418,11 @@ def process_user(group_idx, locomo_df, frame, version, top_k=20, num_workers=1): | |
| speaker_b_user_id = conv_id + "_speaker_b" | ||
| client = get_client(frame, speaker_a_user_id, version, top_k=top_k) | ||
| reversed_client = get_client(frame, speaker_b_user_id, version, top_k=top_k) | ||
| elif frame == "memos-api": | ||
| speaker_a_user_id = conv_id + "_speaker_a" | ||
| speaker_b_user_id = conv_id + "_speaker_b" | ||
| client = memos_client(mode="api") | ||
| reversed_client = memos_client(mode="api") | ||
| else: | ||
| client = get_client(frame, conv_id, version) | ||
|
|
||
|
|
@@ -372,7 +431,7 @@ def process_qa(qa): | |
| if qa.get("category") == 5: | ||
| return None | ||
| context, duration_ms = search_query( | ||
| client, query, metadata, frame, reversed_client=reversed_client, top_k=top_k | ||
| client, query, metadata, frame, version, reversed_client=reversed_client, top_k=top_k | ||
| ) | ||
|
|
||
| if not context: | ||
|
|
@@ -439,7 +498,7 @@ def main(frame, version="default", num_workers=1, top_k=20): | |
| parser.add_argument( | ||
| "--lib", | ||
| type=str, | ||
| choices=["zep", "memos", "mem0", "mem0_graph", "langmem"], | ||
| choices=["zep", "memos", "mem0", "mem0_graph", "memos-api"], | ||
| help="Specify the memory framework (zep or memos or mem0 or mem0_graph)", | ||
| ) | ||
| parser.add_argument( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the
helpstring to include "openai" and the newly added "memos-api" for consistency with thechoiceslist.Ensure corresponding updates are made in other relevant files where this argument is defined or documented to maintain coherence across the codebase.