From 4cce5972538f380624d4731c1f0f9deb4899f7ce Mon Sep 17 00:00:00 2001 From: Barry Zhang Date: Thu, 21 Nov 2024 11:00:47 -0500 Subject: [PATCH 1/3] README improvements --- src/memory/README.md | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/memory/README.md b/src/memory/README.md index 159374f2..26f63009 100644 --- a/src/memory/README.md +++ b/src/memory/README.md @@ -1,5 +1,5 @@ # Knowledge Graph Memory Server -A basic MCP server implementation that provides persistent memory using a knowledge-graph. The server manages entities, their observations, and the relationships between them using a JSON-based file system. +A basic MCP server implementation that provides persistent memory using a knowledge graph. The server manages entities, their observations, and the relationships between them using a JSON-based file system. This lets Claude remember information about the user across chats and projects, and lets them bypass the issues of having super long chats @@ -16,16 +16,17 @@ Example: { "name": "John_Smith", "entityType": "person", - "observations": ["Lives in New York", "Works as a software engineer"] + "observations": ["Speaks fluent Spanish"] } ``` ## Relations Relations define directed connections between entities. They are always stored in active voice and describe how entities interact or relate to each other. Example: -```jsonCopy{ +```json +{ "from": "John_Smith", - "to": "TechCorp", + "to": "Anthropic", "relationType": "works_at" } ``` @@ -38,7 +39,8 @@ Observations are discrete pieces of information about an entity. They are: - Should be atomic (one fact per observation) Example: -```jsonCopy{ +```json +{ "entityName": "John_Smith", "observations": [ "Speaks fluent Spanish", @@ -70,9 +72,9 @@ Example: - search_nodes: Search for nodes based on names, types, and observation content - open_nodes: Access specific nodes by their names -# Prompts +# Prompt -The prompt for utilizing memory depends on the use case, but here is an example prompt for chat personalization. You could use this prompt in the "Custom Instructions" field of a Project +The prompt for utilizing memory depends on the use case, but here is an example prompt for chat personalization. You could use this prompt in the "Custom Instructions" field of a Project. Changing this prompt will help the model determine the frequency and types of memories created. ``` Follow these steps for each interaction: @@ -95,7 +97,7 @@ Follow these steps for each interaction: 4. Memory Update: - If any new information was gathered during the interaction, update your memory as follows: - a) Create nodes for recurring organizations, people, and significant events, connecting them to the current node. + a) Create entities for recurring organizations, people, and significant events, connecting them to the current node using relations b) Store most facts as observations within these nodes - Try to perform all updates in one operation using the create and delete functions. ``` \ No newline at end of file From 0f2fb24d7c80e37d527cd85a4e6083544637ace1 Mon Sep 17 00:00:00 2001 From: Barry Zhang Date: Thu, 21 Nov 2024 11:16:33 -0500 Subject: [PATCH 2/3] more wording changes --- src/memory/README.md | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/memory/README.md b/src/memory/README.md index 26f63009..14c67d20 100644 --- a/src/memory/README.md +++ b/src/memory/README.md @@ -1,7 +1,7 @@ # Knowledge Graph Memory Server -A basic MCP server implementation that provides persistent memory using a knowledge graph. The server manages entities, their observations, and the relationships between them using a JSON-based file system. +A basic MCP server that provides persistent memory using a knowledge graph. The server manages entities, observations of them, and the relationships among them using a JSON-based file system. -This lets Claude remember information about the user across chats and projects, and lets them bypass the issues of having super long chats +This lets Claude remember information about the user across chats, and lets them bypass the issues of having super long chats. # Core Concepts @@ -22,6 +22,7 @@ Example: ## Relations Relations define directed connections between entities. They are always stored in active voice and describe how entities interact or relate to each other. + Example: ```json { @@ -74,7 +75,9 @@ Example: # Prompt -The prompt for utilizing memory depends on the use case, but here is an example prompt for chat personalization. You could use this prompt in the "Custom Instructions" field of a Project. Changing this prompt will help the model determine the frequency and types of memories created. +The prompt for utilizing memory depends on the use case. Changing the prompt will help the model determine the frequency and types of memories created. + +Here is an example prompt for chat personalization. You could use this prompt in the "Custom Instructions" field of a [Claude.ai Project](https://www.anthropic.com/news/projects). ``` Follow these steps for each interaction: @@ -85,19 +88,19 @@ Follow these steps for each interaction: 2. Memory Retrieval: - Always begin your chat by saying only "Remembering..." and retrieve all relevant information from your knowledge graph - - Always refer to your knowledge as your "memory" + - Always refer to your knowledge graph as your "memory" 3. Memory - While conversing with the user, be attentive to any new information that falls into these categories: - a) Basic Identity (Age, gender, location, Job title, education level, etc.) + a) Basic Identity (age, gender, location, job title, education level, etc.) b) Behaviors (interests, habits, etc.) c) Preferences (communication style, preferred language, etc.) - d) Goals/Psychology (Goals, targets, aspirations, etc.) + d) Goals (goals, targets, aspirations, etc.) e) Relationships (personal and professional relationships up to 3 degrees of separation) 4. Memory Update: - If any new information was gathered during the interaction, update your memory as follows: - a) Create entities for recurring organizations, people, and significant events, connecting them to the current node using relations - b) Store most facts as observations within these nodes - - Try to perform all updates in one operation using the create and delete functions. + a) Create entities for recurring organizations, people, and significant events + b) Connect them to the current entities using relations + b) Store facts about them as observations ``` \ No newline at end of file From 4fe5682eb9f2506c2763d2e5933bfcb86c96041a Mon Sep 17 00:00:00 2001 From: Barry Zhang Date: Thu, 21 Nov 2024 11:57:59 -0500 Subject: [PATCH 3/3] MORE MD improvements --- src/memory/README.md | 121 ++++++++++++++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 29 deletions(-) diff --git a/src/memory/README.md b/src/memory/README.md index 14c67d20..40bd7b07 100644 --- a/src/memory/README.md +++ b/src/memory/README.md @@ -1,11 +1,9 @@ # Knowledge Graph Memory Server -A basic MCP server that provides persistent memory using a knowledge graph. The server manages entities, observations of them, and the relationships among them using a JSON-based file system. +A basic implementation of persistent memory using a local knowledge graph. This lets Claude remember information about the user across chats. -This lets Claude remember information about the user across chats, and lets them bypass the issues of having super long chats. +## Core Concepts -# Core Concepts - -## Entities +### Entities Entities are the primary nodes in the knowledge graph. Each entity has: - A unique name (identifier) - An entity type (e.g., "person", "organization", "event") @@ -20,7 +18,7 @@ Example: } ``` -## Relations +### Relations Relations define directed connections between entities. They are always stored in active voice and describe how entities interact or relate to each other. Example: @@ -31,7 +29,7 @@ Example: "relationType": "works_at" } ``` -## Observations +### Observations Observations are discrete pieces of information about an entity. They are: - Stored as strings @@ -51,29 +49,94 @@ Example: } ``` -# Tools - -## Entity Management - -- create_entities: Create new entities in the knowledge graph with names, types, and observations -- delete_entities: Remove entities and their associated relations from the graph -- add_observations: Add new observations to existing entities -- delete_observations: Remove specific observations from entities - - -## Relation Management - -- create_relations: Establish relationships between entities in active voice -- delete_relations: Remove specific relationships between entities - - -## Query Tools - -- read_graph: Retrieve the entire knowledge graph -- search_nodes: Search for nodes based on names, types, and observation content -- open_nodes: Access specific nodes by their names +## API + +### Tools +- **create_entities** + - Create multiple new entities in the knowledge graph + - Input: `entities` (array of objects) + - Each object contains: + - `name` (string): Entity identifier + - `entityType` (string): Type classification + - `observations` (string[]): Associated observations + - Ignores entities with existing names + +- **create_relations** + - Create multiple new relations between entities + - Input: `relations` (array of objects) + - Each object contains: + - `from` (string): Source entity name + - `to` (string): Target entity name + - `relationType` (string): Relationship type in active voice + - Skips duplicate relations + +- **add_observations** + - Add new observations to existing entities + - Input: `observations` (array of objects) + - Each object contains: + - `entityName` (string): Target entity + - `contents` (string[]): New observations to add + - Returns added observations per entity + - Fails if entity doesn't exist + +- **delete_entities** + - Remove entities and their relations + - Input: `entityNames` (string[]) + - Cascading deletion of associated relations + - Silent operation if entity doesn't exist + +- **delete_observations** + - Remove specific observations from entities + - Input: `deletions` (array of objects) + - Each object contains: + - `entityName` (string): Target entity + - `observations` (string[]): Observations to remove + - Silent operation if observation doesn't exist + +- **delete_relations** + - Remove specific relations from the graph + - Input: `relations` (array of objects) + - Each object contains: + - `from` (string): Source entity name + - `to` (string): Target entity name + - `relationType` (string): Relationship type + - Silent operation if relation doesn't exist + +- **read_graph** + - Read the entire knowledge graph + - No input required + - Returns complete graph structure with all entities and relations + +- **search_nodes** + - Search for nodes based on query + - Input: `query` (string) + - Searches across: + - Entity names + - Entity types + - Observation content + - Returns matching entities and their relations + +- **open_nodes** + - Retrieve specific nodes by name + - Input: `names` (string[]) + - Returns: + - Requested entities + - Relations between requested entities + - Silently skips non-existent nodes + +# Usage with Claude Desktop + +### Setup +Add this to your claude_desktop_config.json: +```json +{ + "mcp-server-memory": { + "command": "mcp-server-memory" + } +} +``` -# Prompt +### System Prompt The prompt for utilizing memory depends on the use case. Changing the prompt will help the model determine the frequency and types of memories created.