You can save and reuse values from one Pipeline invocation to another. This lets you create complex Pipelines that change according to the results of previous runs. Check out the Chatbot example for an interactive example.
Memory Manager
To enable Pipeline Memory you first need to define your Memory Manager when creating the Aigur Client instance.
Here is an example of using Upstash Redis (opens in a new tab) as your Memory Manager.
Current available Memory Managers
@aigur/memory-upstash-redis
- Uses Upstash Redis (opens in a new tab) to manage your persistent memory. Looks for theUPSTASH_REDIS_REST_TOKEN
andUPSTASH_REDIS_REST_URL
environment variables.- More to come soon...
Define Your Memory Data Type
The aigur.pipeline.create
function accepts an optional third generic type parameter that defines the type of your memory data. This is the data that will be saved and loaded between Pipeline invocations.
Consume Memory Data
When configuring the input of a Node using the Input Function
(the second parameter of the flow.node
function), you can access the memory data by using the memory
parameter.
Saving Memory Data
To save memory data, the flow.node
function accepts an optional third parameter that is a function that returns an object which is the memory data to save.
It can be partial data of the type you defined in the Pipeline creation.
The memory update function receives 5 parameters:
input
- The input data of the Nodeoutput
- The output data of the Node (even if it's a Stream node)nodes
- The Nodes of the Pipeline that were executed before the current Nodeprev
- The output of the immediate previous Nodememory
- The current memory data
In order to save the memory data for a specific User you need to invoke the Pipeline with the userId parameter:
const { output } = await myPipeline.invoke({ someParameter: someValue}, { userId: someUserId });