import type { LoggerInterface } from '@qvac/logging'; import type { Corestore, Hypercore, HyperDBInstance, HyperDBReader, HyperDBTransaction } from './db-types.js'; import { type LRUCache } from '../../utils/helper.js'; import type { EmbeddedDoc, HyperDBAdapterConfig, SaveEmbeddingsOpts, SaveEmbeddingsResult } from '../../types.js'; export declare const UPSERT_MUTATION_OPERATION = "upsert"; export declare const DELETE_MUTATION_OPERATION = "delete"; export type WorkspaceMutationOperation = typeof UPSERT_MUTATION_OPERATION | typeof DELETE_MUTATION_OPERATION; export interface HyperDBStorageInput { store?: object; db?: HyperDBInstance; dbName?: string; BATCH_SIZE?: number; PROGRESS_INTERVAL?: number; CACHE_SIZE?: number; documentsTable?: string; vectorsTable?: string; configTable?: string; workspaceStateTable?: string; mutationsTable?: string; logger?: LoggerInterface; } export type StoredAdapterConfig = Pick; export interface PreparedDocument { id: string; vector: number[]; content: string; contentHash: string; metadata: Record; embeddingModelId: string; dimension: number; } export interface VectorRecord { docId: string; vector: number[]; } export interface DocumentRecord { id: string; content: string; } export interface WorkspaceStateRecord { key: string; revision: number; updatedAt: Date; } export interface MutationRecord { revision: number; operation: WorkspaceMutationOperation; documentIds: string[]; createdAt: Date; } export interface SavePipelineHooks { prepare?(doc: EmbeddedDoc, contentHash: string): TDoc; write(tx: HyperDBTransaction, docs: TDoc[], now: Date): Promise; beforeFlush?(): void | Promise; committed?(docs: TDoc[], writeResult: TWrite, revision: number): void | Promise; } export interface DeletePipelineHooks { write?(tx: HyperDBTransaction, ids: string[], now: Date): Promise; beforeFlush?(): void | Promise; committed?(ids: string[], writeResult: TWrite, revision: number): void | Promise; } export declare class HyperDBStorage { store: Corestore | null; db: HyperDBInstance | null; readonly dbName: string; readonly BATCH_SIZE: number; readonly PROGRESS_INTERVAL: number; readonly CACHE_SIZE: number; readonly documentsTable: string; readonly vectorsTable: string; readonly configTable: string; readonly workspaceStateTable: string; readonly mutationsTable: string; readonly logger: LoggerInterface; readonly documentCache: LRUCache; readonly vectorCache: LRUCache; hypercore: Hypercore | null; private workspaceKey; constructor(config?: HyperDBStorageInput); open(): Promise; close(): Promise; withSnapshot(operation: (snapshot: HyperDBReader) => Promise): Promise; getConfig(): Promise; readConfig(snapshot: HyperDBReader): Promise; ensureConfig(embeddingModelId: string, dimension: number, adapterConfig: StoredAdapterConfig): Promise; validateEmbeddingBatch(embeddedDocs: EmbeddedDoc[]): { embeddingModelId: string; dimension: number; } | null; prepareDocument(doc: EmbeddedDoc, contentHash: string): PreparedDocument; saveEmbeddings(embeddedDocs: EmbeddedDoc[], opts: SaveEmbeddingsOpts, hooks: SavePipelineHooks): Promise; deleteEmbeddings(ids: string[], hooks?: DeletePipelineHooks): Promise; private _withWorkspaceWriteLock; deleteDocumentsAndVectors(tx: HyperDBTransaction, ids: string[]): Promise; readCurrentRevision(reader: HyperDBReader): Promise; evictDocuments(ids: string[]): void; clearCaches(): void; findEntries(snapshot: HyperDBReader, table: string, query?: object): Promise; getVectors(snapshot: HyperDBReader, docIds: string[]): Promise>; getDocumentContents(snapshot: HyperDBReader, ids: string[]): Promise>; private appendMutation; private insertDocumentsAndVectors; private cacheDocuments; private _getCached; private filterDuplicates; private _persistConfig; private _filterDuplicatesFromSnapshot; }