Вот общие компоненты памяти для LangChain:

Примечание: После определения компонента памяти вы можете передать его в качестве параметра в память цепочки и использовать его.

ConversationBufferMemory

Компонент памяти, основанный на памяти, хранящий данные в памяти

from langchain.memory import ConversationBufferMemory

memory = ConversationBufferMemory()
memory.save_context({"input": "привет"}, {"output": "че каво"})

RedisChatMessageHistory

Компонент памяти на основе Redis

from langchain.memory import RedisChatMessageHistory

history = RedisChatMessageHistory(
	session_id="abc123",
	url="redis://192.168.0.100:6379/0",
	key_prefix="demo_prefix:"
)

history.add_user_message("привет!")

history.add_ai_message("че каво?")

PostgresChatMessageHistory

Компонент памяти на основе базы данных Postgres

from langchain.memory import PostgresChatMessageHistory

history = PostgresChatMessageHistory(
    connection_string="postgresql://postgres:mypassword@localhost/chat_history",
    session_id="foo",
)

history.add_user_message("привет!")

history.add_ai_message("че каво?")

MongoDBChatMessageHistory

Компонент памяти на основе MongoDB

from langchain.memory import MongoDBChatMessageHistory

connection_string = "mongodb://mongo_user:password123@mongo:27017"

message_history = MongoDBChatMessageHistory(
    connection_string=connection_string, session_id="test-session"
)

message_history.add_user_message("привет!")

message_history.add_ai_message("че каво?")