[Feature]: knowledge-base list has no paging — 4,388 KBs cost 36 MB and ~14 s per page open
Summary
On a tenant that has grown past a few hundred knowledge bases, the KB list is unusable: GET /api/v1/knowledge-bases returns every row with all 39 fields, and the list page renders all of them client-side. On our production instance (4,388 KBs) one page open costs 36 MB and ~14 s on a warm connection, and the frontend then builds 4,388 cards.
?page= / ?page_size= are silently ignored — the response is byte-for-byte identical with and without them.
The handler already documents the assumption this breaks:
// internal/handler/knowledgebase.go:653
kbs, err := h.service.ListKnowledgeBases(ctx)
// ...:661
// control on the list page. We filter in-process rather than pushing
// down into SQL because the tenant-bounded KB list is small (typically
// <100 rows) and adding a creator predicate to ListKnowledgeBases would
// ripple through every other caller (chat pipeline, agent editor, …).
<100 rows is a reasonable default, but nothing stops a tenant from reaching thousands — importing/provisioning per-user KBs does it easily. Our tenant reached 4.4k with a script that creates one KB per person/folder.
Measurements (self-hosted, v0.9.0, PostgreSQL 16)
4,388 KBs / 27,091 documents / single tenant:
GET /api/v1/knowledge-bases
run 1: HTTP 200 13.84 s 38,032,329 bytes
run 2: HTTP 200 14.20 s 38,032,329 bytes
run 3: HTTP 200 13.21 s 38,032,329 bytes
GET /api/v1/knowledge-bases?page=1&page_size=10
HTTP 200 13.84 s 38,032,329 bytes rows returned: 4,388
Root cause — nothing in the read path can page
Handler (internal/handler/knowledgebase.go) reads only agent_id and creator from the query string; there is no page/page_size/limit/offset.
Repository (internal/application/repository/knowledgebase.go:83) — no Limit:
func (r *knowledgeBaseRepository) ListKnowledgeBasesByTenantID(
ctx context.Context, tenantID uint64,
) ([]*types.KnowledgeBase, error) {
var kbs []*types.KnowledgeBase
if err := r.db.WithContext(ctx).Where("tenant_id = ? AND is_temporary = ?", tenantID, false).
Order("created_at DESC").Find(&kbs).Error; err != nil {
return nil, err
}
return kbs, nil
}
Frontend (frontend/src/views/knowledge/KnowledgeBaseList.vue, 2,112 lines) has no pagination and no virtual list — a plain v-for over filteredKnowledgeBases, so all 4,388 records become DOM:
<template v-for="(kb, index) in filteredKnowledgeBases" :key="kb.id">
Checked main today (internal/handler/knowledgebase.go:653, internal/application/repository/knowledgebase.go:83): identical, so this is not fixed on main.
Why the payload is 36 MB — 62.6% is extract_config
Measured by summing len(json.dumps(value)) per field across the whole response:
| field | bytes | share |
|---|---|---|
extract_config |
23,794,353 | 62.6% |
chunking_config |
3,530,214 | 9.3% |
wiki_config |
2,459,168 | 6.5% |
generated_profile |
1,459,921 | 3.8% |
vlm_config |
696,293 | 1.8% |
storage_config |
513,406 | 1.3% |
image_processing_config |
511,604 | 1.3% |
indexing_strategy |
418,834 | 1.1% |
asr_config |
372,875 | 1.0% |
capabilities |
339,850 | 0.9% |
auto_tag_config |
270,782 | 0.7% |
profile_config |
174,332 | 0.5% |
Average extract_config is ~5.4 KB per KB, and it is the full document-level parsing config (tags/schema), which the list page never uses — the card shows name, doc count, creator, timestamps.
So the list is not slow because the query is slow; it is slow because it streams 23.8 MB of per-KB parse config to draw a card that needs a few dozen bytes.
Suggested fix, cheapest first
- Trim the list response (biggest win, no API contract change). Return a list projection —
id, name, description, type, doc/word counts, creator, created_at, updated_at, is_pinned, permission— and dropextract_config,chunking_config,wiki_config,generated_profile,*_config. By the table above this alone takes 36 MB → roughly 2–3 MB and removes most of the 14 s. - Add paging to the endpoint:
offset/limit(or a cursor) plustotalin the response, keeping the unpaged behaviour for internal callers (chat pipeline,agent editor) — they can keep calling the service the way they do today. - Frontend: consume the paged response with a pager, or keep the single fetch but add a virtual list plus a filter-first UI. Paging is better here because it also fixes the transfer.
Steps 1 and 2 are independent; 1 is a pure projection change and would already make the page usable without touching the client.
Environment
- WeKnora v0.9.0, self-hosted, Docker Compose
- PostgreSQL 16, ~4.4k KBs, ~27k documents in one tenant
- Reproduced from both the browser and
curlagainst127.0.0.1:8089
A shape that would keep existing callers untouched: an opt-in lightweight=1 (or view=list) projection flag first, then offset/limit for real paging.
I’d like to take this issue. I’ll work on a paginated, lightweight knowledge-base list for the dashboard and preserve the current response for existing callers.