**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.
This commit is contained in:
parent
c641467854
commit
243a5f65f4
1 changed files with 32 additions and 0 deletions
|
|
@ -1631,6 +1631,38 @@ export class BrainyData<T = any> implements BrainyDataInterface<T> {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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<T>[]
|
||||
verbs: GraphVerb[]
|
||||
nounTypes?: string[]
|
||||
verbTypes?: string[]
|
||||
hnswIndex?: {
|
||||
entryPointId: string | null
|
||||
maxLevel: number
|
||||
dimension: number | null
|
||||
config: HNSWConfig
|
||||
connections: Record<string, Record<string, string[]>>
|
||||
}
|
||||
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()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue