DocumentationAPI ReferenceReact SDKRelease Notes
ScaleAI

Getting Started

OverviewInstallationQuick Start

Core

Provider & Setup

Hooks

AgentsOutbound CallsCall HistoryPhone NumbersIntegration CredentialsWebhooksKnowledge BasesFunction ToolsFunction Logs

Realtime

Realtime

UI

Components

Reference

TypesUtilities
Go to platform

Knowledge Bases

Ingest documents and crawl websites to give your AI agents a searchable knowledge base using the ScaleAI React SDK.

Knowledge bases let your agents answer questions grounded in your own content — either uploaded documents or crawled web pages. This page covers all knowledge base hooks, the data model, and the full ingestion workflow.


Data models

KnowledgeBase

type KnowledgeBaseStatus = "pending" | "processing" | "ready" | "failed" | "cancelled";

interface KnowledgeBase {
  id: string;
  name: string;
  description: string | null;
  is_active: boolean;
  status?: KnowledgeBaseStatus;
  created_at: string;  // ISO 8601
  updated_at: string;  // ISO 8601
}

KnowledgeBaseDetail

Extends KnowledgeBase with ingestion output:

interface KnowledgeBaseDetail extends KnowledgeBase {
  scraped_pages: ScrapedPage[];
  ingestion_meta?: Record<string, unknown> | null;
  successful_urls?: string[] | null;
  failed_urls?: string[] | null;
  ingestion_error?: string | null;
}

interface ScrapedPage {
  id: string;
  source_url: string;
  file_path_presigned: string;  // temporary pre-signed URL for the stored content
  type: string;
}

Ingestion workflow

The typical lifecycle for a URL-based knowledge base is:

flowchart LR
  A["Discover URLs\n(optional)"] --> B["Create KB\n(file or URLs)"]
  B --> C["Poll status\nuntil ready"]
  C --> D["Attach to agent"]
  D --> E["Refresh when\ncontent changes"]
  1. Discover internal pages of a site with useDiscoverKnowledgeBaseUrls (optional but recommended).
  2. Create the knowledge base with useCreateKnowledgeBase — choose file upload or URL crawl mode.
  3. Poll the detail endpoint with useKnowledgeBaseDetails until status === "ready".
  4. Refresh with useRefreshKnowledgeBase whenever the source content changes.

useDiscoverKnowledgeBaseUrls does not require a project scope — it can be called independently before creating a knowledge base, making it ideal for a URL preview/selection step in your UI.


Hooks

useGetKnowledgeBases

Fetch a paginated list of knowledge bases.

import { useGetKnowledgeBases } from "@scalereal/sr-voice-engine-react-sdk/hooks";

function KnowledgeBaseList() {
  const { data, isLoading } = useGetKnowledgeBases({
    page: 1,
    size: 20,
    status: "ready",
    is_active: true,
    sort_by: "-updated_at",
  });

  if (isLoading) return <p>Loading…</p>;

  return (
    <ul>
      {data?.results.map((kb) => (
        <li key={kb.id}>
          {kb.name} — {kb.status}
        </li>
      ))}
    </ul>
  );
}

Parameters

ParameterTypeDescription
pagenumberPage number (1-based).
sizenumberResults per page.
searchstringFull-text search on knowledge base name.
is_activebooleanFilter by active/inactive state.
status"pending" | "processing" | "ready" | "failed" | "cancelled"Filter by ingestion status.
sort_by"created_at" | "-created_at" | "updated_at" | "-updated_at" | "name" | "-name"Sort field. Prefix with - for descending.

useKnowledgeBaseDetails

Fetch full detail for a single knowledge base, including its scraped pages and ingestion metadata.

import { useKnowledgeBaseDetails } from "@scalereal/sr-voice-engine-react-sdk/hooks";

function KnowledgeBaseStatus({ id }: { id: string }) {
  const { data, isLoading } = useKnowledgeBaseDetails(id);

  if (isLoading) return <p>Loading…</p>;

  return (
    <div>
      <p>Status: {data?.status}</p>
      <p>Pages scraped: {data?.scraped_pages.length}</p>
      {data?.failed_urls?.map((url) => (
        <p key={url} className="text-red-500">Failed: {url}</p>
      ))}
    </div>
  );
}

