Retrieval Evaluation
memorylayer-eval measures how well MemoryLayer retrieves. It boots the real service stack in-process, ingests a corpus, runs every query through the real recall() pipeline, and scores the results against ground truth. Any change to ranking shows up in the numbers, whether it is fusion, boosts, channels, or rerankers. The same command runs in MemoryLayer’s CI as a required retrieval-regression gate.
It installs with the server:
pip install memorylayer-servermemorylayer-eval run # score only; always exits 0memorylayer-eval gate # score, then fail (exit 1) if any threshold is missedYou can also run it as python -m memorylayer_server.eval.
With no arguments, it uses a small fixture corpus bundled in the wheel (15 documents plus a qrels file) and the deterministic hash embedding provider. That makes it fast and fully offline.
Metrics
| Metric | Meaning |
|---|---|
| recall@k | Share of each query’s relevant memories found in the top k (mean over queries) |
| precision@k | Share of the top k that are relevant |
| MRR | Mean reciprocal rank of the first relevant result |
| nDCG@k | Rank-discounted gain (uses graded relevance when the qrels provide grades) |
| first-relevant hit rate | Share of queries with at least one relevant memory in the top k |
| expected-top1 hit rate | Share of queries whose expected_top1 memory ranked first |
| latency | Mean recall latency in milliseconds |
The Gate
gate passes only if every metric meets its floor:
| Threshold | Default | Override |
|---|---|---|
| mean recall@k | 0.80 | --min-recall |
| first-relevant hit rate | 0.80 | --min-first-relevant |
| expected-top1 hit rate | 0.60 | --min-expected-top1 |
| k | 5 | --k |
The defaults are tuned for the bundled fixture. Set your own floors when you gate on a different corpus. Add --json for machine-readable output in CI.
Options
| Flag | Default | Description |
|---|---|---|
--corpus / --qrels | bundled fixture | Your own corpus and ground truth |
--k | 5 | Cutoff for the @k metrics |
--embedding-provider | hash | Any server embedding provider, such as embed_server or openai |
--dimensions | provider default | Embedding dimensions |
--embed-server-url | http://localhost:61051 for embed_server | Embed server peer |
--hybrid / --no-hybrid | server default | Force keyword + vector fusion on or off |
--reranker | none | none, rrf, llm, or hyde |
--storage-backend | sqlite | sqlite, postgresql, or in_memory |
--postgres-url | — | Connection URL when the backend is postgresql |
--data-dir | fresh temp dir | Where the run stores its data |
--clean-ingest | off | Batch-embed and insert directly, skipping write-path enrichment |
--json | off | JSON output |
For example, to compare two embedding setups on the same data:
memorylayer-eval run --corpus my_corpus.jsonl --qrels my_qrels.json --k 10 \ --embedding-provider embed_server --dimensions 384 --json > embed.jsonmemorylayer-eval run --corpus my_corpus.jsonl --qrels my_qrels.json --k 10 --json > hash.jsonData Format
Corpus is JSONL. Each row is one memory, identified by a key:
{"key": "fastapi-web", "content": "FastAPI is a Python framework for building APIs.", "tags": ["python", "web"]}Qrels is JSON. Each query lists the corpus keys that are relevant, and optionally the one that should rank first, plus graded relevance:
{ "schema_version": 1, "queries": [ {"query_id": "q1", "query": "python web framework for building APIs", "relevant": ["fastapi-web", "python-backend"], "expected_top1": "fastapi-web"} ]}Public Benchmarks
The memorylayer-core-python/benchmarks/ directory in the source repository has converters that turn public datasets into this format. They are standalone scripts, not part of the installed CLI. Each reads raw data from benchmarks/.cache/raw/ and writes corpus.jsonl and qrels.json under benchmarks/.cache/<name>/. For HotpotQA and LoCoMo, download the raw file yourself; each script’s docstring gives the URL.
| Script | Dataset | Notes |
|---|---|---|
hotpotqa_convert.py | HotpotQA | Multi-hop QA (--questions, default 200; needs pyarrow) |
locomo_convert.py | LoCoMo | Long-term conversational memory. Evidence turns are the relevant set. Adversarial questions are excluded unless you pass --include-adversarial. |
longmemeval_convert.py | LongMemEval | Long-horizon chat memory (--questions 75, --max-sessions 60) |
gammacorpus_convert.py | GammaCorpus | Pulled from the Hugging Face datasets server (--rows 2000, --queries 400) |
build_subset.py | any converted corpus | Draws a reproducible subset (--size 500, --seed 13) |
download_sources.py | GammaCorpus, LongMemEval | Fetches raw source files into benchmarks/.cache/raw/ |
python benchmarks/locomo_convert.py --questions 200memorylayer-eval run \ --corpus benchmarks/.cache/locomo/corpus.jsonl \ --qrels benchmarks/.cache/locomo/qrels.json \ --k 5 --embedding-provider embed_server --dimensions 384Use these runs to validate a change before you flip one of the retrieval channel flags in production. Several channels are off by default until they pass exactly this kind of gate.