/** * Layer 4 (v1.7.5): persistence for resolved embedding metadata. * * Reads / writes the schema-v7 columns on `embedder_capability` * (`dim`, `query_prefix`, `document_prefix`, `prefix_source`, `base_model`, * `size_bytes`, `fetched_at`). * * **Cache lifetime: forever, until explicit invalidation.** v1.7.5 originally * shipped a 90-day TTL with stale-while-revalidate; that was reverted before * promotion in favour of "cache once, never auto-refetch" semantics. Reasoning: * the fields we cache (dim, model_type, hidden_size, ONNX sizes) are immutable * for a given HF model id — HF doesn't allow rewriting a published revision. * The fields that CAN change post-publish (tokenizer_config corrections, * retroactively-added prompts) change rarely, and silently auto-refetching * burns HF API quota across the whole user base for negligible benefit. * Users invalidate explicitly when they need to via the * `obsidian-brain models refresh-cache` CLI command. * * SQL-only — does not call HF, does not load JSON, does not consult seed. * All higher-level orchestration lives in `metadata-resolver.ts` (Layer 3). */ import type { DatabaseHandle } from '../store/db.js'; /** Source markers persisted into `prefix_source`. */ export type CachedPrefixSource = 'override' | 'seed' | 'metadata' | 'metadata-base' | 'readme' | 'fallback' | 'none'; /** Shape stored in / loaded from the `embedder_capability` v7 columns. */ export interface CachedMetadata { modelId: string; dim: number | null; /** Resolved max tokens (from advertised_max_tokens column for v6 compat). */ maxTokens: number | null; queryPrefix: string | null; documentPrefix: string | null; prefixSource: CachedPrefixSource; baseModel: string | null; sizeBytes: number | null; fetchedAt: number | null; } /** * Load cached metadata for `modelId`, or null if absent / has no v7 columns * populated yet. */ export declare function loadCachedMetadata(db: DatabaseHandle, modelId: string): CachedMetadata | null; /** * Persist metadata for `modelId`. Writes to v7 columns; preserves any * existing `discovered_max_tokens` / `discovered_at` / `method` from the v6 * adaptive-capacity flow (we only INSERT-or-UPDATE the v7 fields). */ export declare function upsertCachedMetadata(db: DatabaseHandle, meta: CachedMetadata): void; /** * Invalidate cached metadata so the next resolver pass refetches from the * seed → HF chain. NULLs the v7 columns (dim, query_prefix, etc.) on the * matching row(s) but preserves v6 capacity columns (`advertised_max_tokens`, * `discovered_max_tokens`, `method`) — those track adaptive-capacity drift, * not metadata, and shouldn't be reset by a metadata refresh. * * Returns the number of rows touched. When `modelId` is omitted, clears * every entry; otherwise only the row for that exact `embedder_id`. * * Called by `obsidian-brain models refresh-cache [--model ]`. */ export declare function clearMetadataCache(db: DatabaseHandle, modelId?: string): number;