Skip to content

perf(knowledge): paginate facts/by_category (unbounded list) #12394

Description

@mrveiss

Problem

GET /api/knowledge_base/facts/by_category returns every fact in each category with no upper bound across categories (per-category limit defaults to 100, but all KnowledgeCategory values are fetched at once). As the KB grows this becomes a latency/memory cliff: the handler batch-fetches and JSON-serialises the full category set on every cache miss, and the frontend KnowledgeBrowser builds the entire tree in one pass.

Follow-up to #12370, which removed full_content from each list item (~98% payload cut). The remaining scaling risk is the unbounded number of items.

Proposed change

  • Backend: add cursor/limit pagination to facts/by_category (e.g. ?cursor=&limit=), returning a next_cursor + has_more — mirror the existing /entries cursor contract in useKnowledgeBrowser.fetchEntriesPage so the frontend pattern is reused, not reinvented.
  • Frontend: wire KnowledgeBrowser category expansion to infinite-scroll / "Load more" using the returned cursor (the component already has loadMore/hasMoreEntries scaffolding for the user-knowledge mode — extend it to the by-category tree).

Scope / notes

  • Keep the per-fact detail endpoint (GET /fact/{fact_key}) as the lazy-load source (unchanged by this work).
  • Preserve the 60s Redis cache; cache per (category, cursor, limit) key.
  • No data-loss risk — read-path only.

priority: medium. Discovered during #12370.

Activity

  1. mrveiss commented on Jul 25, 2026

    @mrveiss
    OwnerAuthor

    Delivered in PR #12424 (merged, review MERGE-READY). GET /facts/by_category paginated (limit/offset, stable sorted windows, total_count/has_more) + frontend load-more; #12370 snippet-only preserved. SMEMBERS-scaling/legacy-SCAN notes tracked #12426.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions