symfonic.memory.backends.postgres_candidate_budget¶
postgres_candidate_budget ¶
Physical row budget for native PostgreSQL candidate selection (CORE-199).
Ranking scores every eligible row (token hits, ancestor decay, the profile
slot) before LIMIT, so a cue-bearing read must see the whole eligible set. The
native read therefore materializes at most CANDIDATE_SCAN_BUDGET + 1 rows
and refuses when the set is larger. It never truncates recall and never
reports a partial page as complete; under budget it ranks exactly the rows the
unbounded statement ranked.
With idx_nodes_candidate_eligible_c installed the budget counts eligible
rows only (postgres_candidate_index). Without it, it counts every visible
row in the owner paths, whatever its layer or eligibility, because only the
C range index condition bounds what that scan reads. Dead index entries and
TTL-expired rows are still visited without counting; the native read deadline
bounds that residual.
Empty cue: every row of one (path, layer, audience, profile) seek shares its
ancestor decay and cue factor, so the score orders exactly as the index rank
key, provided the decay power(0.5, d), a numeric that the float8 rank
product casts implicitly, is the exact power of two 2**-d. Then the global
top limit (plus the profile slot) is drawn from each seek's first
limit rows, and one more row per seek decides completeness: a page never
holds more than limit rows of one seek, profile slots included. Rows too
wide for the eligible key have no rank order, so their seeks read every such
row; the page draws from a superset and stays exact. Every fetched row counts
against the budget, so an empty-cue read stays exact only while (limit + 1)
times the populated seeks, plus the wide rows, fits it; past that it refuses
rather than truncates. PostgreSQL 16's numeric power stops being exact at
d = 23, so deeper scopes keep the counting budget.
bounded_source ¶
CTEs reading at most budget + 1 visible rows, and the refusal flag.
paths_sql replaces the owner array (CORE-199 erasing owners removed).
Source code in src/symfonic/memory/backends/postgres_candidate_budget.py
eligible_source ¶
CTEs keeping at most budget + 1 eligible seek rows, and the refusal flag.
ordered_index_scan
async
¶
Pin the bounded read to an ordered index scan; restore on every exit.
Source code in src/symfonic/memory/backends/postgres_candidate_budget.py
ranked_rows ¶
Refuse an over-budget row set; drop the flag-only row of an empty page.
Source code in src/symfonic/memory/backends/postgres_candidate_budget.py
seek_cap ¶
Rows per seek: the budget itself unless the empty-cue top-k is exact.
Source code in src/symfonic/memory/backends/postgres_candidate_budget.py
visible_paths ¶
Owner paths the ranked statement may read: ancestors, admitted, exact.
Equality under COLLATE "C" is byte equality, so the intersection is the same set the SQL predicates select; one array keeps it an index condition.