feat(eval): add openai memory on locomo - eval guide - #54
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for evaluating OpenAI’s Memory feature on the LoCoMo dataset by providing automation scripts, a detailed guide, and an evaluation tool.
- Introduces
run_openai_eval.shto orchestrate the LoCoMo OpenAI memory evaluation pipeline - Adds a step-by-step Markdown guide for manual memory extraction and consolidation
- Implements
locomo_openai.pyto automate question answering against stored memories - Updates the main
README.mdto reference the new guide
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| evaluation/scripts/run_openai_eval.sh | Shell script to run the OpenAI-based evaluation steps |
| evaluation/scripts/locomo/openai_memory_locomo_eval_guide.md | Manual guide for extracting and consolidating ChatGPT memories |
| evaluation/scripts/locomo/locomo_openai.py | Python script to query stored memories and evaluate responses |
| evaluation/README.md | README update linking to the OpenAI memory evaluation guide |
Comments suppressed due to low confidence (1)
evaluation/README.md:36
- [nitpick] It would be helpful to include the exact command for running the new evaluation script (e.g.,
./evaluation/scripts/run_openai_eval.sh --version <version>), so users don’t have to look it up.
✍️ For evaluating OpenAI's native memory feature with the LoCoMo dataset, please refer to the detailed guide: [OpenAI Memory on LoCoMo - Evaluation Guide](./scripts/locomo/openai_memory_locomo_eval_guide.md).
| echo "Running locomo_openai.py..." | ||
| python scripts/locomo/locomo_openai.py --version $VERSION | ||
| if [ $? -ne 0 ]; then | ||
| echo "Error running locomo_openai.py." | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Running locomo_eval.py..." | ||
| python scripts/locomo/locomo_eval.py --lib $LIB --version $VERSION --num_runs $NUM_RUNS | ||
| if [ $? -ne 0 ]; then | ||
| echo "Error running locomo_eval.py" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "Running locomo_metric.py..." | ||
| python scripts/locomo/locomo_metric.py --lib $LIB --version $VERSION |
There was a problem hiding this comment.
The relative path scripts/locomo/locomo_openai.py will be resolved from the current working directory, which may not be the script’s location. Consider using the script’s directory for paths (e.g., DIR=$(dirname "$0") and then python "$DIR"/locomo/locomo_openai.py --version "$VERSION").
| echo "Running locomo_openai.py..." | |
| python scripts/locomo/locomo_openai.py --version $VERSION | |
| if [ $? -ne 0 ]; then | |
| echo "Error running locomo_openai.py." | |
| exit 1 | |
| fi | |
| echo "Running locomo_eval.py..." | |
| python scripts/locomo/locomo_eval.py --lib $LIB --version $VERSION --num_runs $NUM_RUNS | |
| if [ $? -ne 0 ]; then | |
| echo "Error running locomo_eval.py" | |
| exit 1 | |
| fi | |
| echo "Running locomo_metric.py..." | |
| python scripts/locomo/locomo_metric.py --lib $LIB --version $VERSION | |
| DIR=$(dirname "$0") | |
| echo "Running locomo_openai.py..." | |
| python "$DIR"/scripts/locomo/locomo_openai.py --version $VERSION | |
| if [ $? -ne 0 ]; then | |
| echo "Error running locomo_openai.py." | |
| exit 1 | |
| fi | |
| echo "Running locomo_eval.py..." | |
| python "$DIR"/scripts/locomo/locomo_eval.py --lib $LIB --version $VERSION --num_runs $NUM_RUNS | |
| if [ $? -ne 0 ]; then | |
| echo "Error running locomo_eval.py" | |
| exit 1 | |
| fi | |
| echo "Running locomo_metric.py..." | |
| python "$DIR"/scripts/locomo/locomo_metric.py --lib $LIB --version $VERSION |
| class OpenAIPredict: | ||
| def __init__(self, model="gpt-4o-mini"): | ||
| self.model = model | ||
| self.openai_client = OpenAI( | ||
| api_key=os.getenv("OPENAI_API_KEY"), base_url=os.getenv("OPENAI_BASE_URL") | ||
| ) | ||
| self.results = defaultdict(list) | ||
|
|
||
| def search_memory(self, idx): | ||
| with open(f"openai_memory/{idx}.txt", encoding="utf-8") as file: | ||
| memories = file.read().strip().replace("\n\n", "\n") | ||
|
|
||
| return memories, 0 | ||
|
|
There was a problem hiding this comment.
The code assumes an openai_memory/ directory exists and hardcodes that path, but the guide uses openai_inputs/ and doesn’t mention creating openai_memory/. Either parameterize this directory or document/setup the folder before reading.
| class OpenAIPredict: | |
| def __init__(self, model="gpt-4o-mini"): | |
| self.model = model | |
| self.openai_client = OpenAI( | |
| api_key=os.getenv("OPENAI_API_KEY"), base_url=os.getenv("OPENAI_BASE_URL") | |
| ) | |
| self.results = defaultdict(list) | |
| def search_memory(self, idx): | |
| with open(f"openai_memory/{idx}.txt", encoding="utf-8") as file: | |
| memories = file.read().strip().replace("\n\n", "\n") | |
| return memories, 0 | |
| class OpenAIPredict: | |
| def __init__(self, model="gpt-4o-mini", memory_dir="openai_memory"): | |
| self.model = model | |
| self.memory_dir = memory_dir | |
| os.makedirs(self.memory_dir, exist_ok=True) | |
| self.openai_client = OpenAI( | |
| api_key=os.getenv("OPENAI_API_KEY"), base_url=os.getenv("OPENAI_BASE_URL") | |
| ) | |
| self.results = defaultdict(list) | |
| def search_memory(self, idx): | |
| memory_file_path = os.path.join(self.memory_dir, f"{idx}.txt") | |
| with open(memory_file_path, encoding="utf-8") as file: | |
| memories = file.read().strip().replace("\n\n", "\n") | |
| return memories, 0 | |
| def search_memory(self, idx): | ||
| with open(f"openai_memory/{idx}.txt", encoding="utf-8") as file: | ||
| memories = file.read().strip().replace("\n\n", "\n") | ||
|
|
||
| return memories, 0 | ||
|
|
There was a problem hiding this comment.
Currently search_memory always returns 0 for the search time. For accurate metrics, consider measuring and returning the actual file‐read duration using time.time().
| def search_memory(self, idx): | |
| with open(f"openai_memory/{idx}.txt", encoding="utf-8") as file: | |
| memories = file.read().strip().replace("\n\n", "\n") | |
| return memories, 0 | |
| def search_memory(self, idx): | |
| t1 = time.time() | |
| with open(f"openai_memory/{idx}.txt", encoding="utf-8") as file: | |
| memories = file.read().strip().replace("\n\n", "\n") | |
| t2 = time.time() | |
| search_time = (t2 - t1) * 1000 # Convert to milliseconds | |
| return memories, search_time | |
hush-cd
left a comment
There was a problem hiding this comment.
The file evaluation/scripts/locomo/openai_memory_locomo_eval_guide.md requires partial revisions.
| 4. **Save Memories:** | ||
| * Click on **Manage** in the memory confirmation to view the newly generated memories. | ||
| * Create a new local `.txt` file with the same name as the input file (e.g., `0-D1.txt`). | ||
| * Copy each memory entry from ChatGPT and paste it into the new file, with each memory on a new line. |
There was a problem hiding this comment.
It is important to emphasize that once all sessions under a single conversation have been processed and their memories saved, all memories in ChatGPT must be deleted(Settings -> Personalization -> Manage memories -> Delete all) before starting memory extraction for the next conversation. This prevents interference between memories from different conversations.
| ## 3. Considerations | ||
|
|
||
| - **Account Differences:** Be aware of potential differences between free and Plus accounts, such as context length limitations and the number of memories that can be stored. | ||
| - **Granularity:** The current process adds memories at a **session** level. This is due to the context window limitations of the web UI. Evaluating at a full **conversation** level at once might be preferable if the context window allows. |
There was a problem hiding this comment.
Memory extraction should be performed at the session level only. It is not recommended to input the entire conversation at once, as this often results in very few memories being extracted, leading to significant information loss.
* 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
Description
Summary: add openai memory on locomo - eval guide
Fix: #(issue)
Reviewer: @hush-cd
Checklist: