Skip to content

Graph history looks up successor facts within the knowledge base - #1501

Merged
WaylandYang merged 2 commits into
deeplethe:devfrom
Maya-Kid:codex/scope-graph-successors-by-knowledge-base
Nov 16, 2026
Merged

WaylandYang merged 2 commits into
deeplethe:devfrom
Maya-Kid:codex/scope-graph-successors-by-knowledge-base

Conversation

@Maya-Kid

Copy link
Copy Markdown
Contributor

Why

Graph changes and entity history look for successors to distinguish a correction from a rejection. The outer queries already select a single knowledge base, but the successor lookups omit that condition. PostgreSQL cannot narrow the scan by the leading column of the existing (kb_id, supersedes) index.

What changes

Add s.kb_id = $1 to both successor lookups. The existing composite foreign key ensures a successor belongs to the same knowledge base as its predecessor. The entity history page and count share the same lookup.

How it was checked

On Linux with PostgreSQL 16.15 and the repository migrations applied, run the complete statements extracted from f33f9fc9 and d4899715 against the same synthetic data set of 100 knowledge bases, 500,000 facts, and 100,000 successor links. Medians are from six warm pairs of EXPLAIN (ANALYZE, BUFFERS) runs, alternating the order of the queries.

Full SQL statement Before After
Graph changes, 25 rows 21.253 ms 11.832 ms
Entity history, 25 rows 27.389 ms 1.598 ms
Entity history count 24.945 ms 0.289 ms

Graph changes scanned 100,000 successor index entries before the change and 1,000 after. The history page and count both began constraining index lookups by kb_id and supersedes. Results matched byte for byte in order for first and later pages, a filtered query with corrections and rejections, and empty cases. Entity history returned the same totals for the populated entity (216) and a missing entity (0).

  • cargo fmt --all --check passed.
  • cargo clippy --workspace --all-targets -- -D warnings passed on Linux.
  • On Linux with PostgreSQL required, the focused ledger, history and recording-axis tests passed. The full workspace suite passed with 1,847 passed and 6 ignored.

Before review

  • The commit is signed off (git commit -s).
  • Workspace formatting, Clippy and tests pass.
  • Store SQL was tested with UTOPIA_DATABASE_URL set and UTOPIA_TEST_REQUIRE_DB=1.

Signed-off-by: Maya Kid <BinjunYann@gmail.com>

@WaylandYang WaylandYang left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, LGTM. Optional follow-up: add_evidence_located (graph.rs, the supersedes = $1 walk) and the recursive successor chains in resolution.rs also look up supersedes without kb_id. Merging.

@WaylandYang
WaylandYang merged commit 675aaf5 into deeplethe:dev Nov 16, 2026
6 checks passed
@Maya-Kid
Maya-Kid deleted the codex/scope-graph-successors-by-knowledge-base branch November 29, 2026 05:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants