Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a conversation memory that combines a (optionally persistent) vectorstore history with a token buffer #22155

Merged
merged 12 commits into from
Jun 26, 2024

Conversation

lstein
Copy link
Contributor

@lstein lstein commented May 25, 2024

langchain: ConversationVectorStoreTokenBufferMemory

-Description: This PR adds ConversationVectorStoreTokenBufferMemory. It is similar in concept to ConversationSummaryBufferMemory. It maintains an in-memory buffer of messages up to a preset token limit. After the limit is hit timestamped messages are written into a vectorstore retriever rather than into a summary. The user's prompt is then used to retrieve relevant fragments of the previous conversation. By persisting the vectorstore, one can maintain memory from session to session.
-Issue: n/a
-Dependencies: none
-Twitter handle: Please no!!!

  • Add tests and docs: I looked to see how the unit tests were written for the other ConversationMemory modules, but couldn't find anything other than a test for successful import. I need to know whether you are using pytest.mock or another fixture to simulate the LLM and vectorstore. In addition, I would like guidance on where to place the documentation. Should it be a notebook file in docs/docs?

  • Lint and test: I am seeing some linting errors from a couple of modules unrelated to this PR.

If no one reviews your PR within a few days, please @-mention one of baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.

Copy link

vercel bot commented May 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Jun 22, 2024 0:22am

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. Ɑ: memory Related to memory module Ɑ: vector store Related to vector store module 🤖:improvement Medium size change to existing code to handle new use-cases labels May 25, 2024
@lstein lstein requested a review from isahers1 June 14, 2024 15:39
@lstein
Copy link
Contributor Author

lstein commented Jun 14, 2024

BTW, I'm using this routinely with persistence in my personal chatbots and am constantly amazed at how frequently the chatbot recalls something relevant from a previous conversation. For small (7b) local models, this really works much better than the conversation summary chain.

I think a maintainer needs to approve the required workflows?

@lstein lstein force-pushed the conversation_memory_vectorstore branch from f1e65aa to ba23101 Compare June 14, 2024 18:18
Copy link

vercel bot commented Jun 18, 2024

Deployment failed with the following error:

The provided GitHub repository does not contain the requested branch or commit reference. Please ensure the repository is not empty.

@lstein
Copy link
Contributor Author

lstein commented Jun 18, 2024

The memory/test_imports.py unit test was failing due to a circular import issue. I have fixed by changing the import order.

@ccurme ccurme added the langchain Related to the langchain package label Jun 21, 2024
@lstein
Copy link
Contributor Author

lstein commented Jun 23, 2024

@isahers1 All tests are passing, documentation looks good. At what point does this get merged with the main branch — or is more needed to be done?

@isahers1 isahers1 merged commit c314222 into langchain-ai:master Jun 26, 2024
73 checks passed
@isahers1
Copy link
Collaborator

Just merged, sorry for the delay!

@lstein lstein deleted the conversation_memory_vectorstore branch June 26, 2024 03:38
hinthornw pushed a commit that referenced this pull request Jul 3, 2024
…torstore history with a token buffer (#22155)

**langchain: ConversationVectorStoreTokenBufferMemory**

-**Description:** This PR adds ConversationVectorStoreTokenBufferMemory.
It is similar in concept to ConversationSummaryBufferMemory. It
maintains an in-memory buffer of messages up to a preset token limit.
After the limit is hit timestamped messages are written into a
vectorstore retriever rather than into a summary. The user's prompt is
then used to retrieve relevant fragments of the previous conversation.
By persisting the vectorstore, one can maintain memory from session to
session.
-**Issue:** n/a
-**Dependencies:** none
-**Twitter handle:** Please no!!!
- [X] **Add tests and docs**: I looked to see how the unit tests were
written for the other ConversationMemory modules, but couldn't find
anything other than a test for successful import. I need to know whether
you are using pytest.mock or another fixture to simulate the LLM and
vectorstore. In addition, I would like guidance on where to place the
documentation. Should it be a notebook file in docs/docs?

- [X] **Lint and test**: I am seeing some linting errors from a couple
of modules unrelated to this PR.

If no one reviews your PR within a few days, please @-mention one of
baskaryan, efriis, eyurtsev, ccurme, vbarda, hwchase17.

---------

Co-authored-by: Lincoln Stein <lstein@gmail.com>
Co-authored-by: isaac hershenson <ihershenson@hmc.edu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:improvement Medium size change to existing code to handle new use-cases langchain Related to the langchain package Ɑ: memory Related to memory module size:L This PR changes 100-499 lines, ignoring generated files. Ɑ: vector store Related to vector store module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants