Skip to content

Class: SearchPlugin

AppKit extension plugin for agent tools, federated search, and optional Vector Search lifecycle operations. Register aiSearch() or lakebaseAiSearch() before this plugin.

import { createApp, server } from "@databricks/appkit";
import { aiSearch } from "@databricks/appkit/beta";
import { search } from "@dbx-tools/search";
await createApp({
plugins: [
server(),
aiSearch({
indexes: {
docs: {
indexName: "main.support.docs",
columns: ["id", "title", "body"],
},
},
}),
search({
index: "main.support.docs",
indexes: [{ name: "main.support.docs", alias: "docs" }],
}),
],
});

new SearchPlugin(config): SearchPlugin

SearchPluginConfig

SearchPlugin

ToolRegistryPlugin<SearchPluginConfig>.constructor

protected app: AppManager

ToolRegistryPlugin.app


protected cache: CacheManager

ToolRegistryPlugin.cache


protected config: SearchPluginConfig

ToolRegistryPlugin.config


protected optional context?: PluginContext

ToolRegistryPlugin.context


protected devFileReader: DevFileReader

ToolRegistryPlugin.devFileReader


protected isReady: boolean

ToolRegistryPlugin.isReady


name: string

Plugin name identifier.

ToolRegistryPlugin.name


protected streamManager: StreamManager

ToolRegistryPlugin.streamManager


protected telemetry: ITelemetry

ToolRegistryPlugin.telemetry


static manifest: object

config: object

schema: JSONSchema7 = SEARCH_CONFIG_SCHEMA

description: string

displayName: string = "AI Search"

name: "search" = "search"

resources: object

optional: never[] = []

required: never[] = []

stability: "beta" = "beta"


static phase: PluginPhase

Plugin initialization phase.

  • ‘core’: Initialized first (e.g., config plugins)
  • ‘normal’: Initialized second (most plugins)
  • ‘deferred’: Initialized last (e.g., server plugin)

ToolRegistryPlugin.phase

get protected toolRegistry(): ToolRegistry

The tools this plugin offers to an AppKit agent. search / universal_search are reads; add_documents / create_index / sync_index are only offered when the write surface is enabled. None is autoInheritable: every tool runs under the caller’s identity, so it must be granted explicitly.

ToolRegistry

ToolRegistryPlugin.toolRegistry

abortActiveOperations(): void

void

ToolRegistryPlugin.abortActiveOperations


asUser(req): this

Execute operations using the user’s identity from the request. Returns a proxy of this plugin where all method calls execute with the user’s Databricks credentials instead of the service principal.

Request

The Express request containing the user token in headers

this

A proxied plugin instance that executes as the user

AuthenticationError if user token is not available in request headers (production only). In development mode (NODE_ENV=development), skips user impersonation instead of throwing.

ToolRegistryPlugin.asUser


attachContext(deps?): void

Binds runtime dependencies (telemetry provider, cache, plugin context) to this plugin. Called by AppKit._createApp after construction and before setup(). Idempotent: safe to call if the constructor already bound them eagerly. Kept separate so factories can eagerly construct plugin instances without running this before TelemetryManager.initialize() / CacheManager.getInstance() have run.

unknown

TelemetryOptions

void

ToolRegistryPlugin.attachContext


clientConfig(): Record<string, unknown>

Surface the index catalogue + defaults so a search box needs no round-trip.

Record<string, unknown>

ToolRegistryPlugin.clientConfig


protected execute<T>(fn, options, userKey?): Promise<ExecutionResult<T>>

Execute a function with the plugin’s interceptor chain.

Returns an ExecutionResult discriminated union:

  • { ok: true, data: T } on success
  • { ok: false, status: number, message: string } on failure

Errors are never thrown — the method is production-safe.

T

(signal?) => Promise<T>

PluginExecutionSettings

string

Promise<ExecutionResult<T>>

ToolRegistryPlugin.execute


executeAgentTool(name, args, signal?, _context?): Promise<unknown>

Validate and dispatch one AppKit agent tool call.

string

unknown

AbortSignal

AgentToolExecutionContext

