@dbx-tools/shared-search
v0.6.211
Published
Readme
@dbx-tools/shared-search
Browser-safe schemas and extension types for AppKit-compatible AI Search providers.
Import this package when a UI, Mastra tool schema, server route, or test needs
to validate the same search payloads that
@dbx-tools/search reads and writes.
Key features:
- Shared
SearchRequest/SearchResultcontract with{ id, score, fields }hits, so an autocomplete box, a docs lookup, and a Mastra tool speak one shape. SearchMode(hybrid/vector/keyword) plustoAiSearchQueryType()for the AppKit query vocabulary.UniversalSearchRequestfor federated search across several indexes at once.SearchDocument/UpsertResultfor adding and updating direct-access index contents.SearchIndexInfo/SearchClientConfigfor the boot-time index catalogue a search box reads with no server round-trip.- Model/tool-friendly schemas that avoid JSON Schema constraints known to cause problems with some serving endpoints.
Validate A Search Request
import { search, type SearchRequest } from "@dbx-tools/shared-search";
const request: SearchRequest = search.searchRequestSchema.parse({
query: "reset my password",
index: "main.support.docs",
limit: 5,
mode: "hybrid",
filter: { locale: "en", category: ["billing", "support"] },
});Validate Search Results
const result = search.searchResultSchema.parse(await response.json());
for (const hit of result.hits) {
console.log(hit.score, hit.id, hit.fields.title);
}searchHitSchema returns the requested columns under fields, keyed by column
name, plus the primary-key id and a relevance score. A federated hit also
carries the index it came from.
Read The Index Catalogue
const config = search.searchClientConfigSchema.parse(
await fetch("/api/search/indexes").then((r) => r.json()),
);searchClientConfigSchema is the extension catalogue for universal search.
Single-index UI queries read native aiSearch client config instead.
Module
search-searchModeSchema,searchRequestSchema,searchHitSchema,searchResultSchema,universalSearchRequestSchema,searchDocumentSchema,upsertResultSchema,searchIndexInfoSchema,searchClientConfigSchema, andtoAiSearchQueryType, the flat inferred types (SearchMode,SearchRequest,SearchHit,SearchResult,UniversalSearchRequest,SearchDocument,UpsertResult,SearchIndexInfo,SearchClientConfig).
Runtime search, index management, the Mastra tools, and the AppKit plugin live
in @dbx-tools/search. The React search box lives in
@dbx-tools/ui-search.