@henrychong-ai/mcp-neo4j-knowledge-graph 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +718 -0
  3. package/dist/KnowledgeGraphManager.d.ts +215 -0
  4. package/dist/KnowledgeGraphManager.js +910 -0
  5. package/dist/KnowledgeGraphManager.js.map +1 -0
  6. package/dist/callToolHandler.d.ts +5 -0
  7. package/dist/callToolHandler.js +26 -0
  8. package/dist/callToolHandler.js.map +1 -0
  9. package/dist/cli/neo4j-setup.d.ts +52 -0
  10. package/dist/cli/neo4j-setup.js +258 -0
  11. package/dist/cli/neo4j-setup.js.map +1 -0
  12. package/dist/config/paths.d.ts +13 -0
  13. package/dist/config/paths.js +41 -0
  14. package/dist/config/paths.js.map +1 -0
  15. package/dist/config/storage.d.ts +35 -0
  16. package/dist/config/storage.js +52 -0
  17. package/dist/config/storage.js.map +1 -0
  18. package/dist/embeddings/DefaultEmbeddingService.d.ts +64 -0
  19. package/dist/embeddings/DefaultEmbeddingService.js +139 -0
  20. package/dist/embeddings/DefaultEmbeddingService.js.map +1 -0
  21. package/dist/embeddings/EmbeddingJobManager.d.ts +212 -0
  22. package/dist/embeddings/EmbeddingJobManager.js +545 -0
  23. package/dist/embeddings/EmbeddingJobManager.js.map +1 -0
  24. package/dist/embeddings/EmbeddingService.d.ts +96 -0
  25. package/dist/embeddings/EmbeddingService.js +44 -0
  26. package/dist/embeddings/EmbeddingService.js.map +1 -0
  27. package/dist/embeddings/EmbeddingServiceFactory.d.ts +72 -0
  28. package/dist/embeddings/EmbeddingServiceFactory.js +147 -0
  29. package/dist/embeddings/EmbeddingServiceFactory.js.map +1 -0
  30. package/dist/embeddings/OpenAIEmbeddingService.d.ts +73 -0
  31. package/dist/embeddings/OpenAIEmbeddingService.js +195 -0
  32. package/dist/embeddings/OpenAIEmbeddingService.js.map +1 -0
  33. package/dist/embeddings/config.d.ts +83 -0
  34. package/dist/embeddings/config.js +65 -0
  35. package/dist/embeddings/config.js.map +1 -0
  36. package/dist/index.d.ts +4 -0
  37. package/dist/index.js +220 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/server/handlers/callToolHandler.d.ts +20 -0
  40. package/dist/server/handlers/callToolHandler.js +505 -0
  41. package/dist/server/handlers/callToolHandler.js.map +1 -0
  42. package/dist/server/handlers/listToolsHandler.d.ts +7 -0
  43. package/dist/server/handlers/listToolsHandler.js +511 -0
  44. package/dist/server/handlers/listToolsHandler.js.map +1 -0
  45. package/dist/server/handlers/toolHandlers/addObservations.d.ts +12 -0
  46. package/dist/server/handlers/toolHandlers/addObservations.js +99 -0
  47. package/dist/server/handlers/toolHandlers/addObservations.js.map +1 -0
  48. package/dist/server/handlers/toolHandlers/createEntities.d.ts +12 -0
  49. package/dist/server/handlers/toolHandlers/createEntities.js +20 -0
  50. package/dist/server/handlers/toolHandlers/createEntities.js.map +1 -0
  51. package/dist/server/handlers/toolHandlers/createRelations.d.ts +12 -0
  52. package/dist/server/handlers/toolHandlers/createRelations.js +20 -0
  53. package/dist/server/handlers/toolHandlers/createRelations.js.map +1 -0
  54. package/dist/server/handlers/toolHandlers/deleteEntities.d.ts +12 -0
  55. package/dist/server/handlers/toolHandlers/deleteEntities.js +20 -0
  56. package/dist/server/handlers/toolHandlers/deleteEntities.js.map +1 -0
  57. package/dist/server/handlers/toolHandlers/index.d.ts +8 -0
  58. package/dist/server/handlers/toolHandlers/index.js +9 -0
  59. package/dist/server/handlers/toolHandlers/index.js.map +1 -0
  60. package/dist/server/handlers/toolHandlers/readGraph.d.ts +12 -0
  61. package/dist/server/handlers/toolHandlers/readGraph.js +20 -0
  62. package/dist/server/handlers/toolHandlers/readGraph.js.map +1 -0
  63. package/dist/server/setup.d.ts +8 -0
  64. package/dist/server/setup.js +48 -0
  65. package/dist/server/setup.js.map +1 -0
  66. package/dist/storage/FileStorageProvider.d.ts +125 -0
  67. package/dist/storage/FileStorageProvider.js +322 -0
  68. package/dist/storage/FileStorageProvider.js.map +1 -0
  69. package/dist/storage/SearchResultCache.d.ts +102 -0
  70. package/dist/storage/SearchResultCache.js +258 -0
  71. package/dist/storage/SearchResultCache.js.map +1 -0
  72. package/dist/storage/StorageProvider.d.ts +171 -0
  73. package/dist/storage/StorageProvider.js +46 -0
  74. package/dist/storage/StorageProvider.js.map +1 -0
  75. package/dist/storage/StorageProviderFactory.d.ts +63 -0
  76. package/dist/storage/StorageProviderFactory.js +113 -0
  77. package/dist/storage/StorageProviderFactory.js.map +1 -0
  78. package/dist/storage/VectorStoreFactory.d.ts +43 -0
  79. package/dist/storage/VectorStoreFactory.js +41 -0
  80. package/dist/storage/VectorStoreFactory.js.map +1 -0
  81. package/dist/storage/neo4j/Neo4jConfig.d.ts +37 -0
  82. package/dist/storage/neo4j/Neo4jConfig.js +13 -0
  83. package/dist/storage/neo4j/Neo4jConfig.js.map +1 -0
  84. package/dist/storage/neo4j/Neo4jConnectionManager.d.ts +40 -0
  85. package/dist/storage/neo4j/Neo4jConnectionManager.js +58 -0
  86. package/dist/storage/neo4j/Neo4jConnectionManager.js.map +1 -0
  87. package/dist/storage/neo4j/Neo4jSchemaManager.d.ts +74 -0
  88. package/dist/storage/neo4j/Neo4jSchemaManager.js +224 -0
  89. package/dist/storage/neo4j/Neo4jSchemaManager.js.map +1 -0
  90. package/dist/storage/neo4j/Neo4jStorageProvider.d.ts +225 -0
  91. package/dist/storage/neo4j/Neo4jStorageProvider.js +1900 -0
  92. package/dist/storage/neo4j/Neo4jStorageProvider.js.map +1 -0
  93. package/dist/storage/neo4j/Neo4jVectorStore.d.ts +80 -0
  94. package/dist/storage/neo4j/Neo4jVectorStore.js +396 -0
  95. package/dist/storage/neo4j/Neo4jVectorStore.js.map +1 -0
  96. package/dist/types/entity-embedding.d.ts +156 -0
  97. package/dist/types/entity-embedding.js +2 -0
  98. package/dist/types/entity-embedding.js.map +1 -0
  99. package/dist/types/relation.d.ts +77 -0
  100. package/dist/types/relation.js +93 -0
  101. package/dist/types/relation.js.map +1 -0
  102. package/dist/types/temporalEntity.d.ts +55 -0
  103. package/dist/types/temporalEntity.js +66 -0
  104. package/dist/types/temporalEntity.js.map +1 -0
  105. package/dist/types/temporalRelation.d.ts +60 -0
  106. package/dist/types/temporalRelation.js +89 -0
  107. package/dist/types/temporalRelation.js.map +1 -0
  108. package/dist/types/vector-index.d.ts +48 -0
  109. package/dist/types/vector-index.js +2 -0
  110. package/dist/types/vector-index.js.map +1 -0
  111. package/dist/types/vector-store.d.ts +16 -0
  112. package/dist/types/vector-store.js +2 -0
  113. package/dist/types/vector-store.js.map +1 -0
  114. package/dist/utils/fs.d.ts +2 -0
  115. package/dist/utils/fs.js +3 -0
  116. package/dist/utils/fs.js.map +1 -0
  117. package/dist/utils/logger.d.ts +10 -0
  118. package/dist/utils/logger.js +35 -0
  119. package/dist/utils/logger.js.map +1 -0
  120. package/package.json +85 -0
