Skip to content

before_rabbithole_insert_memory

Intervene before the RabbitHole insert a Document in the declarative memory.

Allows editing and enhancing a single Document before the RabbitHole add it to the declarative vector memory.

Example of the Langchain document:

doc = Document(page_content="So Long, and Thanks for All the Fish", metadata={})

📄 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.

Info

Before adding the doc, the Cat will add source and when metadata with the file name and ingestion time.

â†Šī¸ Return

Type: Document

Langchain Document that is added in the declarative vector memory.

✍ Example

from cat.mad_hatter.decorators import hook

@hook  # default priority = 1
def before_rabbithole_insert_memory(doc, cat):
    # insert the user id metadata
    doc.metadata["user_id"] = cat.user_id

    return doc