import { type SkillIndexCache, type SkillIndexScoring } from '../skill-index-cache.interface'; import { type SkillContent } from '../../common/interfaces'; import { type MutableSkillStorageProvider, type SkillListOptions, type SkillListResult, type SkillLoadResult, type SkillSearchOptions, type SkillSearchResult, type SkillStorageProviderType } from '../skill-storage.interface'; import { type SkillToolValidator } from '../skill-validator'; /** * Configuration options for MemorySkillProvider. */ export interface MemorySkillProviderOptions { /** * Default number of search results. * @default 10 */ defaultTopK?: number; /** * Default minimum similarity threshold. * @default 0.1 */ defaultMinScore?: number; /** * Optional tool validator for enriching results. */ toolValidator?: SkillToolValidator; /** * Ranking function for the underlying vector DB. `bm25` gives stronger keyword * relevance; `cosine` (default) preserves the historical behavior. Only takes * effect when the installed `vectoriadb` supports it (newer versions); older * versions silently ignore it and use cosine. * @default 'cosine' */ scoring?: SkillIndexScoring; /** * Optional cache for the built index so a cold start can restore it instead of * recomputing IDF + embeddings for the whole corpus. Used only when the * installed `vectoriadb` exposes snapshot support. */ indexCache?: SkillIndexCache; } /** * In-memory skill storage provider using TF-IDF for search. * * This is the default provider used when no external storage is configured. * It stores skills in memory and uses TF-IDF vectorization for similarity search. */ export declare class MemorySkillProvider implements MutableSkillStorageProvider { readonly type: SkillStorageProviderType; private vectorDB?; private readonly vectorDBReady; private skills; private defaultTopK; private defaultMinScore; private toolValidator?; private initialized; /** Ranking mode passed to the vector DB (cosine | bm25). */ private readonly scoring; /** Optional snapshot cache for fast cold-start (e.g. KV-backed on the edge). */ private indexCache?; /** * Whether the vector index reflects the current document set. Adds/removes * mark it stale; the FIRST search after a mutation builds (or restores) it * exactly once. This defers the expensive IDF/embedding pass off the * registration hot-path — registering N skills no longer triggers N reindexes. */ private indexReady; constructor(options?: MemorySkillProviderOptions); private initVectorDB; /** * Attach (or replace) the snapshot cache after construction — useful when the * cache binding only exists at request time (e.g. a Cloudflare KV namespace on * `env`). Marks the index stale so the next search consults the new cache. */ setIndexCache(cache: SkillIndexCache | undefined): void; /** * Ensure the vector index reflects the current document set, building it AT * MOST once per mutation batch. When a snapshot cache is configured and the * vector DB supports snapshots, a content-hash hit restores the index without * recomputing IDF/embeddings (the cold-start fast path); a miss rebuilds and * persists the snapshot for next time. Cache failures degrade to a local * rebuild — they never block search. */ private ensureIndexed; /** * Eagerly build (or restore from cache) the search index now, rather than on * the first search. A host calls this after registration completes to move the * one-time index build off the first request's critical path (e.g. the edge * does this right after attaching the KV cache). */ warm(): Promise; /** Force the vector DB to (re)compute its index now. */ private reindexNow; /** * Stable content hash of the indexed skill set + scoring mode. Changing any * skill's searchable text, the set of skills, or the scoring mode changes the * key, so a stale snapshot is never restored. */ private computeIndexKey; /** Await the lazy vectoriadb load (throws the clear install hint if absent). */ private db; /** * Set the tool validator after construction. * Useful when the validator isn't available at construction time. */ setToolValidator(validator: SkillToolValidator): void; initialize(): Promise; search(query: string, options?: SkillSearchOptions): Promise; load(skillId: string): Promise; list(options?: SkillListOptions): Promise; exists(skillId: string): Promise; count(options?: { tags?: string[]; includeHidden?: boolean; }): Promise; add(skill: SkillContent): Promise; update(skillId: string, skill: SkillContent): Promise; remove(skillId: string): Promise; clear(): Promise; dispose(): Promise; /** * Bulk add skills (more efficient than adding one by one). */ addMany(skills: SkillContent[]): Promise; /** * Index a single skill in the vector database. */ private indexSkill; /** * Build searchable text for TF-IDF indexing. * Uses term weighting to improve relevance: * - Description: 3x weight (most important for matching) * - Tags: 2x weight * - Tools: 1x weight * - Name: 1x weight */ private buildSearchableText; /** * Fallback text search when TF-IDF produces no results (e.g., single-document corpus). * Performs case-insensitive substring matching on the searchable text. */ private fallbackTextSearch; /** * Convert SkillContent to SkillMetadata. * This is needed because SkillContent doesn't store the original metadata format. */ private skillToMetadata; /** * Get tags from a skill (stored in metadata but not in SkillContent directly). * We store them in a custom property for now. */ private getSkillTags; /** * Check if a skill is hidden from discovery. */ private isHidden; /** * Get priority of a skill. */ private getPriority; /** * Get visibility of a skill. */ private getVisibility; } //# sourceMappingURL=memory-skill.provider.d.ts.map