Parameters

ParameterTypeDescription
knowledgeBaseIdstringID of the knowledge base to fetch.
enabledbooleanPass false to disable the query (default true).

useCreateKnowledgeBase

Create a new knowledge base. Two modes are supported and are mutually exclusive.

File upload mode

import { useCreateKnowledgeBase } from "@scalereal/sr-voice-engine-react-sdk/hooks";

function UploadKnowledgeBase() {
  const { mutate: createKB, isPending } = useCreateKnowledgeBase();

  function handleUpload(file: File) {
    createKB(
      {
        name: "Product Manual",
        description: "Full product documentation",
        file,
      },
      {
        onSuccess(data) {
          console.log("Knowledge base created:", data.knowledge_base.id);
        },
      }
    );
  }

  return (
    <button onClick={() => handleUpload(myFile)} disabled={isPending}>
      Upload Document
    </button>
  );
}

URL crawl mode

createKB({
  name: "Help Center",
  description: "Crawled from help.example.com",
  urls: [
    "https://help.example.com/getting-started",
    "https://help.example.com/faq",
  ],
  refresh_interval_days: 7,  // auto-refresh every 7 days
});

Request body

FieldTypeRequiredDescription
namestring✓Display name for the knowledge base.
descriptionstring✗Optional description.
fileFile✗*Document to ingest. Required when using file mode.
urlsstring[]✗*List of URLs to crawl. Required when using URL mode.
refresh_interval_daysnumber | null✗URL mode only. Auto-refresh cadence in days. null disables auto-refresh.

Response

interface CreateKnowledgeBaseResponse {
  knowledge_base: KnowledgeBase;
  successful_urls?: string[];
  failed_urls?: string[];
  type?: string;
}

useUpdateKnowledgeBase

Update the name, description, or active state of an existing knowledge base.

import { useUpdateKnowledgeBase } from "@scalereal/sr-voice-engine-react-sdk/hooks";

function EditKnowledgeBase({ id }: { id: string }) {
  const { mutate: updateKB } = useUpdateKnowledgeBase();

  const deactivate = () =>
    updateKB({ knowledgeBaseId: id, data: { is_active: false } });

  const rename = (name: string) =>
    updateKB({ knowledgeBaseId: id, data: { name } });

  return (
    <div>
      <button onClick={deactivate}>Deactivate</button>
      <button onClick={() => rename("New Name")}>Rename</button>
    </div>
  );
}

Request body

FieldTypeDescription
knowledgeBaseIdstringID of the knowledge base.
data.namestringNew display name.
data.descriptionstringNew description.
data.is_activebooleanActivate or deactivate.

useDeleteKnowledgeBase

Soft-deletes the knowledge base by setting is_active: false. The record and its ingested content are retained.

import { useDeleteKnowledgeBase } from "@scalereal/sr-voice-engine-react-sdk/hooks";

function DeleteKnowledgeBase({ id }: { id: string }) {
  const { mutate: deleteKB } = useDeleteKnowledgeBase();
  return (
    <button onClick={() => deleteKB({ knowledgeBaseId: id })}>Delete</button>
  );
}

useRefreshKnowledgeBase

Re-crawls the source URLs for a URL-based knowledge base. Use this when source content changes between automatic refresh cycles.

import { useRefreshKnowledgeBase } from "@scalereal/sr-voice-engine-react-sdk/hooks";

function RefreshButton({ id }: { id: string }) {
  const { mutate: refresh, isPending } = useRefreshKnowledgeBase();
  return (
    <button onClick={() => refresh({ knowledgeBaseId: id })} disabled={isPending}>
      {isPending ? "Refreshing…" : "Refresh Content"}
    </button>
  );
}

useRefreshKnowledgeBase only applies to URL-based knowledge bases. Calling it on a file-based knowledge base will have no effect.


