From 243a5f65f4879975b56f23d77a493b06ddad79d5 Mon Sep 17 00:00:00 2001 From: David Snelling Date: Fri, 20 Jun 2025 10:57:39 -0700 Subject: [PATCH] **feat: add importSparseData method to handle sparse data operations** ### Changes: - Introduced the `importSparseData` method in `src/brainyData.ts` to allow importing sparse data into the database. - Supports embedding generation for nouns if vectors are missing. - Includes options to clear existing data during import. - Returns counts of imported nouns and verbs for tracking. ### Purpose: Added a new method to manage sparse data imports, improving functionality and ensuring alignment with updated terminology across the application. This addition enhances flexibility in handling database operations. --- src/brainyData.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/brainyData.ts b/src/brainyData.ts index 268d4137..623716c6 100644 --- a/src/brainyData.ts +++ b/src/brainyData.ts @@ -1631,6 +1631,38 @@ export class BrainyData implements BrainyDataInterface { } } + /** + * Import sparse data into the database + * @param data The sparse data to import + * If vectors are not present for nouns, they will be created using the embedding function + * @param options Import options + * @returns Object containing counts of imported items + */ + public async importSparseData( + data: { + nouns: VectorDocument[] + verbs: GraphVerb[] + nounTypes?: string[] + verbTypes?: string[] + hnswIndex?: { + entryPointId: string | null + maxLevel: number + dimension: number | null + config: HNSWConfig + connections: Record> + } + version: string + }, + options: { + clearExisting?: boolean + } = {} + ): Promise<{ + nounsRestored: number + verbsRestored: number + }> { + return this.restore(data, options); + } + /** * Restore data into the database from a previously backed up format * @param data The data to restore, in the format returned by backup()