Support bounded, candidate-scoped queries across search backends

Merged
PI
13h ago
+900-11

ArchiveBox can now ask a registered backend to evaluate content operands on a page of snapshots that already passed its permission and metadata filters. The optional commands.search_candidates command reads a bounded request and streams JSONL with confirmed matches, confirmed misses, available relevance scores and resource usage. An omitted operand stays unknown, including under negation.

  • Sonic returns positive evidence and relevance from its native result order. Its tokenizer cannot certify a case-sensitive literal or a missing document.
  • SQLite uses its existing FTS5 postings and BM25 scores. It checks literals against the original indexed text and opens both current and older index layouts read-only.
  • RipGrep accepts host-resolved snapshot directories and shares file, byte, directory-entry and elapsed-time limits across the batch. Multiple operands reuse the same file read.
  • Plugins that produce outgoing navigational URLs can declare an outlinks_path so hosts can discover the artifact.

The screenshots show the actual SQLite backend against the same pair of indexed snapshots. The first document contains “Solar Panel” and the second contains “solar panel”. A third candidate has no indexed document.

Before — the original phrase search returns both indexed IDs.

Original SQLite search

After — the literal query returns a confirmed hit, a confirmed miss and an unknown.

Candidate-scoped SQLite search

Registered-command tests exercise a real Sonic daemon (including a stalled socket), current and older SQLite FTS5 layouts, a locked index, and files read by RipGrep. Partial reads and backend failures preserve confirmed matches. The screenshots use the current main branch (c01cb3b4) and this branch against the same two freshly indexed documents.


Summary by cubic

Adds an optional commands.search_candidates command so search backends evaluate content operands against a bounded, authorized page of snapshot IDs. Requests are one JSON object on stdin; responses stream JSONL with confirmed matches, misses, scores, and usage consumed. Unsupported or unverifiable operands stay unknown, even under negation, and a stalled or locked provider never hides evidence already established.

Backend behavior

  • The shared request caps each page at 64 candidates and 128 operands, requires an absolute archive_root without parent references, and enforces a read budget; each emitted row reports its bytes, files, and entries consumed.
  • Sonic reports positive evidence and relevance from its native result order but cannot certify case-sensitive literals or missing documents. Its connection pool inherits the remaining search deadline, and missing client configuration now surfaces as a clear error instead of a mid-iteration crash.
  • SQLite uses existing FTS5 postings and BM25 scores, checks literals against original indexed text, and opens current and older index layouts read-only. A locked index leaves candidates unknown rather than failing the batch.
  • RipGrep accepts host-resolved snapshot directories and shares file, byte, directory-entry, and elapsed-time limits across the batch; with an archive_root it walks from that trusted root via directory descriptors, rejecting symlinks, special files, and parent references.
  • Plugins that produce outgoing navigation URLs can declare an outlinks_path so hosts can discover the artifact.

Docs and tests

  • The SQLite screenshots show before/after behavior on the same indexed snapshots: a literal query returns a confirmed hit, a confirmed miss, and an unknown.
  • Regression coverage exercises registered commands against a real and stalled Sonic daemon, SQLite FTS5 with and without the identity lookup, and RipGrep archive scans, including archive-root confinement and unreadable-document recovery.

A read-only ArchiveBox shell on Cabbage exercised the first implementation (7e4a4ef) against its existing indexes. For three snapshots present in Sonic’s solar postings, the compound query confirmed all three, took 2.08 s to emit the first result, and read zero archive bytes. A three-snapshot public sample returned two SQLite hits for page OR "the" (0.16 s first, 1.90 s total). A domain-filtered deep:"the" returned a RipGrep hit in 2.13 s (2.19 s total, 64 KiB read). These are individual timings with a three-second budget, three-file limit and 64 KiB allowance.