मेमोरी ग्राफ़

LangChain और Neo4j के साथ Graph RAG

Adam Cowley

Manager, Developer Education at Neo4j

RAG ऐप्लिकेशन्स में मेमोरी

शॉर्ट-टर्म मेमोरी

  • कम अवधि, सीमित स्कोप
  • बातचीत का इतिहास

 

गोल्डफ़िश

लॉन्ग-टर्म मेमोरी

  • सेमान्टिक मेमोरी: दुनिया के तथ्य
  • हाइपर-पर्सनलाइज़ेशन में उपयोगी

हाथी

LangChain और Neo4j के साथ Graph RAG

शॉर्ट-टर्म मेमोरी

LangChain और Neo4j के साथ Graph RAG

शॉर्ट-टर्म मेमोरी

LangChain और Neo4j के साथ Graph RAG

शॉर्ट-टर्म मेमोरी

LangChain और Neo4j के साथ Graph RAG

शॉर्ट-टर्म से लॉन्ग-टर्म मेमोरी

LangChain और Neo4j के साथ Graph RAG

शॉर्ट-टर्म से लॉन्ग-टर्म मेमोरी

LangChain और Neo4j के साथ Graph RAG

शॉर्ट-टर्म से लॉन्ग-टर्म मेमोरी

LangChain और Neo4j के साथ Graph RAG

शॉर्ट-टर्म से लॉन्ग-टर्म मेमोरी

LangChain और Neo4j के साथ Graph RAG

शॉर्ट-टर्म से लॉन्ग-टर्म मेमोरी

LangChain और Neo4j के साथ Graph RAG

Neo4j चैट मैसेज हिस्ट्री

from langchain_neo4j import Neo4jChatMessageHistory


history = Neo4jChatMessageHistory(
url=NEO4J_URI,
username=NEO4J_USERNAME,
password=NEO4J_PASSWORD,
session_id="session_id_1",
)
# Add a human message history.add_user_message("hi!")
# Add an AI message history.add_ai_message("what's up?")
LangChain और Neo4j के साथ Graph RAG

सब कुछ स्टोर करने की समस्याएँ

मेमोरी मेथड्स

LangChain और Neo4j के साथ Graph RAG

Neo4j चैट मैसेज हिस्ट्री

from langchain_neo4j import Neo4jChatMessageHistory

history = Neo4jChatMessageHistory(
    url=NEO4J_URI,
    username=NEO4J_USERNAME,
    password=NEO4J_PASSWORD,
    session_id="session_id_1",

window=10 # defaults to 3 messages
)
# Get history print(history.messages)
[HumanMessage(content='hi!', ...), AIMessage(content='whats up?', ...)]
LangChain और Neo4j के साथ Graph RAG

बातचीत का सार

from pydantic import BaseModel, Field

class ConversationFact(BaseModel):
    """
    A class that holds the facts from a conversation in a format of object, subject, predicate.
    """

object: str = Field(description="The object of the fact. For example, 'Adam' ")
subject: str = Field(description="The subject of the fact. For example, 'Ice cream'")
relationship: str = Field(description="The relationship between object and subject. Eg: 'LOVES'")
class ConversationFacts(BaseModel): """ A class that holds a list of ConversationFact objects. """ facts: list[ConversationFact] = Field(description="A list of ConversationFact objects.")
LangChain और Neo4j के साथ Graph RAG

बातचीत का सार

llm_with_output = (
    init_chat_model("gpt-4o-mini", model_provider="openai", api_key="...")
        .with_structured_output(ConversationFacts)
)
LangChain और Neo4j के साथ Graph RAG

बातचीत का सार

prompt = ChatPromptTemplate.from_messages(

SystemMessagePromptTemplate.from_template("Extract the facts from the conversation."),
MessagesPlaceholder(variable_name="history"),
)
chain = prompt | llm_with_output
chain.invoke({
"history": history.messages,
})
ConversationFacts(facts=[
    ConversationFact(object='child', subject='Bluey', relationship='LOVES')
])
LangChain और Neo4j के साथ Graph RAG

अभ्यास करते हैं!

LangChain और Neo4j के साथ Graph RAG

Preparing Video For Download...