useCancelKnowledgeBase

Cancels an in-progress ingestion job. Status will transition to "cancelled".

import { useCancelKnowledgeBase } from "@scalereal/sr-voice-engine-react-sdk/hooks";

const { mutate: cancel } = useCancelKnowledgeBase();
cancel({ knowledgeBaseId: id });

useRetryKnowledgeBase

Retries ingestion for a knowledge base in "failed" state.

import { useRetryKnowledgeBase } from "@scalereal/sr-voice-engine-react-sdk/hooks";

const { mutate: retry } = useRetryKnowledgeBase();
retry({ knowledgeBaseId: id });

useDiscoverKnowledgeBaseUrls

Discovers all internal pages of a website before crawling. Returns a list of URLs for the user to review and select from. Does not require an existing knowledge base.

import { useDiscoverKnowledgeBaseUrls } from "@scalereal/sr-voice-engine-react-sdk/hooks";

function UrlDiscovery() {
  const { mutate: discover, data, isPending } = useDiscoverKnowledgeBaseUrls();

  return (
    <div>
      <button
        onClick={() => discover({ url: "https://help.example.com" })}
        disabled={isPending}
      >
        Discover Pages
      </button>

      {data && (
        <ul>
          {data.map((url) => (
            <li key={url}>{url}</li>
          ))}
        </ul>
      )}
    </div>
  );
}

Parameters

ParameterTypeDescription
urlstringRoot URL of the website to crawl-discover.

Returns string[] — the list of discovered internal page URLs.


Cache keys

Use knowledgeBaseKeys to invalidate or prefetch knowledge base queries:

import { knowledgeBaseKeys } from "@scalereal/sr-voice-engine-react-sdk/hooks";
import { useQueryClient } from "@tanstack/react-query";

const queryClient = useQueryClient();

// Invalidate all KB list queries
queryClient.invalidateQueries({ queryKey: knowledgeBaseKeys.all });

Polling for ingestion status

Knowledge base ingestion is asynchronous. After creation, poll useKnowledgeBaseDetails until status === "ready":

import { useKnowledgeBaseDetails } from "@scalereal/sr-voice-engine-react-sdk/hooks";

function KnowledgeBasePoller({ id }: { id: string }) {
  const { data } = useKnowledgeBaseDetails(id, true);

  const isProcessing =
    data?.status === "pending" || data?.status === "processing";

  // Re-fetch every 3 seconds while ingestion is in progress
  useEffect(() => {
    if (!isProcessing) return;
    const interval = setInterval(() => {
      queryClient.invalidateQueries({ queryKey: knowledgeBaseKeys.detail(id) });
    }, 3000);
    return () => clearInterval(interval);
  }, [isProcessing, id]);

  return <p>Status: {data?.status ?? "loading…"}</p>;
}

Ingestion status reference

StatusDescription
pendingJob queued, not yet started.
processingIngestion in progress (crawling or parsing).
readyIngestion complete — knowledge base is available to agents.
failedIngestion failed. Use useRetryKnowledgeBase to retry.
cancelledIngestion was cancelled. Use useRetryKnowledgeBase to retry.

Related pages

  • Agents — Attach knowledge bases to an agent's configuration.
  • Provider & Setup — Wrap your app with the SDK provider.

Webhooks

Manage event subscriptions and inspect delivery attempts.

Function Tools

Create and manage the tools your voice agents can invoke during a call — from HTTP endpoints to calendar bookings.

On this page

Data modelsKnowledgeBaseKnowledgeBaseDetailIngestion workflowHooksuseGetKnowledgeBasesParametersuseKnowledgeBaseDetailsParametersuseCreateKnowledgeBaseFile upload modeURL crawl modeRequest bodyResponseuseUpdateKnowledgeBaseRequest bodyuseDeleteKnowledgeBaseuseRefreshKnowledgeBaseuseCancelKnowledgeBaseuseRetryKnowledgeBaseuseDiscoverKnowledgeBaseUrlsParametersCache keysPolling for ingestion statusIngestion status referenceRelated pages