@henrychong-ai/mcp-neo4j-knowledge-graph 1.5.2 → 1.7.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.
- package/README.md +205 -0
- package/SETUP_AUTOMATION.md +596 -0
- package/dist/KnowledgeGraphManager.d.ts +35 -0
- package/dist/KnowledgeGraphManager.js +205 -0
- package/dist/KnowledgeGraphManager.js.map +1 -1
- package/dist/server/handlers/callToolHandler.js +8 -0
- package/dist/server/handlers/callToolHandler.js.map +1 -1
- package/dist/server/handlers/listToolsHandler.js +146 -0
- package/dist/server/handlers/listToolsHandler.js.map +1 -1
- package/dist/server/handlers/toolHandlers/addObservationsBatch.d.ts +19 -0
- package/dist/server/handlers/toolHandlers/addObservationsBatch.js +27 -0
- package/dist/server/handlers/toolHandlers/addObservationsBatch.js.map +1 -0
- package/dist/server/handlers/toolHandlers/createEntitiesBatch.d.ts +19 -0
- package/dist/server/handlers/toolHandlers/createEntitiesBatch.js +27 -0
- package/dist/server/handlers/toolHandlers/createEntitiesBatch.js.map +1 -0
- package/dist/server/handlers/toolHandlers/createRelationsBatch.d.ts +19 -0
- package/dist/server/handlers/toolHandlers/createRelationsBatch.js +27 -0
- package/dist/server/handlers/toolHandlers/createRelationsBatch.js.map +1 -0
- package/dist/server/handlers/toolHandlers/index.d.ts +4 -0
- package/dist/server/handlers/toolHandlers/index.js +4 -0
- package/dist/server/handlers/toolHandlers/index.js.map +1 -1
- package/dist/server/handlers/toolHandlers/updateEntitiesBatch.d.ts +19 -0
- package/dist/server/handlers/toolHandlers/updateEntitiesBatch.js +27 -0
- package/dist/server/handlers/toolHandlers/updateEntitiesBatch.js.map +1 -0
- package/dist/storage/StorageProvider.d.ts +29 -0
- package/dist/storage/StorageProvider.js.map +1 -1
- package/dist/storage/neo4j/Neo4jStorageProvider.d.ts +18 -0
- package/dist/storage/neo4j/Neo4jStorageProvider.js +559 -0
- package/dist/storage/neo4j/Neo4jStorageProvider.js.map +1 -1
- package/dist/types/batch-operations.d.ts +129 -0
- package/dist/types/batch-operations.js +8 -0
- package/dist/types/batch-operations.js.map +1 -0
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -8,6 +8,40 @@ Scalable, high-performance knowledge graph memory system with semantic retrieval
|
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
11
|
+
## 🚀 Quick Start with Claude Code
|
|
12
|
+
|
|
13
|
+
**Already have Claude Code running?** Paste this into your session:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
Read and execute the setup guide at henrychong.com/mcp-neo4j-kg/setup
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Claude Code will guide you through:
|
|
20
|
+
- ✓ Prerequisites check (Node.js, Docker)
|
|
21
|
+
- ✓ Neo4j database setup
|
|
22
|
+
- ✓ Configuration and environment variables
|
|
23
|
+
- ✓ Integration with Claude Desktop/Code
|
|
24
|
+
- ✓ Testing and verification
|
|
25
|
+
|
|
26
|
+
**Expected time:** 10-15 minutes
|
|
27
|
+
**No prior installation needed** - the automation handles everything!
|
|
28
|
+
|
|
29
|
+
---
|
|
30
|
+
|
|
31
|
+
### Manual Setup
|
|
32
|
+
|
|
33
|
+
If you prefer manual installation, see the detailed sections below for:
|
|
34
|
+
- [Installation](#installation) - npm/npx setup
|
|
35
|
+
- [Neo4j Setup](#storage-backend) - Docker or local database
|
|
36
|
+
- [Configuration](#configuration) - Environment variables
|
|
37
|
+
- [Claude Desktop](#integration-with-claude-desktop) - MCP client setup
|
|
38
|
+
- [Claude Code](#integration-with-claude-code) - CLI client setup
|
|
39
|
+
- [Testing](#testing-your-setup) - Verification steps
|
|
40
|
+
|
|
41
|
+
**Expected manual setup time:** 10-15 minutes
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
11
45
|
## Installation
|
|
12
46
|
|
|
13
47
|
### Global Installation with npx (Recommended)
|
|
@@ -300,6 +334,83 @@ Rich metadata support for both entities and relations with custom fields:
|
|
|
300
334
|
- **Query Support**: Search and filter based on metadata properties
|
|
301
335
|
- **Extensible Schema**: Add custom fields as needed without modifying the core data model
|
|
302
336
|
|
|
337
|
+
### Batch Operations
|
|
338
|
+
|
|
339
|
+
Optimized bulk operations providing 10-50x performance improvement over individual operations:
|
|
340
|
+
|
|
341
|
+
- **High-Performance Bulk Processing**: Batch operations use Neo4j's UNWIND clause for dramatic performance gains
|
|
342
|
+
- **Automatic Chunking**: Large batches are automatically split into optimal chunk sizes (default: 100 items)
|
|
343
|
+
- **Parallel Processing**: Independent operations (like embedding generation) can run concurrently
|
|
344
|
+
- **Progress Tracking**: Optional callbacks provide real-time progress updates for long-running operations
|
|
345
|
+
- **Partial Failure Handling**: Continue processing on failures with detailed error reports per item
|
|
346
|
+
- **Performance Metrics**: Each batch operation returns total time and per-item average timing
|
|
347
|
+
- **Transaction Safety**: Automatic rollback on failures ensures data consistency
|
|
348
|
+
|
|
349
|
+
**Available Batch Tools**:
|
|
350
|
+
- `create_entities_batch`: Create multiple entities in single operation
|
|
351
|
+
- `create_relations_batch`: Create multiple relations in single operation
|
|
352
|
+
- `add_observations_batch`: Add observations to multiple entities in single operation
|
|
353
|
+
- `update_entities_batch`: Update multiple entities in single operation
|
|
354
|
+
|
|
355
|
+
**Performance Comparison**:
|
|
356
|
+
```typescript
|
|
357
|
+
// Individual operations: ~50 seconds for 100 entities
|
|
358
|
+
for (const entity of entities) {
|
|
359
|
+
await createEntities([entity]);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
// Batch operation: ~1.5 seconds for 100 entities (33x faster)
|
|
364
|
+
await createEntitiesBatch(entities, {
|
|
365
|
+
maxBatchSize: 100,
|
|
366
|
+
enableParallel: true
|
|
367
|
+
});
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
**Configuration Options**:
|
|
371
|
+
- `maxBatchSize`: Control chunk size (default: 100)
|
|
372
|
+
- `enableParallel`: Reserved for future parallel chunk processing (embeddings always generated if service available)
|
|
373
|
+
- `onProgress`: Callback for progress tracking
|
|
374
|
+
|
|
375
|
+
**Cost Management:**
|
|
376
|
+
- Incremental approach minimizes API calls
|
|
377
|
+
- Only processes entities without embeddings
|
|
378
|
+
- Typical cost: ~$0.02 per 1M tokens
|
|
379
|
+
- Production cost: ~$0.0025 per daily run (for typical workloads)
|
|
380
|
+
|
|
381
|
+
This automation ensures semantic search remains highly effective as your knowledge graph grows, without requiring manual embedding regeneration.
|
|
382
|
+
|
|
383
|
+
### Query Result Caching (v1.5.0+)
|
|
384
|
+
|
|
385
|
+
Semantic search queries are automatically cached for improved performance:
|
|
386
|
+
|
|
387
|
+
**Cache Configuration:**
|
|
388
|
+
- **LRU (Least Recently Used) Strategy**: Automatically evicts oldest entries when full
|
|
389
|
+
- **Capacity**: 500 unique queries cached simultaneously
|
|
390
|
+
- **TTL (Time-To-Live)**: 5 minutes per cache entry
|
|
391
|
+
- **Size Limit**: 10,000 entities maximum across all cached results
|
|
392
|
+
- **Size Calculation**: Entity count + relation count
|
|
393
|
+
|
|
394
|
+
**Cache Behavior:**
|
|
395
|
+
- **Cache Hits**: Sub-millisecond response for repeated queries
|
|
396
|
+
- **Automatic Invalidation**: Cache cleared on mutations (create_entities, add_observations, delete_entities, etc.)
|
|
397
|
+
- **Intelligent Keying**: Considers query text, limit, similarity threshold, entity types, and hybrid config
|
|
398
|
+
- **Metrics Integration**: Cache hits/misses tracked via Prometheus (when enabled)
|
|
399
|
+
|
|
400
|
+
**Performance Impact:**
|
|
401
|
+
- **First Query**: Normal latency (~100-500ms depending on graph size)
|
|
402
|
+
- **Cached Query**: <1ms response time
|
|
403
|
+
- **Memory Usage**: Minimal - automatically bounded by size limits
|
|
404
|
+
- **Cache Miss Rate**: Typically <10% for conversational workloads
|
|
405
|
+
|
|
406
|
+
**Example Scenarios:**
|
|
407
|
+
- User asks "What programming languages do you know?" → Cache miss (~300ms)
|
|
408
|
+
- User asks "What programming languages do you know?" again → Cache hit (<1ms)
|
|
409
|
+
- User creates new entity → Cache cleared for consistency
|
|
410
|
+
- User asks "What programming languages do you know?" → Cache miss (~300ms, fresh results)
|
|
411
|
+
|
|
412
|
+
This caching layer provides significant performance improvements for repeated or similar queries without any configuration needed.
|
|
413
|
+
|
|
303
414
|
## MCP API Tools
|
|
304
415
|
|
|
305
416
|
The following tools are available to LLM client hosts through the Model Context Protocol:
|
|
@@ -684,6 +795,100 @@ The adaptive search capabilities provide practical benefits:
|
|
|
684
795
|
|
|
685
796
|
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.
|
|
686
797
|
|
|
798
|
+
## Integration with Claude Code
|
|
799
|
+
|
|
800
|
+
### Configuration
|
|
801
|
+
|
|
802
|
+
Add this to your `~/.claude.json`:
|
|
803
|
+
|
|
804
|
+
```json
|
|
805
|
+
{
|
|
806
|
+
"mcpServers": {
|
|
807
|
+
"neo4j-kg": {
|
|
808
|
+
"command": "npx",
|
|
809
|
+
"args": ["-y", "@henrychong-ai/mcp-neo4j-knowledge-graph"],
|
|
810
|
+
"env": {
|
|
811
|
+
"MEMORY_STORAGE_TYPE": "neo4j",
|
|
812
|
+
"NEO4J_URI": "bolt://127.0.0.1:7687",
|
|
813
|
+
"NEO4J_USERNAME": "neo4j",
|
|
814
|
+
"NEO4J_PASSWORD": "your_password_here",
|
|
815
|
+
"NEO4J_DATABASE": "neo4j",
|
|
816
|
+
"NEO4J_VECTOR_INDEX": "entity_embeddings",
|
|
817
|
+
"NEO4J_VECTOR_DIMENSIONS": "1536",
|
|
818
|
+
"NEO4J_SIMILARITY_FUNCTION": "cosine",
|
|
819
|
+
"OPENAI_API_KEY": "your-openai-api-key",
|
|
820
|
+
"OPENAI_EMBEDDING_MODEL": "text-embedding-3-small"
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
```
|
|
826
|
+
|
|
827
|
+
### Verify MCP Tools Available
|
|
828
|
+
|
|
829
|
+
In a Claude Code session, the MCP tools will be automatically available. You can verify by asking:
|
|
830
|
+
|
|
831
|
+
```
|
|
832
|
+
Show me the available MCP tools for the knowledge graph
|
|
833
|
+
```
|
|
834
|
+
|
|
835
|
+
You should see tools like:
|
|
836
|
+
- `mcp__kg__create_entities`
|
|
837
|
+
- `mcp__kg__create_relations`
|
|
838
|
+
- `mcp__kg__add_observations`
|
|
839
|
+
- `mcp__kg__search_nodes`
|
|
840
|
+
- `mcp__kg__semantic_search`
|
|
841
|
+
- And more...
|
|
842
|
+
|
|
843
|
+
## Testing Your Setup
|
|
844
|
+
|
|
845
|
+
### Step 1: Create Your First Entity
|
|
846
|
+
|
|
847
|
+
In Claude Desktop or Claude Code, say:
|
|
848
|
+
|
|
849
|
+
```
|
|
850
|
+
Use the knowledge graph to create an entity named "Python"
|
|
851
|
+
of type "Programming Language" with the observation
|
|
852
|
+
"General-purpose, high-level programming language known for readability"
|
|
853
|
+
```
|
|
854
|
+
|
|
855
|
+
### Step 2: Search for the Entity
|
|
856
|
+
|
|
857
|
+
```
|
|
858
|
+
Search the knowledge graph for "Python"
|
|
859
|
+
```
|
|
860
|
+
|
|
861
|
+
Claude should find your entity using the `mcp__kg__search_nodes` tool.
|
|
862
|
+
|
|
863
|
+
### Step 3: Add More Observations
|
|
864
|
+
|
|
865
|
+
```
|
|
866
|
+
Add these observations to the Python entity:
|
|
867
|
+
- Created by Guido van Rossum in 1991
|
|
868
|
+
- Popular for data science, web development, and automation
|
|
869
|
+
- Dynamic typing with interpreted execution
|
|
870
|
+
```
|
|
871
|
+
|
|
872
|
+
### Step 4: Verify in Neo4j Browser
|
|
873
|
+
|
|
874
|
+
Open `http://localhost:7474` and run:
|
|
875
|
+
|
|
876
|
+
```cypher
|
|
877
|
+
MATCH (e:Entity {name: "Python"})
|
|
878
|
+
WHERE e.validTo IS NULL
|
|
879
|
+
RETURN e
|
|
880
|
+
```
|
|
881
|
+
|
|
882
|
+
You should see your entity with all observations.
|
|
883
|
+
|
|
884
|
+
### Step 5: Test Semantic Search (If OpenAI API Key Configured)
|
|
885
|
+
|
|
886
|
+
```
|
|
887
|
+
Perform a semantic search for "programming languages for beginners"
|
|
888
|
+
```
|
|
889
|
+
|
|
890
|
+
The Python entity should appear in results based on semantic similarity.
|
|
891
|
+
|
|
687
892
|
## Troubleshooting
|
|
688
893
|
|
|
689
894
|
### Schema Constraint Configuration
|