/** * Metadata Manager Module * * Provides metadata management for index statistics and state tracking: * - Zod schema validation for metadata * - Version tracking for future migrations * - Statistics tracking (files, chunks, storage size) * - Timestamp management for index operations */ import { z } from 'zod'; /** * Current metadata version * * Increment this when making breaking changes to the metadata schema. * This allows future migrations to handle older metadata formats. */ export declare const CURRENT_VERSION = "1.0.0"; /** * Schema for index statistics */ export declare const StatsSchema: z.ZodObject<{ totalFiles: z.ZodNumber; totalChunks: z.ZodNumber; storageSizeBytes: z.ZodNumber; failedEmbeddings: z.ZodOptional; }, z.core.$strip>; /** * Indexing state values */ export type IndexingState = 'complete' | 'in_progress' | 'failed'; /** * Schema for indexing state tracking */ export declare const IndexingStateSchema: z.ZodObject<{ state: z.ZodEnum<{ complete: "complete"; in_progress: "in_progress"; failed: "failed"; }>; startedAt: z.ZodOptional; lastCheckpoint: z.ZodOptional; expectedFiles: z.ZodOptional; processedFiles: z.ZodOptional; errorMessage: z.ZodOptional; }, z.core.$strip>; /** * Schema for documentation index statistics */ export declare const DocsStatsSchema: z.ZodObject<{ totalDocs: z.ZodNumber; totalDocChunks: z.ZodNumber; docsStorageSizeBytes: z.ZodNumber; }, z.core.$strip>; /** * FTS engine type values */ export type FTSEngineTypeValue = 'js' | 'native'; /** * Schema for hybrid search / FTS information */ export declare const HybridSearchInfoSchema: z.ZodObject<{ enabled: z.ZodBoolean; ftsEngine: z.ZodOptional>; ftsEngineReason: z.ZodOptional; defaultAlpha: z.ZodOptional; ftsChunkCount: z.ZodOptional; }, z.core.$strip>; /** * Schema for embedding model information * Tracks which models were used to create the index for migration detection */ export declare const EmbeddingModelInfoSchema: z.ZodObject<{ codeModelName: z.ZodOptional; codeModelDimension: z.ZodOptional; docsModelName: z.ZodOptional; docsModelDimension: z.ZodOptional; }, z.core.$strip>; /** * Inferred HybridSearchInfo type from the schema */ export type HybridSearchInfo = z.infer; /** * Inferred EmbeddingModelInfo type from the schema */ export type EmbeddingModelInfo = z.infer; /** * Schema for vector index information (SMCP-091) * Tracks the vector index configuration for search optimization. */ export declare const VectorIndexInfoSchema: z.ZodObject<{ hasIndex: z.ZodBoolean; indexType: z.ZodOptional>; numPartitions: z.ZodOptional; numSubVectors: z.ZodOptional; distanceType: z.ZodOptional>; indexCreationTimeMs: z.ZodOptional; chunkCount: z.ZodOptional; createdAt: z.ZodOptional; }, z.core.$strip>; /** * Inferred VectorIndexInfo type from the schema */ export type VectorIndexInfoMeta = z.infer; /** * Zod schema for metadata validation * * Validates metadata with required fields for version, project path, and timestamps. */ export declare const MetadataSchema: z.ZodObject<{ version: z.ZodString; projectPath: z.ZodString; createdAt: z.ZodString; lastFullIndex: z.ZodString; lastIncrementalUpdate: z.ZodOptional; stats: z.ZodObject<{ totalFiles: z.ZodNumber; totalChunks: z.ZodNumber; storageSizeBytes: z.ZodNumber; failedEmbeddings: z.ZodOptional; }, z.core.$strip>; docsStats: z.ZodOptional>; lastDocsIndex: z.ZodOptional; indexingState: z.ZodOptional; startedAt: z.ZodOptional; lastCheckpoint: z.ZodOptional; expectedFiles: z.ZodOptional; processedFiles: z.ZodOptional; errorMessage: z.ZodOptional; }, z.core.$strip>>; hybridSearch: z.ZodOptional>; ftsEngineReason: z.ZodOptional; defaultAlpha: z.ZodOptional; ftsChunkCount: z.ZodOptional; }, z.core.$strip>>; embeddingModels: z.ZodOptional; codeModelDimension: z.ZodOptional; docsModelName: z.ZodOptional; docsModelDimension: z.ZodOptional; }, z.core.$strip>>; vectorIndex: z.ZodOptional>; numPartitions: z.ZodOptional; numSubVectors: z.ZodOptional; distanceType: z.ZodOptional>; indexCreationTimeMs: z.ZodOptional; chunkCount: z.ZodOptional; createdAt: z.ZodOptional; }, z.core.$strip>>; }, z.core.$strip>; /** * Inferred Metadata type from the schema */ export type Metadata = z.infer; /** * Inferred Stats type from the schema */ export type Stats = z.infer; /** * Inferred DocsStats type from the schema */ export type DocsStats = z.infer; /** * Inferred IndexingStateInfo type from the schema */ export type IndexingStateInfo = z.infer; /** * Load metadata from an index path * * Loads metadata.json from the index directory. * * @param indexPath - Absolute path to the index directory * @returns Metadata object or null if file doesn't exist * @throws MCPError if metadata is corrupt or unreadable * * @example * ```typescript * const metadata = await loadMetadata('/home/user/.mcp/search/indexes/abc123'); * if (metadata) { * console.log(metadata.stats.totalFiles); * } * ``` */ export declare function loadMetadata(indexPath: string): Promise; /** * Save metadata to an index path * * Saves the metadata to metadata.json with atomic write (temp + rename). * This prevents partial writes on crash. * * @param indexPath - Absolute path to the index directory * @param metadata - Metadata to save * * @example * ```typescript * await saveMetadata('/path/to/index', metadata); * ``` */ export declare function saveMetadata(indexPath: string, metadata: Metadata): Promise; /** * Create initial metadata for a new index * * Creates metadata with: * - Current version * - Current timestamp for createdAt and lastFullIndex * - Zero stats * * @param projectPath - Absolute path to the project root * @returns Initial metadata object * * @example * ```typescript * const metadata = createMetadata('/Users/dev/my-project'); * await saveMetadata(indexPath, metadata); * ``` */ export declare function createMetadata(projectPath: string): Metadata; /** * Metadata Manager class for managing index metadata * * Provides: * - Loading and caching metadata * - Saving metadata changes with atomic writes * - Updating statistics * - Marking index operations * * @example * ```typescript * const manager = new MetadataManager('/path/to/index'); * await manager.load(); * * // Update stats after indexing * manager.updateStats(100, 500, 1024000); * manager.markFullIndex(); * await manager.save(); * ``` */ export declare class MetadataManager { private readonly indexPath; private cachedMetadata; private lastLoadedAt; /** * Create a new MetadataManager instance * * @param indexPath - Absolute path to the index directory */ constructor(indexPath: string); /** * Load metadata from disk * * Always reads from disk, updating the cache. * * @returns Metadata object or null if no metadata exists * @throws MCPError if metadata is corrupt */ load(): Promise; /** * Save metadata to disk * * Updates both disk and cache with atomic write. * Throws if no metadata is loaded. */ save(): Promise; /** * Check if metadata file exists * * @returns true if metadata.json exists in the index directory */ exists(): Promise; /** * Initialize metadata for a new index * * Creates initial metadata and caches it, but does NOT save to disk. * Call save() to persist. * * @param projectPath - Absolute path to the project root */ initialize(projectPath: string): void; /** * Update index statistics * * Updates the stats in the cached metadata. * Call save() to persist changes. * * @param files - Total number of indexed files * @param chunks - Total number of chunks * @param sizeBytes - Total storage size in bytes */ updateStats(files: number, chunks: number, sizeBytes: number): void; /** * Mark a full index operation * * Updates the lastFullIndex timestamp to now. * Call save() to persist changes. */ markFullIndex(): void; /** * Mark an incremental update operation * * Updates the lastIncrementalUpdate timestamp to now. * Call save() to persist changes. */ markIncrementalUpdate(): void; /** * Get cached metadata * * Returns cached metadata if available. * Use this for synchronous access after initial load. * * @returns Cached metadata or null if not loaded */ getMetadata(): Metadata | null; /** * Check if metadata has been loaded */ isLoaded(): boolean; /** * Get the timestamp of the last load operation */ getLastLoadedAt(): number; /** * Get the path to the metadata file */ getMetadataPath(): string; /** * Get the index path this manager is associated with */ getIndexPath(): string; /** * Get the project path from metadata * * Convenience method to get the project path. * * @returns Project path or null if metadata not loaded */ getProjectPath(): string | null; /** * Get the stats from metadata * * Convenience method to get statistics. * * @returns Stats object or null if metadata not loaded */ getStats(): Stats | null; /** * Get the version from metadata * * @returns Version string or null if metadata not loaded */ getVersion(): string | null; /** * Update documentation index statistics * * Updates the docsStats in the cached metadata. * Call save() to persist changes. * * @param docs - Total number of indexed documentation files * @param chunks - Total number of documentation chunks * @param sizeBytes - Total storage size in bytes for docs index */ updateDocsStats(docs: number, chunks: number, sizeBytes: number): void; /** * Mark a documentation index operation * * Updates the lastDocsIndex timestamp to now. * Call save() to persist changes. */ markDocsIndex(): void; /** * Get the documentation stats from metadata * * Convenience method to get documentation statistics. * * @returns DocsStats object or null if metadata not loaded or no docs stats */ getDocsStats(): DocsStats | null; /** * Set the indexing state to in_progress * * Call this at the start of indexing operations. * Call save() to persist changes. * * @param expectedFiles - Total number of files to be indexed (optional) */ setIndexingInProgress(expectedFiles?: number): void; /** * Update indexing progress * * Call this periodically during indexing to track progress. * Call save() to persist changes. * * @param processedFiles - Number of files processed so far */ updateIndexingProgress(processedFiles: number): void; /** * Set the indexing state to complete * * Call this when indexing finishes successfully. * Call save() to persist changes. */ setIndexingComplete(): void; /** * Set the indexing state to failed * * Call this when indexing fails. * Call save() to persist changes. * * @param errorMessage - Description of the failure (optional) */ setIndexingFailed(errorMessage?: string): void; /** * Get the current indexing state * * @returns IndexingStateInfo object or null if metadata not loaded or no state */ getIndexingState(): IndexingStateInfo | null; /** * Check if the index is in a complete state * * @returns true if the indexing state is 'complete' or undefined (legacy indexes) */ isIndexComplete(): boolean; /** * Check if indexing is currently in progress * * @returns true if the indexing state is 'in_progress' */ isIndexingInProgress(): boolean; /** * Update the failed embeddings count * * @param count - Number of failed embeddings */ updateFailedEmbeddings(count: number): void; /** * Update hybrid search / FTS information * * @param info - Hybrid search info to set */ updateHybridSearchInfo(info: HybridSearchInfo): void; /** * Get the hybrid search / FTS information * * @returns HybridSearchInfo object or null if metadata not loaded or no info */ getHybridSearchInfo(): HybridSearchInfo | null; /** * Check if hybrid search is enabled for this index * * @returns true if hybrid search is enabled and FTS engine is available */ isHybridSearchEnabled(): boolean; /** * Update the FTS chunk count * * @param count - Number of chunks in the FTS index */ updateFTSChunkCount(count: number): void; /** * Update the embedding model information * * @param info - Embedding model info to set */ updateEmbeddingModelInfo(info: EmbeddingModelInfo): void; /** * Update the code model information * * @param modelName - Name of the code embedding model * @param dimension - Dimension of the code embedding vectors */ updateCodeModelInfo(modelName: string, dimension: number): void; /** * Update the docs model information * * @param modelName - Name of the docs embedding model * @param dimension - Dimension of the docs embedding vectors */ updateDocsModelInfo(modelName: string, dimension: number): void; /** * Get the embedding model information * * @returns EmbeddingModelInfo object or null if metadata not loaded or no info */ getEmbeddingModelInfo(): EmbeddingModelInfo | null; /** * Get the code model name * * @returns Code model name or null if not set */ getCodeModelName(): string | null; /** * Get the code model dimension * * @returns Code model dimension or null if not set */ getCodeModelDimension(): number | null; /** * Get the docs model name * * @returns Docs model name or null if not set */ getDocsModelName(): string | null; /** * Get the docs model dimension * * @returns Docs model dimension or null if not set */ getDocsModelDimension(): number | null; /** * Update the vector index information * * @param info - Vector index info to set */ updateVectorIndexInfo(info: VectorIndexInfoMeta): void; /** * Get the vector index information * * @returns VectorIndexInfo object or null if metadata not loaded or no info */ getVectorIndexInfo(): VectorIndexInfoMeta | null; /** * Check if a vector index exists * * @returns true if a vector index has been created */ hasVectorIndex(): boolean; } //# sourceMappingURL=metadata.d.ts.map