Home / File/ vectorstore_token_buffer_memory.py — langchain Source File

vectorstore_token_buffer_memory.py — langchain Source File

Architecture documentation for vectorstore_token_buffer_memory.py, a python file in the langchain codebase. 10 imports, 0 dependents.

File python LangChainCore MessageInterface 10 imports 1 classes

Entity Profile

Dependency Diagram

graph LR
  62cf1bd2_f33b_5f77_b417_fb61d41200c3["vectorstore_token_buffer_memory.py"]
  f3365e3c_fb7a_bb9a_bc79_059b06cb7024["warnings"]
  62cf1bd2_f33b_5f77_b417_fb61d41200c3 --> f3365e3c_fb7a_bb9a_bc79_059b06cb7024
  c0b5feef_1759_3f2b_62d3_f376e06b863f["datetime"]
  62cf1bd2_f33b_5f77_b417_fb61d41200c3 --> c0b5feef_1759_3f2b_62d3_f376e06b863f
  feec1ec4_6917_867b_d228_b134d0ff8099["typing"]
  62cf1bd2_f33b_5f77_b417_fb61d41200c3 --> feec1ec4_6917_867b_d228_b134d0ff8099
  9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"]
  62cf1bd2_f33b_5f77_b417_fb61d41200c3 --> 9444498b_8066_55c7_b3a2_1d90c4162a32
  16c7d167_e2e4_cd42_2bc2_d182459cd93c["langchain_core.prompts.chat"]
  62cf1bd2_f33b_5f77_b417_fb61d41200c3 --> 16c7d167_e2e4_cd42_2bc2_d182459cd93c
  f75e66a0_314a_f961_16d7_464ee959064b["langchain_core.vectorstores"]
  62cf1bd2_f33b_5f77_b417_fb61d41200c3 --> f75e66a0_314a_f961_16d7_464ee959064b
  dd5e7909_a646_84f1_497b_cae69735550e["pydantic"]
  62cf1bd2_f33b_5f77_b417_fb61d41200c3 --> dd5e7909_a646_84f1_497b_cae69735550e
  5b90a9d7_08ea_fab8_2528_673d880c66bf["langchain_classic.memory"]
  62cf1bd2_f33b_5f77_b417_fb61d41200c3 --> 5b90a9d7_08ea_fab8_2528_673d880c66bf
  0631e07f_ced9_09bd_71a1_4630e7d30d26["langchain_classic.memory.chat_memory"]
  62cf1bd2_f33b_5f77_b417_fb61d41200c3 --> 0631e07f_ced9_09bd_71a1_4630e7d30d26
  87a7c6c8_2a3f_c69c_016a_3d1a3991459b["langchain_classic.text_splitter"]
  62cf1bd2_f33b_5f77_b417_fb61d41200c3 --> 87a7c6c8_2a3f_c69c_016a_3d1a3991459b
  style 62cf1bd2_f33b_5f77_b417_fb61d41200c3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

"""Class for a conversation memory buffer with older messages stored in a vectorstore .

This implements a conversation memory in which the messages are stored in a memory
buffer up to a specified token limit. When the limit is exceeded, older messages are
saved to a `VectorStore` backing database. The `VectorStore` can be made persistent
across sessions.
"""

import warnings
from datetime import datetime
from typing import Any

from langchain_core.messages import BaseMessage
from langchain_core.prompts.chat import SystemMessagePromptTemplate
from langchain_core.vectorstores import VectorStoreRetriever
from pydantic import Field, PrivateAttr

from langchain_classic.memory import (
    ConversationTokenBufferMemory,
    VectorStoreRetrieverMemory,
)
from langchain_classic.memory.chat_memory import BaseChatMemory
from langchain_classic.text_splitter import RecursiveCharacterTextSplitter

DEFAULT_HISTORY_TEMPLATE = """
Current date and time: {current_time}.

Potentially relevant timestamped excerpts of previous conversations (you
do not need to use these if irrelevant):
{previous_history}

"""

TIMESTAMP_FORMAT = "%Y-%m-%d %H:%M:%S %Z"


class ConversationVectorStoreTokenBufferMemory(ConversationTokenBufferMemory):
    """Conversation chat memory with token limit and vectordb backing.

    load_memory_variables() will return a dict with the key "history".
    It contains background information retrieved from the vector store
    plus recent lines of the current conversation.

    To help the LLM understand the part of the conversation stored in the
    vectorstore, each interaction is timestamped and the current date and
    time is also provided in the history. A side effect of this is that the
    LLM will have access to the current date and time.

    Initialization arguments:

    This class accepts all the initialization arguments of
    ConversationTokenBufferMemory, such as `llm`. In addition, it
    accepts the following additional arguments

        retriever: (required) A VectorStoreRetriever object to use
            as the vector backing store

        split_chunk_size: (optional, 1000) Token chunk split size
            for long messages generated by the AI

// ... (124 more lines)

Domain

Subdomains

Dependencies

  • datetime
  • langchain_classic.memory
  • langchain_classic.memory.chat_memory
  • langchain_classic.text_splitter
  • langchain_core.messages
  • langchain_core.prompts.chat
  • langchain_core.vectorstores
  • pydantic
  • typing
  • warnings

Frequently Asked Questions

What does vectorstore_token_buffer_memory.py do?
vectorstore_token_buffer_memory.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, MessageInterface subdomain.
What does vectorstore_token_buffer_memory.py depend on?
vectorstore_token_buffer_memory.py imports 10 module(s): datetime, langchain_classic.memory, langchain_classic.memory.chat_memory, langchain_classic.text_splitter, langchain_core.messages, langchain_core.prompts.chat, langchain_core.vectorstores, pydantic, and 2 more.
Where is vectorstore_token_buffer_memory.py in the architecture?
vectorstore_token_buffer_memory.py is located at libs/langchain/langchain_classic/memory/vectorstore_token_buffer_memory.py (domain: LangChainCore, subdomain: MessageInterface, directory: libs/langchain/langchain_classic/memory).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free