UNPKG

@superagent-ai/reag

Version:
66 lines (65 loc) 2.07 kB
import { LanguageModel } from "ai"; import { z } from "zod"; export interface ClientOptions { /** * The language model instance to use for queries. * This should be an instance of a model that implements the Vercel AI SDK's LanguageModel interface. * See: https://sdk.vercel.ai/docs/foundations/providers-and-models */ model: LanguageModel; /** * The system prompt that provides context and instructions to the model. * This string sets the behavior and capabilities of the model for all queries. */ system: string; /** * The size of the batch to process documents in. * This is used to limit the number of documents processed at once. */ batchSize?: number; /** * The schema to use for the response. */ schema?: z.ZodSchema; } export interface Document { name: string; content: string; metadata?: Record<string, string | number>; } export interface QueryResult<T> { results: { relevant: T[]; irrelevant?: boolean; }; document: Document; } export interface MetadataFilter { key: string; value: string | number; operator?: "equals" | "contains" | "startsWith" | "endsWith" | "notEquals" | "greaterThan" | "lessThan" | "greaterThanOrEqual" | "lessThanOrEqual" | "regex"; } /** * The Client class that wraps a language model and exposes query methods. */ export declare class ReagClient { private readonly model; private readonly system; private readonly batchSize; private readonly schema; /** * Constructs a new Client instance. * @param options Configuration options for the Client. */ constructor(options: ClientOptions); /** * Filters documents based on metadata criteria */ private filterDocumentsByMetadata; /** * Executes a query on the assigned language model with document batching */ query<T extends z.ZodType>(prompt: string, documents: Document[], options?: { filter?: MetadataFilter[]; }): Promise<QueryResult<z.infer<T>>[]>; }