SongGuess
    Preparing search index...

    Class AiSearchNamespaceAbstract

    Namespace-level AI Search service.

    Used as the type of env.AI_SEARCH (namespace binding via ai_search_namespaces). Scoped to a single namespace. Provides dynamic instance access, creation, deletion, and multi-instance search/chat operations.

    // Access an instance within the namespace
    const blog = env.AI_SEARCH.get("blog");
    const results = await blog.search({ query: "How does caching work?" });

    // List all instances in the namespace
    const instances = await env.AI_SEARCH.list();

    // Create a new instance with built-in storage
    const tenant = await env.AI_SEARCH.create({ id: "tenant-123" });

    // Upload items into the instance
    await tenant.items.upload("doc.pdf", fileContent);

    // Search across multiple instances
    const multi = await env.AI_SEARCH.search({
    query: "caching",
    ai_search_options: { instance_ids: ["blog", "docs"] },
    });

    // Delete an instance
    await env.AI_SEARCH.delete("tenant-123");
    Index

    Constructors

    Methods

    • Generate chat completions across multiple instances within the bound namespace (streaming). Fans out to the specified instance_ids, merges context, and generates a response.

      Parameters

      Returns Promise<ReadableStream<any>>

      ReadableStream of server-sent events.

    • Generate chat completions across multiple instances within the bound namespace. Fans out to the specified instance_ids, merges context, and generates a response.

      Parameters

      Returns Promise<AiSearchMultiChatCompletionsResponse>

      Chat completion response with choices, chunks tagged by instance_id, and optional partial-failure errors.

    • Create a new instance within the bound namespace.

      Parameters

      • config: AiSearchConfig

        Instance configuration. Only id is required — omit type and source to create with built-in storage.

      Returns Promise<AiSearchInstance>

      Instance service for the newly created instance.

      // Create with built-in storage (upload items manually)
      const instance = await env.AI_SEARCH.create({ id: "my-search" });

      // Create with web crawler source
      const instance = await env.AI_SEARCH.create({
      id: "docs-search",
      type: "web-crawler",
      source: "https://developers.cloudflare.com",
      });
    • Delete an instance from the bound namespace.

      Parameters

      • name: string

        Instance name to delete.

      Returns Promise<void>

    • Get an instance by name within the bound namespace.

      Parameters

      • name: string

        Instance name.

      Returns AiSearchInstance

      Instance service for search, chat, update, stats, items, and jobs.