Skip to content

before_cat_stores_episodic_memory

Intervene before the Cat stores episodic memories.

Allows intercepting the user message Document before is inserted in the vector memory.

The Document can then be edited and enhanced before the Cat stores it in the episodic vector memory.

📄 Arguments

Name Type Description
doc Document Langchain Document to be inserted in memory.
cat StrayCat Cheshire Cat instance, allows you to use the framework components.

The Document has two properties:

  • page_content: the string with the text to save in memory;
  • metadata: a dictionary with at least two keys:
    • source: where the text comes from;
    • when: timestamp to track when it's been uploaded.

â†Šī¸ Return

Type: Document

Langchain Document that is added in the episodic vector memory.

✍ Example

from cat.mad_hatter.decorators import hook

@hook  # default priority = 1
def before_cat_stores_episodic_memory(doc, cat):
    if doc.metadata["source"] == "dolphin":
        doc.metadata["final_answer"] = 42
    return doc