Imports a JsonExporter-compatible JSON file into a SqliteBrain.

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: SHA-256 of content is used as the dedup key. Existing rows with the same hash are skipped.
    • For knowledge_nodes: SHA-256 of label + type.
    • For knowledge_edges: SHA-256 of source_id + target_id + type.

    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.