UNPKG

askexperts

Version:

AskExperts SDK: build and use AI experts - ask them questions and pay with bitcoin on an open protocol

118 lines (117 loc) 4.79 kB
import { Doc, DocStore, Subscription } from "./interfaces.js"; /** * SQLite implementation */ export declare class DocStoreSQLite { private db; private readonly BATCH_SIZE; private readonly RETRY_INTERVAL_MS; /** * Creates a new DocStoreSQLite instance * @param dbPath - Path to the SQLite database file */ constructor(dbPath: string); /** * Initialize the database by creating required tables if they don't exist */ private initDatabase; /** * Subscribe to documents in a docstore with batched queries * @param docstore_id - ID of the docstore to subscribe to * @param type - Type of documents to filter by * @param since - Start timestamp for filtering documents * @param until - End timestamp for filtering documents * @param onDoc - Callback function to handle each document * @returns Subscription object to manage the subscription */ subscribe(options: { docstore_id: string; type?: string; since?: number; until?: number; user_id?: string; }, onDoc: (doc?: Doc) => Promise<void>): Promise<Subscription>; /** * Upsert a document in the store using a single atomic operation * @param doc - Document to upsert */ /** * Convert Float32Array[] to a single Uint8Array for storage * @param embeddings - Array of Float32Array embeddings * @param vectorSize - Size of each embedding vector * @returns Uint8Array containing all embeddings */ private float32ArraysToBlob; /** * Convert a Uint8Array blob back to an array of Float32Array embeddings * @param blob - Uint8Array blob containing embeddings * @param docstore_id - ID of the docstore the blob belongs to * @returns Array of Float32Array embeddings */ private blobToFloat32Arrays; /** * Get a docstore by ID * @param id - ID of the docstore to get * @returns The docstore if found, null otherwise */ getDocstoreSync(id: string, user_id?: string): DocStore | undefined; getDocstore(id: string, user_id?: string): Promise<DocStore | undefined>; upsert(doc: Doc, user_id?: string): Promise<void>; /** * Get a document by ID * @param docstore_id - ID of the docstore containing the document * @param doc_id - ID of the document to get * @returns The document if found, null otherwise */ get(docstore_id: string, doc_id: string, user_id?: string): Promise<Doc | null>; /** * Delete a document from the store * @param docstore_id - ID of the docstore containing the document * @param doc_id - ID of the document to delete * @returns true if document existed and was deleted, false otherwise */ delete(docstore_id: string, doc_id: string, user_id?: string): Promise<boolean>; /** * Create a new docstore if one with the given name doesn't exist * @param name - Name of the docstore to create * @param model - Name of the embeddings model * @param vector_size - Size of embedding vectors * @param options - Options for the model, defaults to empty string * @returns Promise that resolves with the ID of the created or existing docstore */ createDocstore(name: string, model?: string, vector_size?: number, options?: string, user_id?: string): Promise<string>; /** * List all docstores * @returns Promise that resolves with an array of docstore objects */ listDocstores(user_id?: string): Promise<DocStore[]>; /** * List docstores by specific IDs * @param ids - Array of docstore IDs to retrieve * @returns Promise that resolves with an array of docstore objects */ listDocStoresByIds(ids: string[], user_id?: string): Promise<DocStore[]>; /** * List documents by specific IDs * @param docstore_id - ID of the docstore containing the documents * @param ids - Array of document IDs to retrieve * @returns Promise that resolves with an array of document objects */ listDocsByIds(docstore_id: string, ids: string[]): Promise<Doc[]>; /** * Delete a docstore and all its documents * @param id - ID of the docstore to delete * @returns Promise that resolves with true if docstore existed and was deleted, false otherwise */ deleteDocstore(id: string, user_id?: string): Promise<boolean>; /** * Count documents in a docstore * @param docstore_id - ID of the docstore to count documents for * @returns Promise that resolves with the number of documents in the docstore */ countDocs(docstore_id: string, user_id?: string): Promise<number>; /** * Symbol.dispose method for releasing resources */ [Symbol.dispose](): void; }