Imports a JsonExporter-compatible JSON file into a Brain.

Usage:

const importer = new JsonImporter(brain);
const result = await importer.import('/path/to/export.json');
console.log(result.imported, result.skipped, result.errors);

Constructors

Methods

Constructors

Methods

  • Read and merge a JSON export file into the target brain.

    Validation:

    • The file must be valid JSON.
    • The top-level object must contain a traces array.

    Deduplication:

    • For memory_traces: inside the trace's scope and scope id, a row whose content is the record's, or whose metadata names the SHA-256 of that text as import_hash or content_hash, makes the record a duplicate, and it is skipped; a row of another scope id is not a duplicate.
    • For knowledge_nodes: SHA-256 of label + type. A memory-graph node (type memory_graph) is its trace's node instead: it is written under its trace's id for a trace the import wrote or matched under that id, is the duplicate of the node the brain holds under that id, or is skipped (see memoryGraphNodeImport).
    • For knowledge_edges: SHA-256 of source_id + target_id + type. An edge that names a memory-graph node the import skipped is skipped.

    Parameters

    • sourcePath: string

      Absolute path to the JSON file to import.

    • Optional options: Pick<ImportOptions, "dedup">

    Returns Promise<ImportResult>

    ImportResult with counts of imported, skipped, and errored items.

  • Import a JSON string directly into the target brain without filesystem access.

    Parameters

    • jsonContent: string

      The JSON string to parse and import.

    • Optional options: Pick<ImportOptions, "dedup">

    Returns Promise<ImportResult>

    ImportResult with counts of imported, skipped, and errored items.