Xzero UI
Pro library

Knowledge basePro

A retrieval knowledge base in one card: add sources and watch them parse, chunk, embed and index, then test a question and see which chunks come back and why.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui-pro/knowledge-base
Live · keyboard ready

Pass sources, onAdd and search to connect your ingestion and retrieval; with no props it ingests sample sources and answers test queries.

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui-pro/knowledge-base

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { KnowledgeBase } from "@/components/xzero/blocks/knowledge-base/knowledge-base";

export function SupportKnowledge({ sources, upload, retry }) {
  return (
    <KnowledgeBase
      title="Support knowledge base"
      sources={sources}
      onAddSource={({ kind, file }) => upload(kind, file)}
      onRetrySource={retry}
      onQuery={async (query, settings) => {
        const res = await fetch("/api/retrieve", { method: "POST", body: JSON.stringify({ query, ...settings, candidates: 20 }) });
        if (!res.ok) throw new Error("The retriever did not respond");
        return res.json(); // [{ id, sourceId, text, location, similarity, relevance, before, after }]
      }}
    />
  );
}

// With no props the card runs a full simulation with sample documents.
<KnowledgeBase />

API reference

KnowledgeBase

A retrieval knowledge base in one card. The Sources view lists PDFs, Notion pages, Google Drive docs and website crawls, each with a four step ingestion pipeline (parse, chunk, embed, index) that fills as it runs while page, chunk and token counts climb. Add source and a drop zone bring in new sources that ingest live; a failed source names its reason and offers Retry. The Test retrieval view runs a query and lists the top k chunks with similarity bars and scores, highlighted matching words, the source and page. Turning on Rerank reorders the same results in place and shows how far each chunk moved, and opening a result shows the chunk between its neighbours. A settings popover holds chunk size, overlap, top k, hybrid search, reranking and the embedding model, and asks for a re-index when chunking changes.

PropTypeDefaultDescription
titlestring"Support knowledge base"Heading at the top of the card.
sourcesKnowledgeSource[]–Live sources: { id, name, kind ("pdf" | "notion" | "drive" | "web" | "file"), pages, chunks, tokens, status, progress?, failedStep?, error?, note? }. status is "queued", "parse", "chunk", "embed", "index", "indexed" or "failed"; progress is 0 to 1 within the current step. Omit to run the built-in simulation with sample company documents.
chunksKnowledgeChunk[]–Chunks the built-in retriever searches when onQuery is not set: { id, sourceId, index, location, text, overview? }. index orders chunks inside a source so neighbours can be shown. Defaults to the sample corpus in the simulation.
settingsRetrievalSettings–Controlled settings: { chunkSize, overlap, topK, hybrid, rerank, embeddingModel }. Pair with onSettingsChange.
defaultSettingsPartial<RetrievalSettings>{ chunkSize: 512, overlap: 64, topK: 4, hybrid: true, rerank: false, embeddingModel: "general-v2" }Starting settings when uncontrolled.
onSettingsChange(settings: RetrievalSettings) => void–Called on every settings change, including the Rerank switch above the results. Overlap is clamped to half the chunk size.
embeddingModels{ value: string; label: string }[]four generic sample modelsOptions for the embedding model select. The text before the first comma also shows in the card summary.
suggestionsstring[]–Questions offered before the first search. Defaults to sample questions for sources that are indexed, so a new suggestion appears when its source finishes.
onQuery(query: string, settings: RetrievalSettings) => Promise<RetrievedChunk[]> | RetrievedChunk[]–Runs a retrieval test. Return candidates ({ id, sourceId, text, location?, similarity, relevance?, before?, after? }), ideally more than top k so the reranker can pull one up. The card orders by similarity, or by relevance while Rerank is on, and slices to top k. Throw to show the error state.
onAddSource(request: { kind: SourceKind; file?: File }) => void–Called by the Add source menu and for dropped or picked files. In the simulation the card also adds a sample source of that kind and ingests it.
onRetrySource(id: string) => void–Called by Retry on a failed source. The simulation resumes from the failed step.
onRemoveSource(id: string) => void–Called by Remove on a source that cannot be retried, such as an unsupported file type.
onReindex(settings: RetrievalSettings) => void–Called by Re-index after chunk size, overlap or the embedding model changed. Search keeps using the current index until each source finishes.
defaultView"sources" | "retrieval""sources"The view shown first.
classNamestring–Class on the root element.

Keyboard interactions

KeysAction
TabMoves through settings, Add source, the view switch, each Retry or Remove button and browse in Sources; and through the query field, Search, the Rerank switch and each result in Test retrieval.
Arrow left / Arrow rightOn the view switch, moves between Sources and Test retrieval. On a settings slider, changes the value by one step; Shift moves a larger step.
EnterIn the query field, runs the search. On a suggestion, runs that question. On a result, opens or closes the chunk in context.
EscapeIn the query field, clears the query and returns to suggestions. In the settings popover or the Add source menu, closes it and returns focus to its trigger.
SpaceToggles the Rerank, Hybrid search and Reranking switches and activates buttons.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Guidance for AI tools

Blocks are complete, self-contained screens with sample data. Replace the sample data and connect the callbacks described above. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components