Home / Function/ save_context() — langchain Function Reference

save_context() — langchain Function Reference

Architecture documentation for the save_context() function in vectorstore_token_buffer_memory.py from the langchain codebase.

Function python LangChainCore Runnables calls 1 called by 1

Entity Profile

Dependency Diagram

graph TD
  6e071205_25d6_05f7_68cf_15bd4170b5d4["save_context()"]
  5131526a_5463_d58d_257b_58b635bce851["ConversationVectorStoreTokenBufferMemory"]
  6e071205_25d6_05f7_68cf_15bd4170b5d4 -->|defined in| 5131526a_5463_d58d_257b_58b635bce851
  7f0b2656_bf0d_8aa3_f629_85d35d29cc9b["_pop_and_store_interaction()"]
  7f0b2656_bf0d_8aa3_f629_85d35d29cc9b -->|calls| 6e071205_25d6_05f7_68cf_15bd4170b5d4
  7f0b2656_bf0d_8aa3_f629_85d35d29cc9b["_pop_and_store_interaction()"]
  6e071205_25d6_05f7_68cf_15bd4170b5d4 -->|calls| 7f0b2656_bf0d_8aa3_f629_85d35d29cc9b
  style 6e071205_25d6_05f7_68cf_15bd4170b5d4 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain/langchain_classic/memory/vectorstore_token_buffer_memory.py lines 145–155

    def save_context(self, inputs: dict[str, Any], outputs: dict[str, str]) -> None:
        """Save context from this conversation to buffer. Pruned."""
        BaseChatMemory.save_context(self, inputs, outputs)
        self._timestamps.append(datetime.now().astimezone())
        # Prune buffer if it exceeds max token limit
        buffer = self.chat_memory.messages
        curr_buffer_length = self.llm.get_num_tokens_from_messages(buffer)
        if curr_buffer_length > self.max_token_limit:
            while curr_buffer_length > self.max_token_limit:
                self._pop_and_store_interaction(buffer)
                curr_buffer_length = self.llm.get_num_tokens_from_messages(buffer)

Domain

Subdomains

Frequently Asked Questions

What does save_context() do?
save_context() is a function in the langchain codebase, defined in libs/langchain/langchain_classic/memory/vectorstore_token_buffer_memory.py.
Where is save_context() defined?
save_context() is defined in libs/langchain/langchain_classic/memory/vectorstore_token_buffer_memory.py at line 145.
What does save_context() call?
save_context() calls 1 function(s): _pop_and_store_interaction.
What calls save_context()?
save_context() is called by 1 function(s): _pop_and_store_interaction.

Analyze Your Own Codebase

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

Try Supermodel Free