EvoViM-Memory-Traces / examples /read_retrieval.py
Xinyu614's picture
Publish EvoViM-Memory-Traces data and documentation
58d9a58 verified
Raw History Blame Contribute Delete
2.05 kB
"""Show an observed search for a DMV-Hard question and the evidence the agent actually saw."""
import argparse
from pathlib import Path
import pyarrow.parquet as pq
def read(table, filters):
folder = Path(__file__).resolve().parents[1] / "data" / table
return pq.read_table(folder / "dmv-hard.parquet", filters=filters or None).to_pylist()
def show(seed=None, step=None):
questions = read("dmv_questions", [("question_type", "=", "pattern")] if step is None else [])
if seed is not None:
questions = [row for row in questions if row["seed"] == seed]
if step is not None:
questions = [row for row in questions if row["step"] == step]
for question in sorted(questions, key=lambda r: (r["seed"], r["step"])):
filters = [(k, "=", question[k]) for k in ("cell_id", "seed", "step")]
searches = read("dmv_searches", filters)
candidates = read("dmv_candidates", filters)
for search in sorted(searches, key=lambda r: (r["phase"], r["call"])):
shown = sorted(
[r for r in candidates if (r["phase"], r["call"]) == (search["phase"], search["call"])],
key=lambda r: r["rank"],
)
if not shown:
continue
print(f"Seed {question['seed']}, step {question['step']}, {question['question_type']}")
print(f"Search ({search['phase']}, call {search['call']}): {search['query']}")
for item in shown[:3]:
print(f" {item['rank']}. Page {item['product_key']} | {item['retrieval_score']:g} | {item['shown_swatch_text']}")
print(f"Agent answered page {question['executed_product_key']}. Correct: {question['answered_correctly']}.")
return
raise SystemExit("No matching question with an observed ranked response.")
if __name__ == "__main__":
cli = argparse.ArgumentParser(description=__doc__)
cli.add_argument("--seed", type=int)
cli.add_argument("--step", type=int)
args = cli.parse_args()
show(args.seed, args.step)