VectorStoreRetrieverMemory
Author: Harheem Kim
Peer Review:
Proofread : Juni Lee
This is a part of LangChain Open Tutorial
Overview
VectorStoreRetrieverMemory stores memory in a vector store and queries the top-K most 'relevant' documents whenever called.
This differs from most of the other memory classes in that it does not explicitly track the order of conversation.
In this tutorial, we'll explore the practical application of VectorStoreRetrieverMemory through a simulated interview scenario. Through this example, we'll see how VectorStoreRetrieverMemory searches for information based on semantic relevance rather than chronological order of conversations.
Table of Contents
References
Environment Setup
Set up the environment. You may refer to Environment Setup for more details.
[Note]
langchain-opentutorialis a package that provides a set of easy-to-use environment setup, useful functions and utilities for tutorials.You can checkout the
langchain-opentutorialfor 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.
Initializing the Vector Store
Next, we'll set up our vector store using FAISS. FAISS is an efficient similarity search library that will help us store and retrieve conversation embeddings:
This setup creates an in-memory vector store that will maintain our conversation embeddings for quick similarity searches.
Saving Interview Conversations
Now, we'll create our memory system and populate it with example interview conversations.
Note that by setting k=1, we ensure that only the single most relevant conversation is returned. (In real applications, you might want to increase this value to provide more context.):
Retrieving Relevant Conversations
Let's see how the system retrieves relevant information based on queries:
This approach is particularly valuable when building systems that need to reference past conversations contextually, such as in customer service bots, educational assistants, or any application where maintaining context-aware conversation history is important.
Last updated