package/README.md ADDED
@@ -0,0 +1,718 @@
1
+ # Neo4j Knowledge Graph MCP Server
2
+
3
+ ![Memento MCP Logo](assets/memento-logo-gray.svg)
4
+
5
+ Scalable, high performance knowledge graph memory system with semantic retrieval, contextual recall, and temporal awareness. Provides any LLM client that supports the model context protocol (e.g., Claude Desktop, Cursor, Github Copilot) with resilient, adaptive, and persistent long-term ontological memory.
6
+
7
+ [![Memento MCP Tests](https://github.com/gannonh/memento-mcp/actions/workflows/memento-mcp.yml/badge.svg)](https://github.com/gannonh/memento-mcp/actions/workflows/memento-mcp.yml)
8
+
9
+ ---
10
+
11
+ ## 🔧 Fork Notice
12
+
13
+ **This is a maintained fork of [@gannonh/memento-mcp](https://github.com/gannonh/memento-mcp)** with critical bug fixes and improvements.
14
+
15
+ ### What's Fixed
16
+
17
+ This fork addresses a **JSON parsing error** that occurred in the `addObservations` MCP tool in the published npm package:
18
+
19
+ ```
20
+ SyntaxError: Unexpected token 'F', "Framework:"... is not valid JSON
21
+ ```
22
+
23
+ **Root Cause**: The published npm package version had inconsistencies that caused parsing failures when adding observations to entities.
24
+
25
+ **Solution**: This fork:
26
+ - ✅ Uses `neo4j-driver` directly for all database operations (no subprocess)
27
+ - ✅ Proper transaction management with commit/rollback
28
+ - ✅ Parameterized Cypher queries to prevent injection
29
+ - ✅ Professional error handling and connection pooling
30
+ - ✅ All 287 unit tests passing
31
+ - ✅ Zero security vulnerabilities
32
+
33
+ See [INVESTIGATION.md](INVESTIGATION.md) for detailed technical analysis of the fix.
34
+
35
+ ### Installation
36
+
37
+ ```bash
38
+ # Use this fork instead of the upstream package
39
+ npx @henrychong-ai/mcp-neo4j-knowledge-graph
40
+ ```
41
+
42
+ ### Attribution
43
+
44
+ Original work by [Gannon Hall](https://github.com/gannonh) - [@gannonh/memento-mcp](https://github.com/gannonh/memento-mcp)
45
+ Fork maintained by [Henry Chong](https://github.com/henrychong-ai)
46
+
47
+ ---
48
+
49
+ ## Core Concepts
50
+
51
+ ### Entities
52
+
53
+ Entities are the primary nodes in the knowledge graph. Each entity has:
54
+
55
+ - A unique name (identifier)
56
+ - An entity type (e.g., "person", "organization", "event")
57
+ - A list of observations
58
+ - Vector embeddings (for semantic search)
59
+ - Complete version history
60
+
61
+ Example:
62
+
63
+ ```json
64
+ {
65
+ "name": "John_Smith",
66
+ "entityType": "person",
67
+ "observations": ["Speaks fluent Spanish"]
68
+ }
69
+ ```
70
+
71
+ ### Relations
72
+
73
+ Relations define directed connections between entities with enhanced properties:
74
+
75
+ - Strength indicators (0.0-1.0)
76
+ - Confidence levels (0.0-1.0)
77
+ - Rich metadata (source, timestamps, tags)
78
+ - Temporal awareness with version history
79
+ - Time-based confidence decay
80
+
81
+ Example:
82
+
83
+ ```json
84
+ {
85
+ "from": "John_Smith",
86
+ "to": "Anthropic",
87
+ "relationType": "works_at",
88
+ "strength": 0.9,
89
+ "confidence": 0.95,
90
+ "metadata": {
91
+ "source": "linkedin_profile",
92
+ "last_verified": "2025-03-21"
93
+ }
94
+ }
95
+ ```
96
+
97
+ ## Storage Backend
98
+
99
+ Memento MCP uses Neo4j as its storage backend, providing a unified solution for both graph storage and vector search capabilities.
100
+
101
+ ### Why Neo4j?
102
+
103
+ - **Unified Storage**: Consolidates both graph and vector storage into a single database
104
+ - **Native Graph Operations**: Built specifically for graph traversal and queries
105
+ - **Integrated Vector Search**: Vector similarity search for embeddings built directly into Neo4j
106
+ - **Scalability**: Better performance with large knowledge graphs
107
+ - **Simplified Architecture**: Clean design with a single database for all operations
108
+
109
+ ### Prerequisites
110
+
111
+ - Neo4j 5.13+ (required for vector search capabilities)
112
+
113
+ ### Neo4j Desktop Setup (Recommended)
114
+
115
+ The easiest way to get started with Neo4j is to use [Neo4j Desktop](https://neo4j.com/download/):
116
+
117
+ 1. Download and install Neo4j Desktop from <https://neo4j.com/download/>
118
+ 2. Create a new project
119
+ 3. Add a new database
120
+ 4. Set password to `memento_password` (or your preferred password)
121
+ 5. Start the database
122
+
123
+ The Neo4j database will be available at:
124
+
125
+ - **Bolt URI**: `bolt://127.0.0.1:7687` (for driver connections)
126
+ - **HTTP**: `http://127.0.0.1:7474` (for Neo4j Browser UI)
127
+ - **Default credentials**: username: `neo4j`, password: `memento_password` (or whatever you configured)
128
+
129
+ ### Neo4j Setup with Docker (Alternative)
130
+
131
+ Alternatively, you can use Docker Compose to run Neo4j:
132
+
133
+ ```bash
134
+ # Start Neo4j container
135
+ docker-compose up -d neo4j
136
+
137
+ # Stop Neo4j container
138
+ docker-compose stop neo4j
139
+
140
+ # Remove Neo4j container (preserves data)
141
+ docker-compose rm neo4j
142
+ ```
143
+
144
+ When using Docker, the Neo4j database will be available at:
145
+
146
+ - **Bolt URI**: `bolt://127.0.0.1:7687` (for driver connections)
147
+ - **HTTP**: `http://127.0.0.1:7474` (for Neo4j Browser UI)
148
+ - **Default credentials**: username: `neo4j`, password: `memento_password`
149
+
150
+ #### Data Persistence and Management
151
+
152
+ Neo4j data persists across container restarts and even version upgrades due to the Docker volume configuration in the `docker-compose.yml` file:
153
+
154
+ ```yaml
155
+ volumes:
156
+ - ./neo4j-data:/data
157
+ - ./neo4j-logs:/logs
158
+ - ./neo4j-import:/import
159
+ ```
160
+
161
+ These mappings ensure that:
162
+
163
+ - `/data` directory (contains all database files) persists on your host at `./neo4j-data`
164
+ - `/logs` directory persists on your host at `./neo4j-logs`
165
+ - `/import` directory (for importing data files) persists at `./neo4j-import`
166
+
167
+ You can modify these paths in your `docker-compose.yml` file to store data in different locations if needed.
168
+
169
+ ##### Upgrading Neo4j Version
170
+
171
+ You can change Neo4j editions and versions without losing data:
172
+
173
+ 1. Update the Neo4j image version in `docker-compose.yml`
174
+ 2. Restart the container with `docker-compose down && docker-compose up -d neo4j`
175
+ 3. Reinitialize the schema with `npm run neo4j:init`
176
+
177
+ The data will persist through this process as long as the volume mappings remain the same.
178
+
179
+ ##### Complete Database Reset
180
+
181
+ If you need to completely reset your Neo4j database:
182
+
183
+ ```bash
184
+ # Stop the container
185
+ docker-compose stop neo4j
186
+
187
+ # Remove the container
188
+ docker-compose rm -f neo4j
189
+
190
+ # Delete the data directory contents
191
+ rm -rf ./neo4j-data/*
192
+
193
+ # Restart the container
194
+ docker-compose up -d neo4j
195
+
196
+ # Reinitialize the schema
197
+ npm run neo4j:init
198
+ ```
199
+
200
+ ##### Backing Up Data
201
+
202
+ To back up your Neo4j data, you can simply copy the data directory:
203
+
204
+ ```bash
205
+ # Make a backup of the Neo4j data
206
+ cp -r ./neo4j-data ./neo4j-data-backup-$(date +%Y%m%d)
207
+ ```
208
+
209
+ ### Neo4j CLI Utilities
210
+
211
+ Memento MCP includes command-line utilities for managing Neo4j operations:
212
+
213
+ #### Testing Connection
214
+
215
+ Test the connection to your Neo4j database:
216
+
217
+ ```bash
218
+ # Test with default settings
219
+ npm run neo4j:test
220
+
221
+ # Test with custom settings
222
+ npm run neo4j:test -- --uri bolt://127.0.0.1:7687 --username myuser --password mypass --database neo4j
223
+ ```
224
+
225
+ #### Initializing Schema
226
+
227
+ For normal operation, Neo4j schema initialization happens automatically when Memento MCP connects to the database. You don't need to run any manual commands for regular usage.
228
+
229
+ The following commands are only necessary for development, testing, or advanced customization scenarios:
230
+
231
+ ```bash
232
+ # Initialize with default settings (only needed for development or troubleshooting)
233
+ npm run neo4j:init
234
+
235
+ # Initialize with custom vector dimensions
236
+ npm run neo4j:init -- --dimensions 768 --similarity euclidean
237
+
238
+ # Force recreation of all constraints and indexes
239
+ npm run neo4j:init -- --recreate
240
+
241
+ # Combine multiple options
242
+ npm run neo4j:init -- --vector-index custom_index --dimensions 384 --recreate
243
+ ```
244
+
245
+ ## Advanced Features
246
+
247
+ ### Semantic Search
248
+
249
+ Find semantically related entities based on meaning rather than just keywords:
250
+
251
+ - **Vector Embeddings**: Entities are automatically encoded into high-dimensional vector space using OpenAI's embedding models
252
+ - **Cosine Similarity**: Find related concepts even when they use different terminology
253
+ - **Configurable Thresholds**: Set minimum similarity scores to control result relevance
254
+ - **Cross-Modal Search**: Query with text to find relevant entities regardless of how they were described
255
+ - **Multi-Model Support**: Compatible with multiple embedding models (OpenAI text-embedding-3-small/large)
256
+ - **Contextual Retrieval**: Retrieve information based on semantic meaning rather than exact keyword matches
257
+ - **Optimized Defaults**: Tuned parameters for balance between precision and recall (0.6 similarity threshold, hybrid search enabled)
258
+ - **Hybrid Search**: Combines semantic and keyword search for more comprehensive results
259
+ - **Adaptive Search**: System intelligently chooses between vector-only, keyword-only, or hybrid search based on query characteristics and available data
260
+ - **Performance Optimization**: Prioritizes vector search for semantic understanding while maintaining fallback mechanisms for resilience
261
+ - **Query-Aware Processing**: Adjusts search strategy based on query complexity and available entity embeddings
262
+
263
+ ### Temporal Awareness
264
+
265
+ Track complete history of entities and relations with point-in-time graph retrieval:
266
+
267
+ - **Full Version History**: Every change to an entity or relation is preserved with timestamps
268
+ - **Point-in-Time Queries**: Retrieve the exact state of the knowledge graph at any moment in the past
269
+ - **Change Tracking**: Automatically records createdAt, updatedAt, validFrom, and validTo timestamps
270
+ - **Temporal Consistency**: Maintain a historically accurate view of how knowledge evolved
271
+ - **Non-Destructive Updates**: Updates create new versions rather than overwriting existing data
272
+ - **Time-Based Filtering**: Filter graph elements based on temporal criteria
273
+ - **History Exploration**: Investigate how specific information changed over time
274
+
275
+ ### Confidence Decay
276
+
277
+ Relations automatically decay in confidence over time based on configurable half-life:
278
+
279
+ - **Time-Based Decay**: Confidence in relations naturally decreases over time if not reinforced
280
+ - **Configurable Half-Life**: Define how quickly information becomes less certain (default: 30 days)
281
+ - **Minimum Confidence Floors**: Set thresholds to prevent over-decay of important information
282
+ - **Decay Metadata**: Each relation includes detailed decay calculation information
283
+ - **Non-Destructive**: Original confidence values are preserved alongside decayed values
284
+ - **Reinforcement Learning**: Relations regain confidence when reinforced by new observations
285
+ - **Reference Time Flexibility**: Calculate decay based on arbitrary reference times for historical analysis
286
+
287
+ ### Advanced Metadata
288
+
289
+ Rich metadata support for both entities and relations with custom fields:
290
+
291
+ - **Source Tracking**: Record where information originated (user input, analysis, external sources)
292
+ - **Confidence Levels**: Assign confidence scores (0.0-1.0) to relations based on certainty
293
+ - **Relation Strength**: Indicate importance or strength of relationships (0.0-1.0)
294
+ - **Temporal Metadata**: Track when information was added, modified, or verified
295
+ - **Custom Tags**: Add arbitrary tags for classification and filtering
296
+ - **Structured Data**: Store complex structured data within metadata fields
297
+ - **Query Support**: Search and filter based on metadata properties
298
+ - **Extensible Schema**: Add custom fields as needed without modifying the core data model
299
+
300
+ ## MCP API Tools
301
+
302
+ The following tools are available to LLM client hosts through the Model Context Protocol:
303
+
304
+ ### Entity Management
305
+
306
+ - **create_entities**
307
+
308
+ - Create multiple new entities in the knowledge graph
309
+ - Input: `entities` (array of objects)
310
+ - Each object contains:
311
+ - `name` (string): Entity identifier
312
+ - `entityType` (string): Type classification
313
+ - `observations` (string[]): Associated observations
314
+
315
+ - **add_observations**
316
+
317
+ - Add new observations to existing entities
318
+ - Input: `observations` (array of objects)
319
+ - Each object contains:
320
+ - `entityName` (string): Target entity
321
+ - `contents` (string[]): New observations to add
322
+
323
+ - **delete_entities**
324
+
325
+ - Remove entities and their relations
326
+ - Input: `entityNames` (string[])
327
+
328
+ - **delete_observations**
329
+ - Remove specific observations from entities
330
+ - Input: `deletions` (array of objects)
331
+ - Each object contains:
332
+ - `entityName` (string): Target entity
333
+ - `observations` (string[]): Observations to remove
334
+
335
+ ### Relation Management
336
+
337
+ - **create_relations**
338
+
339
+ - Create multiple new relations between entities with enhanced properties
340
+ - Input: `relations` (array of objects)
341
+ - Each object contains:
342
+ - `from` (string): Source entity name
343
+ - `to` (string): Target entity name
344
+ - `relationType` (string): Relationship type
345
+ - `strength` (number, optional): Relation strength (0.0-1.0)
346
+ - `confidence` (number, optional): Confidence level (0.0-1.0)
347
+ - `metadata` (object, optional): Custom metadata fields
348
+
349
+ - **get_relation**
350
+
351
+ - Get a specific relation with its enhanced properties
352
+ - Input:
353
+ - `from` (string): Source entity name
354
+ - `to` (string): Target entity name
355
+ - `relationType` (string): Relationship type
356
+
357
+ - **update_relation**
358
+
359
+ - Update an existing relation with enhanced properties
360
+ - Input: `relation` (object):
361
+ - Contains:
362
+ - `from` (string): Source entity name
363
+ - `to` (string): Target entity name
364
+ - `relationType` (string): Relationship type
365
+ - `strength` (number, optional): Relation strength (0.0-1.0)
366
+ - `confidence` (number, optional): Confidence level (0.0-1.0)
367
+ - `metadata` (object, optional): Custom metadata fields
368
+
369
+ - **delete_relations**
370
+ - Remove specific relations from the graph
371
+ - Input: `relations` (array of objects)
372
+ - Each object contains:
373
+ - `from` (string): Source entity name
374
+ - `to` (string): Target entity name
375
+ - `relationType` (string): Relationship type
376
+
377
+ ### Graph Operations
378
+
379
+ - **read_graph**
380
+
381
+ - Read the entire knowledge graph
382
+ - No input required
383
+
384
+ - **search_nodes**
385
+
386
+ - Search for nodes based on query
387
+ - Input: `query` (string)
388
+
389
+ - **open_nodes**
390
+ - Retrieve specific nodes by name
391
+ - Input: `names` (string[])
392
+
393
+ ### Semantic Search
394
+
395
+ - **semantic_search**
396
+
397
+ - Search for entities semantically using vector embeddings and similarity
398
+ - Input:
399
+ - `query` (string): The text query to search for semantically
400
+ - `limit` (number, optional): Maximum results to return (default: 10)
401
+ - `min_similarity` (number, optional): Minimum similarity threshold (0.0-1.0, default: 0.6)
402
+ - `entity_types` (string[], optional): Filter results by entity types
403
+ - `hybrid_search` (boolean, optional): Combine keyword and semantic search (default: true)
404
+ - `semantic_weight` (number, optional): Weight of semantic results in hybrid search (0.0-1.0, default: 0.6)
405
+ - Features:
406
+ - Intelligently selects optimal search method (vector, keyword, or hybrid) based on query context
407
+ - Gracefully handles queries with no semantic matches through fallback mechanisms
408
+ - Maintains high performance with automatic optimization decisions
409
+
410
+ - **get_entity_embedding**
411
+ - Get the vector embedding for a specific entity
412
+ - Input:
413
+ - `entity_name` (string): The name of the entity to get the embedding for
414
+
415
+ ### Temporal Features
416
+
417
+ - **get_entity_history**
418
+
419
+ - Get complete version history of an entity
420
+ - Input: `entityName` (string)
421
+
422
+ - **get_relation_history**
423
+
424
+ - Get complete version history of a relation
425
+ - Input:
426
+ - `from` (string): Source entity name
427
+ - `to` (string): Target entity name
428
+ - `relationType` (string): Relationship type
429
+
430
+ - **get_graph_at_time**
431
+
432
+ - Get the state of the graph at a specific timestamp
433
+ - Input: `timestamp` (number): Unix timestamp (milliseconds since epoch)
434
+
435
+ - **get_decayed_graph**
436
+ - Get graph with time-decayed confidence values
437
+ - Input: `options` (object, optional):
438
+ - `reference_time` (number): Reference timestamp for decay calculation (milliseconds since epoch)
439
+ - `decay_factor` (number): Optional decay factor override
440
+
441
+ ## Configuration
442
+
443
+ ### Environment Variables
444
+
445
+ Configure Memento MCP with these environment variables:
446
+
447
+ ```bash
448
+ # Neo4j Connection Settings
449
+ NEO4J_URI=bolt://127.0.0.1:7687
450
+ NEO4J_USERNAME=neo4j
451
+ NEO4J_PASSWORD=memento_password
452
+ NEO4J_DATABASE=neo4j
453
+
454
+ # Vector Search Configuration
455
+ NEO4J_VECTOR_INDEX=entity_embeddings
456
+ NEO4J_VECTOR_DIMENSIONS=1536
457
+ NEO4J_SIMILARITY_FUNCTION=cosine
458
+
459
+ # Embedding Service Configuration
460
+ MEMORY_STORAGE_TYPE=neo4j
461
+ OPENAI_API_KEY=your-openai-api-key
462
+ OPENAI_EMBEDDING_MODEL=text-embedding-3-small
463
+
464
+ # Debug Settings
465
+ DEBUG=true
466
+ ```
467
+
468
+ ### Command Line Options
469
+
470
+ The Neo4j CLI tools support the following options:
471
+
472
+ ```
473
+ --uri <uri> Neo4j server URI (default: bolt://127.0.0.1:7687)
474
+ --username <username> Neo4j username (default: neo4j)
475
+ --password <password> Neo4j password (default: memento_password)
476
+ --database <n> Neo4j database name (default: neo4j)
477
+ --vector-index <n> Vector index name (default: entity_embeddings)
478
+ --dimensions <number> Vector dimensions (default: 1536)
479
+ --similarity <function> Similarity function (cosine|euclidean) (default: cosine)
480
+ --recreate Force recreation of constraints and indexes
481
+ --no-debug Disable detailed output (debug is ON by default)
482
+ ```
483
+
484
+ ### Embedding Models
485
+
486
+ Available OpenAI embedding models:
487
+
488
+ - `text-embedding-3-small`: Efficient, cost-effective (1536 dimensions)
489
+ - `text-embedding-3-large`: Higher accuracy, more expensive (3072 dimensions)
490
+ - `text-embedding-ada-002`: Legacy model (1536 dimensions)
491
+
492
+ #### OpenAI API Configuration
493
+
494
+ To use semantic search, you'll need to configure OpenAI API credentials:
495
+
496
+ 1. Obtain an API key from [OpenAI](https://platform.openai.com/api-keys)
497
+ 2. Configure your environment with:
498
+
499
+ ```bash
500
+ # OpenAI API Key for embeddings
501
+ OPENAI_API_KEY=your-openai-api-key
502
+ # Default embedding model
503
+ OPENAI_EMBEDDING_MODEL=text-embedding-3-small
504
+ ```
505
+
506
+ > **Note**: For testing environments, the system will mock embedding generation if no API key is provided. However, using real embeddings is recommended for integration testing.
507
+
508
+ ## Integration with Claude Desktop
509
+
510
+ ### Configuration
511
+
512
+ Add this to your `claude_desktop_config.json`:
513
+
514
+ ```json
515
+ {
516
+ "mcpServers": {
517
+ "memento": {
518
+ "command": "npx",
519
+ "args": ["-y", "@henrychong-ai/mcp-neo4j-knowledge-graph"],
520
+ "env": {
521
+ "MEMORY_STORAGE_TYPE": "neo4j",
522
+ "NEO4J_URI": "bolt://127.0.0.1:7687",
523
+ "NEO4J_USERNAME": "neo4j",
524
+ "NEO4J_PASSWORD": "memento_password",
525
+ "NEO4J_DATABASE": "neo4j",
526
+ "NEO4J_VECTOR_INDEX": "entity_embeddings",
527
+ "NEO4J_VECTOR_DIMENSIONS": "1536",
528
+ "NEO4J_SIMILARITY_FUNCTION": "cosine",
529
+ "OPENAI_API_KEY": "your-openai-api-key",
530
+ "OPENAI_EMBEDDING_MODEL": "text-embedding-3-small",
531
+ "DEBUG": "true"
532
+ }
533
+ }
534
+ }
535
+ }
536
+ ```
537
+
538
+ Alternatively, for local development, you can use:
539
+
540
+ ```json
541
+ {
542
+ "mcpServers": {
543
+ "memento": {
544
+ "command": "/path/to/node",
545
+ "args": ["/path/to/memento-mcp/dist/index.js"],
546
+ "env": {
547
+ "MEMORY_STORAGE_TYPE": "neo4j",
548
+ "NEO4J_URI": "bolt://127.0.0.1:7687",
549
+ "NEO4J_USERNAME": "neo4j",
550
+ "NEO4J_PASSWORD": "memento_password",
551
+ "NEO4J_DATABASE": "neo4j",
552
+ "NEO4J_VECTOR_INDEX": "entity_embeddings",
553
+ "NEO4J_VECTOR_DIMENSIONS": "1536",
554
+ "NEO4J_SIMILARITY_FUNCTION": "cosine",
555
+ "OPENAI_API_KEY": "your-openai-api-key",
556
+ "OPENAI_EMBEDDING_MODEL": "text-embedding-3-small",
557
+ "DEBUG": "true"
558
+ }
559
+ }
560
+ }
561
+ }
562
+ ```
563
+
564
+ > **Important**: Always explicitly specify the embedding model in your Claude Desktop configuration to ensure consistent behavior.
565
+
566
+ ### Recommended System Prompts
567
+
568
+ For optimal integration with Claude, add these statements to your system prompt:
569
+
570
+ ```
571
+ You have access to the Memento MCP knowledge graph memory system, which provides you with persistent memory capabilities.
572
+ Your memory tools are provided by Memento MCP, a sophisticated knowledge graph implementation.
573
+ When asked about past conversations or user information, always check the Memento MCP knowledge graph first.
574
+ You should use semantic_search to find relevant information in your memory when answering questions.
575
+ ```
576
+
577
+ ### Testing Semantic Search
578
+
579
+ Once configured, Claude can access the semantic search capabilities through natural language:
580
+
581
+ 1. To create entities with semantic embeddings:
582
+
583
+ ```
584
+ User: "Remember that Python is a high-level programming language known for its readability and JavaScript is primarily used for web development."
585
+ ```
586
+
587
+ 2. To search semantically:
588
+
589
+ ```
590
+ User: "What programming languages do you know about that are good for web development?"
591
+ ```
592
+
593
+ 3. To retrieve specific information:
594
+
595
+ ```
596
+ User: "Tell me everything you know about Python."
597
+ ```
598
+
599
+ The power of this approach is that users can interact naturally, while the LLM handles the complexity of selecting and using the appropriate memory tools.
600
+
601
+ ### Real-World Applications
602
+
603
+ Memento's adaptive search capabilities provide practical benefits:
604
+
605
+ 1. **Query Versatility**: Users don't need to worry about how to phrase questions - the system adapts to different query types automatically
606
+
607
+ 2. **Failure Resilience**: Even when semantic matches aren't available, the system can fall back to alternative methods without user intervention
608
+
609
+ 3. **Performance Efficiency**: By intelligently selecting the optimal search method, the system balances performance and relevance for each query
610
+
611
+ 4. **Improved Context Retrieval**: LLM conversations benefit from better context retrieval as the system can find relevant information across complex knowledge graphs
612
+
613
+ For example, when a user asks "What do you know about machine learning?", the system can retrieve conceptually related entities even if they don't explicitly mention "machine learning" - perhaps entities about neural networks, data science, or specific algorithms. But if semantic search yields insufficient results, the system automatically adjusts its approach to ensure useful information is still returned.
614
+
615
+ ## Troubleshooting
616
+
617
+ ### Vector Search Diagnostics
618
+
619
+ Memento MCP includes built-in diagnostic capabilities to help troubleshoot vector search issues:
620
+
621
+ - **Embedding Verification**: The system checks if entities have valid embeddings and automatically generates them if missing
622
+ - **Vector Index Status**: Verifies that the vector index exists and is in the ONLINE state
623
+ - **Fallback Search**: If vector search fails, the system falls back to text-based search
624
+ - **Detailed Logging**: Comprehensive logging of vector search operations for troubleshooting
625
+
626
+ ### Debug Tools (when DEBUG=true)
627
+
628
+ Additional diagnostic tools become available when debug mode is enabled:
629
+
630
+ - **diagnose_vector_search**: Information about the Neo4j vector index, embedding counts, and search functionality
631
+ - **force_generate_embedding**: Forces the generation of an embedding for a specific entity
632
+ - **debug_embedding_config**: Information about the current embedding service configuration
633
+
634
+ ### Developer Reset
635
+
636
+ To completely reset your Neo4j database during development:
637
+
638
+ ```bash
639
+ # Stop the container (if using Docker)
640
+ docker-compose stop neo4j
641
+
642
+ # Remove the container (if using Docker)
643
+ docker-compose rm -f neo4j
644
+
645
+ # Delete the data directory (if using Docker)
646
+ rm -rf ./neo4j-data/*
647
+
648
+ # For Neo4j Desktop, right-click your database and select "Drop database"
649
+
650
+ # Restart the database
651
+ # For Docker:
652
+ docker-compose up -d neo4j
653
+
654
+ # For Neo4j Desktop:
655
+ # Click the "Start" button for your database
656
+
657
+ # Reinitialize the schema
658
+ npm run neo4j:init
659
+ ```
660
+
661
+ ## Building and Development
662
+
663
+ ```bash
664
+ # Clone the repository
665
+ git clone https://github.com/henrychong-ai/mcp-neo4j-knowledge-graph.git
666
+ cd mcp-neo4j-knowledge-graph
667
+
668
+ # Install dependencies
669
+ npm install
670
+
671
+ # Build the project
672
+ npm run build
673
+
674
+ # Run tests
675
+ npm test
676
+
677
+ # Check test coverage
678
+ npm run test:coverage
679
+ ```
680
+
681
+ ## Installation
682
+
683
+ ### Global Installation with npx (Recommended)
684
+
685
+ You can run this Neo4j Knowledge Graph MCP server directly using npx without installing it globally:
686
+
687
+ ```bash
688
+ npx -y @henrychong-ai/mcp-neo4j-knowledge-graph
689
+ ```
690
+
691
+ This method is recommended for use with Claude Desktop and other MCP-compatible clients.
692
+
693
+ ### Local Development
694
+
695
+ For development or contributing to the project:
696
+
697
+ ```bash
698
+ # Clone the repository
699
+ git clone https://github.com/henrychong-ai/mcp-neo4j-knowledge-graph.git
700
+ cd mcp-neo4j-knowledge-graph
701
+
702
+ # Install dependencies
703
+ npm install
704
+
705
+ # Build the project
706
+ npm run build
707
+
708
+ # Run tests
709
+ npm test
710
+ ```
711
+
712
+ ### Upstream Package
713
+
714
+ For the original upstream package (without bug fixes), see [@gannonh/memento-mcp](https://www.npmjs.com/package/@gannonh/memento-mcp)
715
+
716
+ ## License
717
+
718
+ MIT