Promise<unknown>

ToolRegistryPlugin.executeAgentTool


protected executeStream<T>(res, fn, options, userKey?): Promise<void>

T

IAppResponse

StreamExecuteHandler<T>

StreamExecutionSettings

string

Promise<void>

ToolRegistryPlugin.executeStream


exports(): object

Returns the public exports for this plugin. Override this to define a custom public API. By default, returns an empty object.

The returned object becomes the plugin’s public API on the AppKit instance (e.g. appkit.myPlugin.method()). AppKit automatically binds method context and adds asUser(req) for user-scoped execution.

addDocuments: (request, signal?) => Promise<{ count: number; index: string; }>

Add or update documents in a direct-access index (throws when writes are disabled).

unknown

string

AbortSignal

Promise<{ count: number; index: string; }>

createIndex: (request, signal?) => Promise<{ columns: string[]; directAccess?: boolean; endpoint?: string; name: string; primaryKey?: string; ready: boolean; rowCount?: number; }>

Create a Vector Search index (throws when writes are disabled).

string[] = ...

number = ...

string = ...

string = ...

string = ...

string = ...

"TRIGGERED" | "CONTINUOUS" = ...

string = ...

string = ...

AbortSignal

Promise<{ columns: string[]; directAccess?: boolean; endpoint?: string; name: string; primaryKey?: string; ready: boolean; rowCount?: number; }>

search: (request, signal?) => Promise<{ count: number; hits: object[]; index?: string; query: string; }>

Search one index (default when omitted). Runs as the current context user.

string[] = ...

Record<string, string | number | boolean | (string | number)[]> = ...

string = ...

number = ...

"hybrid" | "vector" | "keyword" = ...

string = ...

number = ...

AbortSignal

Promise<{ count: number; hits: object[]; index?: string; query: string; }>

syncIndex: (request, signal?) => Promise<{ index: string; synced: boolean; }>

Sync a Delta Sync index from its source table (throws when writes are disabled).

string = ...

AbortSignal

Promise<{ index: string; synced: boolean; }>

universalSearch: (request, signal?) => Promise<{ count: number; hits: object[]; index?: string; query: string; }>

Search across every configured index and merge the hits.

string[] = ...

number = ...

"hybrid" | "vector" | "keyword" = ...

string = ...

AbortSignal

Promise<{ count: number; hits: object[]; index?: string; query: string; }>

class MyPlugin extends Plugin {
private getData() { return []; }
exports() {
return { getData: this.getData };
}
}
// After registration:
const appkit = await createApp({ plugins: [myPlugin()] });
appkit.myPlugin.getData();

ToolRegistryPlugin.exports


getAgentTools(): AgentToolDefinition[]

Tool definitions offered to an AppKit agent.

AgentToolDefinition[]

ToolRegistryPlugin.getAgentTools


getEndpoints(): PluginEndpointMap

PluginEndpointMap

ToolRegistryPlugin.getEndpoints


getSkipBodyParsingPaths(): ReadonlySet<string>

ReadonlySet<string>

ToolRegistryPlugin.getSkipBodyParsingPaths


injectRoutes(router): void

Mount extension routes under /api/search. Single-index queries stay on the provider’s native /api/ai-search/:alias/query surface.

Router

void

ToolRegistryPlugin.injectRoutes


protected registerEndpoint(name, path): void

string

string

void

ToolRegistryPlugin.registerEndpoint


protected resolveUserId(req): string

Resolve the effective user ID from a request.

Returns the x-forwarded-user header when present. In development mode (NODE_ENV=development) falls back to the current context user ID so that callers outside an active runInUserContext scope still get a consistent value.

Request

string

AuthenticationError in production when no user header is present.

ToolRegistryPlugin.resolveUserId


protected route<_TResponse>(router, config): void

_TResponse

Router

RouteConfig

void

ToolRegistryPlugin.route


setup(): Promise<void>

Attach the registered provider and log the effective policy at boot.

Promise<void>

ToolRegistryPlugin.setup


shutdown(): void

Release this plugin’s instance-owned runtime.

void