langchain.js
    Preparing search index...

    Class EntityMemory

    Class for managing entity extraction and summarization to memory in chatbot applications. Extends the BaseChatMemory class and implements the EntityMemoryInput interface.

    const memory = new EntityMemory({
    llm: new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0 }),
    chatHistoryKey: "history",
    entitiesKey: "entities",
    });
    const model = new ChatOpenAI({ model: "gpt-4o-mini", temperature: 0.9 });
    const chain = new LLMChain({
    llm: model,
    prompt: ENTITY_MEMORY_CONVERSATION_TEMPLATE,
    memory,
    });

    const res1 = await chain.call({ input: "Hi! I'm Jim." });
    console.log({
    res1,
    memory: await memory.loadMemoryVariables({ input: "Who is Jim?" }),
    });

    const res2 = await chain.call({
    input: "I work in construction. What about you?",
    });
    console.log({
    res2,
    memory: await memory.loadMemoryVariables({ input: "Who is Jim?" }),
    });

    Hierarchy (View Summary)

    Implements

    • EntityMemoryInput
    Index

    Constructors

    Properties

    aiPrefix?: string
    chatHistory: BaseChatMessageHistory
    chatHistoryKey: string = "history"
    entitiesKey: string = "entities"
    entityCache: string[] = []
    entityStore: BaseEntityStore
    humanPrefix?: string
    inputKey?: string
    k: number = 3
    llm: BaseLanguageModelInterface
    outputKey?: string
    returnMessages: boolean = false

    Accessors

    • get memoryKeys(): string[]

      Returns string[]

    • get memoryVariables(): string[]

      Returns string[]

    Methods

    • Method to clear the memory contents.

      Returns Promise<void>

      Promise resolving to void.

    • Method to load memory variables and perform entity extraction.

      Parameters

      • inputs: InputValues

        Input values for the method.

      Returns Promise<MemoryVariables>

      Promise resolving to an object containing memory variables.

    • Method to save the context from a conversation to a buffer and perform entity summarization.

      Parameters

      • inputs: InputValues

        Input values for the method.

      • outputs: OutputValues

        Output values from the method.

      Returns Promise<void>

      Promise resolving to void.