Class for storing and retrieving chat message history from a Cloudflare D1 database. Extends the BaseListChatMessageHistory class.
const memory = new BufferMemory({ returnMessages: true, chatHistory: new CloudflareD1MessageHistory({ tableName: "stored_message", sessionId: "example", database: env.DB, }),});const chainInput = { input };const res = await memory.chatHistory.invoke(chainInput);await memory.saveContext(chainInput, { output: res,}); Copy
const memory = new BufferMemory({ returnMessages: true, chatHistory: new CloudflareD1MessageHistory({ tableName: "stored_message", sessionId: "example", database: env.DB, }),});const chainInput = { input };const res = await memory.chatHistory.invoke(chainInput);await memory.saveContext(chainInput, { output: res,});
Method to add a new message to the Cloudflare D1 database for the current session.
The BaseMessage object to be added to the database.
Promise that resolves to void.
Method to delete all messages from the Cloudflare D1 database for the current session.
Method to retrieve all messages from the Cloudflare D1 database for the current session.
Promise that resolves to an array of BaseMessage objects.
Class for storing and retrieving chat message history from a Cloudflare D1 database. Extends the BaseListChatMessageHistory class.
Example