Interface IMemoryInstance

Interface for memory instance implementations. Defines the contract for local, persist, and dummy backends.

interface IMemoryInstance {
    dispose(): void;
    listMemory<T extends object = object>(
        when: Date,
    ): Promise<{ content: T; memoryId: string }[]>;
    readMemory<T extends object = object>(
        memoryId: string,
        when: Date,
    ): Promise<T>;
    removeMemory(memoryId: string, when: Date): Promise<void>;
    searchMemory<T extends object = object>(
        query: string,
        when: Date,
        settings?: SearchSettings,
    ): Promise<{ content: T; memoryId: string; score: number }[]>;
    waitForInit(initial: boolean): Promise<void>;
    writeMemory<T extends object = object>(
        memoryId: string,
        value: T,
        description: string,
        when: Date,
    ): Promise<void>;
}

Methods

  • Releases any resources held by this instance.

    Returns void

  • List all entries in memory. Filters out entries whose when is greater than the requested when.

    Type Parameters

    • T extends object = object

    Parameters

    • when: Date

      Logical timestamp at which the read is happening (look-ahead guard)

    Returns Promise<{ content: T; memoryId: string }[]>

    Array of all stored entries

  • Read a single entry from memory. Behaves as not-found if the stored when is greater than the requested when.

    Type Parameters

    • T extends object = object

    Parameters

    • memoryId: string

      Unique entry identifier

    • when: Date

      Logical timestamp at which the read is happening (look-ahead guard)

    Returns Promise<T>

    Entry value

    Error if entry not found (or shadowed by look-ahead)

  • Remove an entry from memory.

    Parameters

    • memoryId: string

      Unique entry identifier

    • when: Date

      Logical timestamp (kept for API consistency; removal is by UUID)

    Returns Promise<void>

  • Search memory using BM25 full-text scoring. Filters out entries whose when is greater than the requested when.

    Type Parameters

    • T extends object = object

    Parameters

    • query: string

      Search query string

    • when: Date

      Logical timestamp at which the read is happening (look-ahead guard)

    • Optionalsettings: SearchSettings

    Returns Promise<{ content: T; memoryId: string; score: number }[]>

    Array of matching entries with scores

  • Initialize the memory instance.

    Parameters

    • initial: boolean

      Whether this is the first initialization

    Returns Promise<void>

  • Write a value to memory.

    Type Parameters

    • T extends object = object

    Parameters

    • memoryId: string

      Unique entry identifier

    • value: T

      Value to store

    • description: string

      Optional BM25 index string; defaults to JSON.stringify(value)

    • when: Date

      Logical timestamp this entry belongs to (look-ahead guard)

    Returns Promise<void>