Cache search results between page navigations #1

Open
opened 2026-10-23 22:48:22 +00:00 by lichenblankie · 0 comments

Every search page load re-executes the full pipeline:

  • BM25 FTS5 query (LIMIT 100)
  • ONNX inference to embed the query (~10–50ms)
  • HNSW knn_query() for ANN (~5ms)
  • RRF fusion of BM25 + semantic scores
  • Tag matching

Then fused_ids[offset:offset + PER_PAGE] discards all but 10 results. Pages 2+ recompute the exact same fused result set for a different slice.

Fix: Cache the fused result set in memory keyed by (query_text, semantic_flag). On subsequent page loads, slice from cache instead of re-running inference + ANN + fusion.

~20 lines in search.py. A simple dict with a short TTL (30–60s) or a generational counter incremented on reindex.

Benefit: Cuts page 2+ latency from ~60ms to ~0ms. Also guarantees consistent results across pages.


Synced from Codeberg issue #1 — opened by @fluffblankie on 2026-07-04.

Every search page load re-executes the full pipeline: - BM25 FTS5 query (LIMIT 100) - ONNX inference to embed the query (~10–50ms) - HNSW knn_query() for ANN (~5ms) - RRF fusion of BM25 + semantic scores - Tag matching Then fused_ids[offset:offset + PER_PAGE] discards all but 10 results. Pages 2+ recompute the exact same fused result set for a different slice. Fix: Cache the fused result set in memory keyed by (query_text, semantic_flag). On subsequent page loads, slice from cache instead of re-running inference + ANN + fusion. ~20 lines in search.py. A simple dict with a short TTL (30–60s) or a generational counter incremented on reindex. Benefit: Cuts page 2+ latency from ~60ms to ~0ms. Also guarantees consistent results across pages. --- *Synced from [Codeberg issue #1](https://codeberg.org/tinyweb/tinyweb/issues/1) — opened by @fluffblankie on 2026-07-04.* <!-- codeberg-issue: 1 -->
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lichenblankie/tinyweb#1
No description provided.