यहाँ लांगचेन के लिए सामान्य रूप से इस्तेमाल किए जाने वाले मेमोरी कंपोनेंट्स हैं:

नोट: मेमोरी कंपोनेंट को परिभाषित करने के बाद, आप इसे चेन की मेमोरी के रूप में पैरामीटर के रूप में पास कर सकते हैं और इसे उपयोग कर सकते हैं।

ConversationBufferMemory

मेमोरी पर आधारित एक मेमोरी कंपोनेंट, जो मेमोरी में डेटा संग्रहित करता है

from langchain.memory import ConversationBufferMemory

memory = ConversationBufferMemory()
memory.save_context({"input": "hi"}, {"output": "whats up"})

RedisChatMessageHistory

रेडिस पर आधारित एक मेमोरी कंपोनेंट

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("hi!")

history.add_ai_message("whats up?")

PostgresChatMessageHistory

पोस्टग्रेस डेटाबेस पर आधारित एक मेमोरी कंपोनेंट

from langchain.memory import PostgresChatMessageHistory

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

history.add_user_message("hi!")

history.add_ai_message("whats up?")

MongoDBChatMessageHistory

मोंगोडीबी पर आधारित एक मेमोरी कंपोनेंट

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("hi!")

message_history.add_ai_message("whats up?")