langchain.js
    Preparing search index...

    Class used to manage the memory of a chat session using the Mem0 service. It handles loading and saving chat history, and provides methods to format the memory content for use in chat models.

    const memory = new Mem0Memory({
    sessionId: "user123" // or use user_id inside of memoryOptions (recommended),
    apiKey: "your-api-key",
    memoryOptions: {
    user_id: "user123",
    run_id: "run123"
    },
    });

    // Use with a chat model
    const model = new ChatOpenAI({
    model: "gpt-3.5-turbo",
    temperature: 0,
    });

    const chain = new ConversationChain({ llm: model, memory });

    Hierarchy

    • BaseChatMemory
      • Mem0Memory

    Implements

    Index

    Constructors

    Properties

    aiPrefix: string = "AI"
    apiKey: string
    humanPrefix: string = "Human"
    mem0Client: MemoryClient
    mem0Options: ClientOptions
    memoryKey: string = "history"
    memoryOptions: MemoryOptions | SearchOptions
    separateMessages?: boolean
    sessionId: string

    Accessors

    • get memoryKeys(): string[]

      Returns string[]

    Methods

    • Clears all memories for the current session

      Returns Promise<void>

      Promise resolving when memories have been cleared

    • Retrieves memories from the Mem0 service and formats them for use

      Parameters

      • values: InputValues

        Input values containing optional search query

      Returns Promise<MemoryVariables>

      Promise resolving to formatted memory variables

    • Saves the current conversation context to the Mem0 service

      Parameters

      • inputValues: InputValues

        Input messages to be saved

      • outputValues: OutputValues

        Output messages to be saved

      Returns Promise<void>

      Promise resolving when the context has been saved