ConversationBufferWindowMemory

Open in ColabOpen in GitHub

Overview

This tutorial introduces ConversationBufferWindowMemory, which maintains a sliding window of recent conversation interactions over time.

Instead of utilizing all conversation content, ConversationBufferWindowMemory retains only the most recent K interactions.

This prevents the memory buffer from growing too large.

Table of Contents

References


Environment Setup

Set up the environment. You may refer to Environment Setup for more details.

[Note]

  • langchain-opentutorial is a package that provides a set of easy-to-use environment setup, useful functions and utilities for tutorials.

  • You can checkout the langchain-opentutorial for more details.

You can alternatively set OPENAI_API_KEY in .env file and load it.

[Note] This is not necessary if you've already set OPENAI_API_KEY in previous steps.

Online Bank Account Opening Conversation Example

This example demonstrates using ConversationBufferWindowMemory to simulate a virtual banking assistant conversation. The flow covers a typical online bank account opening process, from initial greeting to account creation confirmation, retaining only the most recent interactions in memory.

Retrieving Conversation History

Let's examine the stored conversation history using the load_memory_variables() method to verify our window-based memory retention.

Last updated