diff --git a/src/assets/images/memory-episodic-data-model.svg b/src/assets/images/memory-episodic-data-model.svg new file mode 100644 index 0000000..081e1de --- /dev/null +++ b/src/assets/images/memory-episodic-data-model.svg @@ -0,0 +1,2 @@ +CypherQuestionHAS_QUESTION id: str | key name: str statement: str id: str | key question: str embedding: list<float> \ No newline at end of file diff --git a/src/assets/images/memory-episodic-example.svg b/src/assets/images/memory-episodic-example.svg new file mode 100644 index 0000000..c0fd8fd --- /dev/null +++ b/src/assets/images/memory-episodic-example.svg @@ -0,0 +1,2 @@ +CypherQuestionHAS_QUESTION id: c2 name: query b statement: MATCH (n:Apple {name:... id: q3 question: what apples are similar to fuji? embedding: [0.157, -0.456, ...]CypherQuestionHAS_QUESTION id: c1 name: query a statement: MATCH (n:Apple) ... id: q2 question: how many apples can I eat? embedding: [0.123, 0.467, ...]Question id: q1 question: how many apples are there? embedding: [0.123, 0.456, ...]HAS_QUESTION \ No newline at end of file diff --git a/src/assets/images/memory-procedural-data-model.svg b/src/assets/images/memory-procedural-data-model.svg new file mode 100644 index 0000000..4cf1fd7 --- /dev/null +++ b/src/assets/images/memory-procedural-data-model.svg @@ -0,0 +1,2 @@ +UseCaseUserPromptSysPromptHAS_SYS_PROMPT id: str | key name: str description: str id: str | key name: str content: strHAS_USER_PROMPT id: str | key name: str content: str parameters: list<str> \ No newline at end of file diff --git a/src/assets/images/memory-procedural-example.svg b/src/assets/images/memory-procedural-example.svg new file mode 100644 index 0000000..90d06dc --- /dev/null +++ b/src/assets/images/memory-procedural-example.svg @@ -0,0 +1,2 @@ +UseCaseUserPromptSysPromptHAS_SYS_PROMPT id: uc1 name: Cypher Generation description: Generate a Cypher query to gather context id: sp1 name: Cypher Generation Sys Prompt content: You are a professional Graph Analyst...HAS_USER_PROMPT id: up1 name: Cypher Generation User Prompt content: <instructions>\nPlease follow Neo4j best... parameters: ["schema", "examples", "question"] \ No newline at end of file diff --git a/src/assets/images/memory-procedural-temporal-data-model.svg b/src/assets/images/memory-procedural-temporal-data-model.svg new file mode 100644 index 0000000..ac2b361 --- /dev/null +++ b/src/assets/images/memory-procedural-temporal-data-model.svg @@ -0,0 +1,2 @@ +UseCaseUseCaseDescUserPromptUserPromptDetailsSysPromptSysPromptDetailsHAS_SYS_PROMPT id: str | key name: str id: str | key description: str version: int createDatetime: datetime id: str | key name: str id: str | key content: str version: int createDatetime: datetimeHAS_USER_PROMPT id: str | key name: str id: str | key content: str parameters: list<str> version: int createDatetime: datetimeHAS_CUR_DETAILSHAS_CUR_DESCHAS_CUR_DETAILSPREVIOUSPREVIOUSPREVIOUS \ No newline at end of file diff --git a/src/assets/images/memory-procedural-temporal-example.svg b/src/assets/images/memory-procedural-temporal-example.svg new file mode 100644 index 0000000..c52337f --- /dev/null +++ b/src/assets/images/memory-procedural-temporal-example.svg @@ -0,0 +1,2 @@ +UseCaseUseCaseDescUserPromptUserPromptDetailsUserPromptDetailsSysPromptSysPromptDetailsSysPromptDetailsHAS_SYS_PROMPT id: uc1 name: Cypher Generation id: ucd1 description: Generate a Cypher query to gather context version: 1 createDatetime: 01-01-2024T00:00.00 id: sp1 name: Cypher Generation Sys Prompt id: spd2 content: You are a professional Graph Analyst... version: 2 createDatetime: 02-01-2025T00:00.00 id: spd1 content: You are a Graph Analyst... version: 1 createDatetime: 12-01-2024T00:00.00HAS_USER_PROMPT id: up1 name: Cypher Generation User Prompt id: udp2 content: <instructions>\nPlease follow Neo4j best... parameters: ["schema", "examples", "question"] version: 2 createDatetime: 02-15-2025T00:00.00 id: udp1 content: <instructions>\nPlease follow Neo4j best... parameters: ["schema", "question"] version: 1 createDatetime: 01-15-2025T00:00.00HAS_CUR_DETAILSPREVIOUSHAS_CUR_DESCHAS_CUR_DETAILSPREVIOUS \ No newline at end of file diff --git a/src/assets/images/memory-semantic-data-model.svg b/src/assets/images/memory-semantic-data-model.svg new file mode 100644 index 0000000..b0d5555 --- /dev/null +++ b/src/assets/images/memory-semantic-data-model.svg @@ -0,0 +1,2 @@ +UserEventATTENDEDHAS_FRIEND id: str | key name: str age: int description: str id: str | key name: str description: str \ No newline at end of file diff --git a/src/assets/images/memory-semantic-example.svg b/src/assets/images/memory-semantic-example.svg new file mode 100644 index 0000000..a9d0864 --- /dev/null +++ b/src/assets/images/memory-semantic-example.svg @@ -0,0 +1,2 @@ +UserUserEventATTENDED id: a name: Bob age: 25 description: loves animals and has many pets id: c name: Jim age: 45 id: e name: Trivia Night description: 80's themed trivia night at a local barUser id: b name: AliceATTENDEDHAS_FRIEND \ No newline at end of file diff --git a/src/assets/images/memory-semantic-temporal-data-model.svg b/src/assets/images/memory-semantic-temporal-data-model.svg new file mode 100644 index 0000000..09b2952 --- /dev/null +++ b/src/assets/images/memory-semantic-temporal-data-model.svg @@ -0,0 +1,2 @@ +UserEventATTENDEDHAS_FRIEND id: str | key name: str birthday: Date id: str | key name: str description: str startDate: Date endDate: Date active: boolUserDescHAS_CURRENT_DESCPREVIOUS id: str | key description: str createDatetime: datetime version: int \ No newline at end of file diff --git a/src/assets/images/memory-semantic-temporal-example.svg b/src/assets/images/memory-semantic-temporal-example.svg new file mode 100644 index 0000000..7fc0ccd --- /dev/null +++ b/src/assets/images/memory-semantic-temporal-example.svg @@ -0,0 +1,2 @@ +UserUserDescUserDescUserDescEventATTENDED id: a name: Bob birthday: 12/12/1999 id: e name: Trivia Night description: 80's themed trivia night at a local barUser id: b name: AliceHAS_FRIEND id: ud3 description: loves animals and has many pets createDatetime: 03-01-2025T00:00.00 version: 3 id: ud2 description: loves animals and has one pet createDatetime: 02-15-2025T00:00.00 version: 2 id: ud1 description: loves animals createDatetime: 12-01-2024T00:00.00 version: 1HAS_CURRENT_DESCPREVIOUSPREVIOUS startDate: 04-12-2005 endDate: 10-10-2024 active: false \ No newline at end of file diff --git a/src/content/docs/reference/knowledge-graph/memory-graph-episodic.md b/src/content/docs/reference/knowledge-graph/memory-graph-episodic.md new file mode 100644 index 0000000..4d86600 --- /dev/null +++ b/src/content/docs/reference/knowledge-graph/memory-graph-episodic.md @@ -0,0 +1,31 @@ +--- +title: Episodic Memory Graph +description: Structured, navigable, contains episodic details of events +--- + +## Episodic Memory + +Episodic memory stores remembered experiences. These contain information about event details and past agent actions. A common use case for this type of memory is in few-shot prompting. Previous question-answer pairs are stored in the graph and retrieved to provide examples in the prompt. Performing a similarity search between the user query and questions in the database accomplishes this. + +The image below shows a graph data model that stores user questions and the Cypher query used to retrieve the data. Using similarity search and a simple graph traversal, we can retrieve the top k most relevant examples from the database and inject them into the prompt to inform novel Cypher generation. + +![Graph](../../../../assets/images/memory-episodic-data-model.svg) + +Here’s an example of how this may look in practice. A possible retrieval method is to perform a similarity search against the question embeddings in the database and then traverse to the associated Cypher queries. The top k question texts and Cypher query statements are returned and formatted into a few-shot examples. + +![Graph](../../../../assets/images/memory-episodic-example.svg) + +*A Cypher query may have many questions. This is because some user questions may differ in explicit text but have the same semantic meaning.* + +The process of updating these memories may look like this: + +* The agent generates a Cypher query to retrieve information from a Neo4j database. +* The user rates the returned result from the agent as good or bad. +* Positive feedback kicks off a process that writes the Cypher query and question to the database to use for future examples. + +Episodic memory is better written in the background once user feedback is received. This prevents bad or unhelpful memories from being included, which would ultimately diminish performance. + +## Further reading + +* [Modeling Agent Memory](https://medium.com/neo4j/modeling-agent-memory-d3b6bc3bb9c4) +* [LangGraph Memory](https://langchain-ai.github.io/langgraph/concepts/memory/) \ No newline at end of file diff --git a/src/content/docs/reference/knowledge-graph/memory-graph-procedural.md b/src/content/docs/reference/knowledge-graph/memory-graph-procedural.md new file mode 100644 index 0000000..539dc4f --- /dev/null +++ b/src/content/docs/reference/knowledge-graph/memory-graph-procedural.md @@ -0,0 +1,33 @@ +--- +title: Procedural Memory Graph +description: Structured, navigable, annotated and instructional content +--- + +## Procedural Memory Graph + +Procedural memory stores how to do something. In real life, this type of memory helps us write with a pen or play guitar without thinking about the explicit actions. Through practice, these actions have become internalized in our brains, and we no longer have to think about how to perform them. + +For AI systems, procedural memory is a combination of the model weights, code, and prompts. Since the prompts are most accessible to us, this type of memory is commonly used to store system prompts, tool descriptions, and instructions. These memories may then be updated in a feedback loop from either the end user or another system, such as an LLM-as-a-judge. Just as we learned to write through practice and feedback, an agent can learn a task by refining its internal set of instructions. + +Here, the graph data model stores information about prompts. It contains both system and user prompts for a particular use case. + +![Graph](../../../../assets/images/memory-procedural-data-model.svg) + +This is how the data may look for a Text2Cypher agent. A possible retrieval strategy is to retrieve these prompts anytime a new chat session is started. This ensures that any updates made since the previous session are implemented. + +![Graph](../../../../assets/images/memory-procedural-example.svg) + +Note the difference between episodic and procedural memory. In the Cypher generation example, episodic memory is recalling the explicit question and Cypher pairs, whereas procedural memory is recalling how the Cypher is generated. + +The process of updating these memories may look like this: + +* A series of prompt, answer, and feedback triples are collected as input. +* An LLM takes this series and generates a new prompt that adheres to the provided feedback. +* This new prompt is written into the database. + +Procedural memory also lends itself well to being written in the background once feedback is received. In the example of improving prompts, it is probably best to wait until many feedback responses are received so the LLM performing the improvement can align with a more representative sample of the user base. + +## Further reading + +* [Modeling Agent Memory](https://medium.com/neo4j/modeling-agent-memory-d3b6bc3bb9c4) +* [LangGraph Memory](https://langchain-ai.github.io/langgraph/concepts/memory/) \ No newline at end of file diff --git a/src/content/docs/reference/knowledge-graph/memory-graph-semantic.md b/src/content/docs/reference/knowledge-graph/memory-graph-semantic.md new file mode 100644 index 0000000..25e2db9 --- /dev/null +++ b/src/content/docs/reference/knowledge-graph/memory-graph-semantic.md @@ -0,0 +1,32 @@ +--- +title: Semantic Memory Graph +description: Structured, navigable, contains entities extracted from conversation +--- + +## Semantic Memory Graph + +Semantic memory contains facts about the world. For an agent, this can be information about the user, such as name, age, or relationships to other people. This could also take the form of a collection of documents used in a RAG pipeline. This type of memory requires information to be properly maintained and can change frequently, which leads to complexity in creating, updating, and deleting memories appropriately. + +Below is a possible graph data model that contains information about a user profile. In this data model, we also can track the relationships a user has with other users, as well as events they attended. + +![Graph](../../../../assets/images/memory-semantic-data-model.svg) + +Here’s an example of how this may look in practice. Information about the current user may be retrieved dynamically according to the input question. For example, if the question requires knowledge about what the user does for fun, a query may be used to grab information about events they’ve attended. + +![Graph](../../../../assets/images/memory-semantic-example.svg) + +The process of updating these memories may look like this: + +* Prepare entities or unstructured text from the conversation to be written as a memory. +* Search for the top k memories in the database that are similar to the incoming prepared data. +* Identify if there is new or conflicting information in the user query. +* Update the existing memories with new nodes or values. +* Create or delete relationships. + +Semantic memory lends itself well to being updated in the hot path. This prevents the agent from communicating out-of-date information to the user. Since this data is typically used in a RAG pipeline, it poses a risk of delayed writing in the future. + + +## Further reading + +* [Modeling Agent Memory](https://medium.com/neo4j/modeling-agent-memory-d3b6bc3bb9c4) +* [LangGraph Memory](https://langchain-ai.github.io/langgraph/concepts/memory/) diff --git a/src/content/docs/reference/knowledge-graph/memory-graph-temporal.md b/src/content/docs/reference/knowledge-graph/memory-graph-temporal.md new file mode 100644 index 0000000..f5f6025 --- /dev/null +++ b/src/content/docs/reference/knowledge-graph/memory-graph-temporal.md @@ -0,0 +1,30 @@ +--- +title: Temporal Memory Graph +description: Structured, navigable, maintained change history of data +--- + +## Temporal Memory Graph + +Temporal memory stores how data changes over time. This can apply to any other memory type and allows the agent to be aware of how things have changed. In the example of storing the semantic memory of a user profile, we can implement temporal memory in a few ways. One is by including timestamps on `HAS_FRIEND` relationships with other users to identify the beginning and end of personal relationships. The other is implementing a `PREVIOUS` relationship between nodes we want to maintain versions of. In the example below, we’ll pull out the user description into its own `UserDescription` node, which can be tracked in this manner. The image below shows the updated user profile data model that incorporates semantic and temporal memory. + +![Graph](../../../../assets/images/memory-semantic-temporal-data-model.svg) + +We see an applied version of this data where the user description has been updated over several months. Notice that the `User` node only has a `HAS_CURRENT_DESC` relationship with the most up-to-date `UserDesc`. This makes retrieval easier. We also see that Bob used to be friends with Alice until recently. + +![Graph](../../../../assets/images/memory-semantic-temporal-example.svg) + +Another example would be tracking prompt versions with the procedural memory type. Here, we have a primary prompt node with the prompt name. It’s connected to a sequence of `UserPromptDetails` or `SysPromptDetails` nodes with a `PREVIOUS` relationship to the most recent version. This allows the prompt to be retrieved while allowing previous versions to be easily accessible for auditing or reverting changes. + +![Graph](../../../../assets/images/memory-procedural-temporal-data-model.svg) + +We can see the applied version of this data model for a Text2Cypher agent, where changes in prompt content and parameters are easily accessible. + + +![Graph](../../../../assets/images/memory-procedural-temporal-example.svg) + + + +## Further reading + +* [Modeling Agent Memory](https://medium.com/neo4j/modeling-agent-memory-d3b6bc3bb9c4) +* [LangGraph Memory](https://langchain-ai.github.io/langgraph/concepts/memory/) \ No newline at end of file