BaşlayınÜcretsiz başlayın

Saving conversation memory in the graph

The simplest chat message history strategy is save all of the messages in the database, exactly as they are. This implementation is simple to code, but the information can be difficult to extract reliably from longer conversations. For longer conversations, you'll also potentially have cost and latency issues due to the number of tokens being sent with each input.

Bu egzersiz, kursun bir parçasıdır

Graph RAG with LangChain and Neo4j

Kursa Göz Atın

Egzersiz talimatları

  • Instantiate a class for storing chat messages in a Neo4j database using the credentials and SESSION_ID variable provided.
  • Start the conversation with a message from the user.
  • Add an AI generated response to the conversation.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

from langchain_neo4j import Neo4jChatMessageHistory

# Store chat history in Neo4j
history = ____(
    url=NEO4J_URL,
    username=NEO4J_USERNAME,
    password=NEO4J_PASSWORD,
    ____=SESSION_ID,
)

# Add a user message
history.____("My favourite character is Juliet.")

# Add an AI message
history.____("Great choice! Juliet is a multi-faceted and complex character.")
Kodu Düzenle ve Çalıştır