Skip to content

Session Query

pawaca edited this page Aug 30, 2026 · 3 revisions

Session Query

Edge adaptation of the upstream session search and query system.

Upstream reference: Session Query documentation

What Upstream Provides

The Session Query provides full-text search across the session corpus. It consists of two packages:

  • dsh-session-query — service definition: query vocabulary, search document extraction (buildSessionEventSearchDocuments), session/event filtering, and relationship tracking.
  • dsh-session-query-sqlite — SQLite FTS provider: maintains a full-text index updated on each event, supports ranked cross-session search with opaque cursor pagination.

The ctx.sessionQuery service is consumed by session.search in the apiproxy layer, which handles result deduplication, stale-generation restarts, and per-provider page-size probing.

What Edge Changed

Simplified Replacement Linear scan search

Edge does not install the upstream SessionQueryEngine or the SQLite FTS provider. Instead, searchApiSessions() in session-store.ts implements a bounded linear scan:

  • Scans the most recent 32 sessions (MAX_SEARCH_SESSIONS)
  • For each session, loads up to 512 events (MAX_SEARCH_EVENTS_PER_SESSION) or 256 KB (MAX_SEARCH_STORED_BYTES_PER_SESSION)
  • Extracts search documents using upstream's buildSessionEventSearchDocuments()
  • Matches against a normalized query string

This reuses the upstream text extraction logic but bypasses the FTS index entirely.

What Edge Did NOT Change

  • Search document extraction via buildSessionEventSearchDocuments() — upstream logic, reused as-is
  • Search result schema (SessionSearchItem with snippets) — upstream format
  • The session.search API contract exposed to the client

Performance Characteristics

Search latency

Each search scans up to 32 sessions × 512 events = 16,384 events in the worst case. Events are loaded from DO SQL (live sessions) or persistence (cold sessions). The linear scan has no index — latency scales with the number of sessions and their size. For a typical deployment with a few dozen sessions, this completes in tens of milliseconds.

Search coverage limitations

Sessions with more than 512 events are skipped entirely (marked as hasMore). Only the 32 most recent sessions are searched. There is no cross-session ranking — results are returned in session recency order, not relevance order.

Architecture Summary

Component Category Edge Code
Text extraction Reuse buildSessionEventSearchDocuments() from upstream
Search engine Replace Linear scan in searchApiSessions()
FTS index Not installed

Key observation: Edge trades search quality for simplicity. The FTS index and its SQLite dependency are avoided; the search is "good enough" for personal single-user deployments with limited session counts. The text extraction is upstream code, so upgrading to full FTS later would only require installing the provider plugin.

TODO

Evaluate DO SQL FTS. Durable Objects support SQLite, which includes FTS5. The upstream dsh-session-query-sqlite provider could potentially be installed directly if its SQLite access pattern is compatible with DO's SQL API. This would replace the linear scan with indexed search, lifting the 32-session and 512-event limits.

English

中文

Clone this wiki locally