You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(layers): fetch the most recent drawers for L1 wake-up
PR #1630 fixed the L1 wake-up ordering by adding filed_at as a secondary
sort key, and documented what it could not fix:
"The fetch still scans up to MAX_SCAN=2000 drawers in collection
(insertion) order, so on a very large unscoped wing the most-recent
drawers may fall outside the cap before sorting... A SQL-side
most-recent-N by filed_at fetch would fix the unscoped case but is a
larger change left for a follow-up."
This is that follow-up. On a 149k-drawer palace the sort was correct and
the input was not: the 2000 drawers Layer1 scored were the oldest
backfill slice, so wake-up permanently opened on the first files ever
mined and never on this week's sessions.
Backend capability rather than a pgvector special case:
- BaseCollection.get_recent(limit, where, order_field, include) returns
up to limit records newest-first on an ISO-8601 metadata field.
The ABC default pages through get() and sorts the window locally,
which is exactly what Layer1 did inline, so every backend that does
not override it behaves as before.
- PgVectorCollection overrides it with ORDER BY metadata->>%s DESC
NULLS LAST, id pushed into the scan, and PgVectorBackend advertises
the supports_recency_order capability token. That is exact at any
table size. Filters that pgvector cannot push down exactly keep the
existing local post-filter path.
- EmbeddingCollection forwards get_recent explicitly. Without the
forwarder, MRO would resolve the concrete ABC default on the wrapper
and shadow the inner backend's pushdown (the invariant
test_wrapper_forwards_all_concrete_basecollection_methods guards).
- Layer1._fetch_candidates uses the capability and falls back to the
previous paged scan when a collection predates get_recent or the
backend errors, so wake-up degrades instead of failing.
recency_sort_key is shared so every local sort orders identically:
records missing the field, holding an empty string, or holding a
non-string sort last instead of raising on a str/None comparison.
No ordering semantics change for Layer1 itself. importance stays the
primary key and filed_at the tiebreak; only the candidate window
changes, from "the first 2000 rows the backend hands back" to "the 2000
most recently filed".
Measured on the 149k-drawer palace this was written for: wake-up now
leads with the newest sessions and renders in 0.72s.
Tests: base default (ordering, missing/odd timestamps, window cap,
where passthrough, dict-shaped get), pgvector pushdown (SQL text and
bind order, filter pushdown, local-filter fallback, include, zero
limit, custom order field), and Layer1 (capability used, wing filter
forwarded, fallback when the capability is missing or raises).
Copy file name to clipboardExpand all lines: CHANGELOG.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
8
8
9
9
## [Unreleased]
10
10
11
+
### Bug Fixes
12
+
13
+
-**Layer 1 wake-up fetches the most recent drawers instead of an arbitrary scan window.**`BaseCollection.get_recent()` returns the newest N by `filed_at`; pgvector overrides it with an `ORDER BY ... DESC LIMIT n` pushdown (capability token `supports_recency_order`), and backends without pushdown keep the previous scan-and-sort behavior. On palaces larger than the 2,000-drawer scan cap, wake-up no longer leads with the oldest backfill. (#1630)
0 commit comments