improvement(knowledge): serve date tag filters from an index

Merged
WA
1mo ago
+29702-68

Summary

  • Date tag filters compiled to col::date <op> d::date, which no btree on the timestamp column can serve. Every date filter walked past its slot index, so #8332 dropped those never-used indexes. This makes date filtering index-backed instead
  • Date filters now compile to half-open ranges on the raw timestamp column, e.g. eq d → col >= d AND col < d + 1 day. Each range selects exactly the rows the calendar-day comparison did: the slots have no time zone, and a NULL tag still matches nothing
  • One builder, buildDateTagCondition, is shared by search tag filters and the document list filter. Each keeps its existing fallback for unknown operators
  • New migration re-creates {emb,doc}_date1_idx / date2_idx concurrently

Type of Change

  • Improvement

Testing

  • Real-Postgres equivalence test: every operator, every day boundary (23:59:59.999999, midnight), NULL, and equal-endpoint and multi-day between, under three session time zones, compared against the old ::date predicate evaluated on the same rows. Five boundary mutations of the builder each turn it red
  • Isolated EXPLAIN test: selective eq, between, gte, and lt date filters use the date index from both builders. It fails on the pre-change builders
  • Knowledge search A/B on a synthetic 732k-chunk fixture, with identical results in every shape:
    • a single-day filter no longer seq-scans embedding in the vector leg's short-result rescue probe (55–61 ms → under 1 ms)
    • vector and hybrid date searches run 19–25% faster end to end
    • hybrid keyword ranking with a date filter drops from ~30 → ~10 ms
    • tags-only single-day filters add ~1 ms
  • kb-block-search, filtered-search, workspace-kb-document-access, search-index-policy, type-check, lint, check:audits, and check:migrations origin/staging pass
  • Migration number is renumbered at merge time, since other open PRs also add migrations

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)