Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(retrieval): entity graph lever for LongMemEval#295

Closed
jamby77 wants to merge 1 commit into
feature/longmemeval-facts-concurrencyfrom
feature/longmemeval-entity-graph
Closed

feat(retrieval): entity graph lever for LongMemEval#295
jamby77 wants to merge 1 commit into
feature/longmemeval-facts-concurrencyfrom
feature/longmemeval-entity-graph

Conversation

@jamby77

@jamby77 jamby77 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Part of the LongMemEval recall→QA gap epic (Issue 6 — entity/relationship graph). Stacked on #291.

What

Adds the graph lever: a lightweight in-memory entity graph built per record from the curated facts (Phase 4), traversed 1–2 hops at question time to pull connected facts the vector query misses.

  • eval/longmemeval/graph.ts — pure buildEntityGraph (entity → fact adjacency, case-normalized) and traverseGraph (BFS from seed entities; as-of temporal validity mirroring the temporal lever — facts dated after the question are dropped, dateless facts kept; discovery-order dedupe; capped).
  • EntityLinker seam (texts[] → entities[][], one batched call): mock (capitalized words) for offline runs, OpenAI (JSON array-of-arrays, guarded parseEntityLists that degrades to empty lists on malformed replies).
  • consolidateRecordFacts now also returns the curated facts (additive return field).

Wiring

LONGMEMEVAL_GRAPH=1, inert without LONGMEMEVAL_FACTS=1 (the graph is built over curated facts). Reader-side only: question entities seed the traversal and the traversed facts are appended to the reader contexts, skipping any fact whose statement is already present in a context. Recall stays measured on the unmodified rerank top-k, so recall cannot regress by construction (same principle as the reworked assemble/temporal levers).

Knobs: LONGMEMEVAL_GRAPH_HOPS (default 2), LONGMEMEVAL_GRAPH_MAX_FACTS (default 5), LONGMEMEVAL_GRAPH_MODEL. Cost report: 1 batch entity-link LLM call per record + 1 seed-link call per question; nothing is stored on Valkey.

Tests

12 new tests (traverse hop-1/hop-2/as-of/dedupe+limit/unknown-seeds, mock linker, parse guards, curated-facts return, 2 runEval integrations incl. no-duplicate-evidence). Full retrieval suite 184/184.

Offline Tier-0 smoke (LONGMEMEVAL_FACTS=1 LONGMEMEVAL_GRAPH=1 LONGMEMEVAL_QA=1): baseline metrics unchanged, cost lines facts llm=15, graph llm=6 (3 records × 2 calls).

The +5pt multi-session QA target awaits a real Tier-2 run on _m.


Note

Low Risk
Changes are confined to the LongMemEval eval harness and reader-side context assembly; retrieval scoring and production retrieval paths are untouched.

Overview
Adds a graph LongMemEval lever that builds an in-memory entity graph from curated facts and expands reader contexts at question time without changing recall@k.

graph.ts introduces buildEntityGraph, BFS traverseGraph (hop depth, asOf temporal filter, dedupe, limit), and an EntityLinker seam (mock capitalized-word linker + OpenAI batch linker with safe parseEntityLists).

consolidateRecordFacts now also returns facts: Fact[] so the graph can be built over reconciled facts.

runner / run: when graph is on (requires facts), each record gets one batched entity-link call over fact statements; per question, question entities seed traversal and up to LONGMEMEVAL_GRAPH_MAX_FACTS (default 5) connected facts are appended to contexts, skipping statements already present. Env: LONGMEMEVAL_GRAPH, LONGMEMEVAL_GRAPH_HOPS, LONGMEMEVAL_GRAPH_MODEL. Graph costs are tracked in the cost report.

12 new tests cover traversal, parsing, curated-facts return, and runEval integration (including no duplicate evidence).

Reviewed by Cursor Bugbot for commit 6f3135a. Bugbot is set up for automated code reviews on this repo. Configure here.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 14c9780. Configure here.

Comment thread packages/retrieval/eval/longmemeval/runner.ts
@jamby77 jamby77 force-pushed the feature/longmemeval-entity-graph branch from 14c9780 to c5d90ea Compare July 3, 2026 06:37
@jamby77 jamby77 force-pushed the feature/longmemeval-facts-concurrency branch from 457eae2 to 20ea924 Compare July 3, 2026 06:37
- Add eval/longmemeval/graph.ts: buildEntityGraph + traverseGraph (BFS over
  entity co-occurrence, as-of temporal validity, deduped, capped)
- EntityLinker seam with mock (capitalized words) and OpenAI (batch JSON,
  guarded parseEntityLists) implementations
- consolidateRecordFacts also returns the curated facts (additive)
- Wire LONGMEMEVAL_GRAPH reader-side only (requires LONGMEMEVAL_FACTS):
  question entities seed a 1-2 hop traversal whose facts are appended to
  reader contexts, deduped against evidence already present; recall stays
  measured on the unmodified rerank top-k
- Knobs: LONGMEMEVAL_GRAPH_HOPS (2), LONGMEMEVAL_GRAPH_MAX_FACTS (5),
  LONGMEMEVAL_GRAPH_MODEL; cost report gets 1 link call per record plus 1
  seed call per question
@jamby77 jamby77 force-pushed the feature/longmemeval-facts-concurrency branch from 20ea924 to fca29ff Compare July 3, 2026 07:10
@jamby77 jamby77 force-pushed the feature/longmemeval-entity-graph branch from c5d90ea to 6f3135a Compare July 3, 2026 07:10
@KIvanow

KIvanow commented Jul 7, 2026

Copy link
Copy Markdown
Member

Closing it for now, as we prioritise other things and this doesn't move the needle sufficiently

@KIvanow KIvanow closed this Jul 7, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 7, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants