Docs/SDK/Programmatic Indexing

Programmatic Indexing

Push content directly into your knowledge base without waiting for the web crawler. This is perfect for seeding test environments on localhost or handing specific documents over to an agent workflow.

Overview

When working locally (e.g. on localhost), the Apptvty cloud crawler cannot reach your website to index its contents. The indexDocument() function solves this by letting you push raw text directly to your site ID's database.

typescript
import { indexDocument } from 'apptvty/setup';

async function seedKnowledgeBase() {
  const result = await indexDocument({
    apiKey: process.env.APPTVTY_API_KEY!,
    siteId: process.env.APPTVTY_SITE_ID!,
    url: 'http://localhost:3000/faq',
    title: 'Frequently Asked Questions',
    content: 'Apptvty is an agentic optimization platform. It helps agents parse your site easily...'
  });

  console.log('Chunks Indexed:', result.chunks_indexed);
  console.log('Status:', result.status);
}

IndexDocumentOptions

FieldTypeDescription
apiKeystringRequired. Your site API key starting with ak_...
siteIdstringRequired. Your Apptvty Site ID.
urlstringRequired. The URL the content belongs to (used for source citations).
contentstringRequired. The full, raw text content you want embodied and indexed.
titlestringOptional. A title for the document.
apiUrlstringOptional. Override API base URL.

IndexDocumentResult

Returns feedback from the semantic chunking and embedding pipeline.

typescript
interface IndexDocumentResult {
  site_id: string;
  url: string;
  chunks_indexed: number;  // How many text chunks were generated and embedded
  chunks_skipped: number;  // How many chunks were skipped (e.g. unmodified since last crawl)
  status: 'success' | 'error';
}