UNPKG

@mastra/rag

Version:

The Retrieval-Augmented Generation (RAG) module contains document processing and embedding utilities.

54 lines 2.83 kB
import type { MastraUnion } from '@mastra/core/action'; import type { RequestContext } from '@mastra/core/request-context'; import type { MastraVector } from '@mastra/core/vector'; import type { VectorStoreResolver } from '../tools/types.js'; interface Logger { error(message: string, data?: Record<string, unknown>): void; warn(message: string, data?: Record<string, unknown>): void; } /** * Context for resolving vector stores. */ export interface ResolveVectorStoreContext { requestContext?: RequestContext; mastra?: MastraUnion; /** Fallback vector store name to look up from mastra if vectorStore option is not provided */ vectorStoreName: string; /** * When true, logs a warning and falls back to mastra.getVector if an explicitly provided * vectorStore is invalid. When false (default), throws an error for invalid vectorStore. * @default false */ fallbackOnInvalid?: boolean; } /** * Resolves a vector store from options, supporting both static instances and dynamic resolver functions. * For multi-tenant setups, the resolver function receives the request context to select the appropriate store. * * @param options - Tool options object that may contain a vectorStore property * @param context - Context including requestContext, mastra instance, and fallback vectorStoreName * @param logger - Optional logger for warning/error reporting * @returns The resolved MastraVector instance, or undefined if not found * @throws Error if an explicit vectorStore was provided but is invalid (unless fallbackOnInvalid is true) */ export declare function resolveVectorStore(options: { vectorStore?: MastraVector | VectorStoreResolver; } | Record<string, unknown>, context: ResolveVectorStoreContext, logger?: Logger | null): Promise<MastraVector | undefined>; /** * Coerces a topK value to a number, handling string inputs and providing a default. * Validates that the result is a finite positive number greater than zero. * @param topK - The value to coerce (number, string, or undefined) * @param defaultValue - Default value if coercion fails (defaults to 10) * @returns A valid positive number for topK, or defaultValue if invalid/non-finite/zero/negative */ export declare function coerceTopK(topK: number | string | undefined, defaultValue?: number): number; /** * Parses a filter value, handling both string (JSON) and object inputs. * @param filter - The filter value to parse (string or object) * @param logger - Optional logger for error reporting * @returns Parsed filter object * @throws Error if filter is a string that cannot be parsed as JSON or if filter is not a plain object */ export declare function parseFilterValue(filter: unknown, logger?: Logger | null): Record<string, any>; export {}; //# sourceMappingURL=tool-helpers.d.ts.map