@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.
- package/LICENSE +21 -0
- package/README.md +718 -0
- package/dist/KnowledgeGraphManager.d.ts +215 -0
- package/dist/KnowledgeGraphManager.js +910 -0
- package/dist/KnowledgeGraphManager.js.map +1 -0
- package/dist/callToolHandler.d.ts +5 -0
- package/dist/callToolHandler.js +26 -0
- package/dist/callToolHandler.js.map +1 -0
- package/dist/cli/neo4j-setup.d.ts +52 -0
- package/dist/cli/neo4j-setup.js +258 -0
- package/dist/cli/neo4j-setup.js.map +1 -0
- package/dist/config/paths.d.ts +13 -0
- package/dist/config/paths.js +41 -0
- package/dist/config/paths.js.map +1 -0
- package/dist/config/storage.d.ts +35 -0
- package/dist/config/storage.js +52 -0
- package/dist/config/storage.js.map +1 -0
- package/dist/embeddings/DefaultEmbeddingService.d.ts +64 -0
- package/dist/embeddings/DefaultEmbeddingService.js +139 -0
- package/dist/embeddings/DefaultEmbeddingService.js.map +1 -0
- package/dist/embeddings/EmbeddingJobManager.d.ts +212 -0
- package/dist/embeddings/EmbeddingJobManager.js +545 -0
- package/dist/embeddings/EmbeddingJobManager.js.map +1 -0
- package/dist/embeddings/EmbeddingService.d.ts +96 -0
- package/dist/embeddings/EmbeddingService.js +44 -0
- package/dist/embeddings/EmbeddingService.js.map +1 -0
- package/dist/embeddings/EmbeddingServiceFactory.d.ts +72 -0
- package/dist/embeddings/EmbeddingServiceFactory.js +147 -0
- package/dist/embeddings/EmbeddingServiceFactory.js.map +1 -0
- package/dist/embeddings/OpenAIEmbeddingService.d.ts +73 -0
- package/dist/embeddings/OpenAIEmbeddingService.js +195 -0
- package/dist/embeddings/OpenAIEmbeddingService.js.map +1 -0
- package/dist/embeddings/config.d.ts +83 -0
- package/dist/embeddings/config.js +65 -0
- package/dist/embeddings/config.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +220 -0
- package/dist/index.js.map +1 -0
- package/dist/server/handlers/callToolHandler.d.ts +20 -0
- package/dist/server/handlers/callToolHandler.js +505 -0
- package/dist/server/handlers/callToolHandler.js.map +1 -0
- package/dist/server/handlers/listToolsHandler.d.ts +7 -0
- package/dist/server/handlers/listToolsHandler.js +511 -0
- package/dist/server/handlers/listToolsHandler.js.map +1 -0
- package/dist/server/handlers/toolHandlers/addObservations.d.ts +12 -0
- package/dist/server/handlers/toolHandlers/addObservations.js +99 -0
- package/dist/server/handlers/toolHandlers/addObservations.js.map +1 -0
- package/dist/server/handlers/toolHandlers/createEntities.d.ts +12 -0
- package/dist/server/handlers/toolHandlers/createEntities.js +20 -0
- package/dist/server/handlers/toolHandlers/createEntities.js.map +1 -0
- package/dist/server/handlers/toolHandlers/createRelations.d.ts +12 -0
- package/dist/server/handlers/toolHandlers/createRelations.js +20 -0
- package/dist/server/handlers/toolHandlers/createRelations.js.map +1 -0
- package/dist/server/handlers/toolHandlers/deleteEntities.d.ts +12 -0
- package/dist/server/handlers/toolHandlers/deleteEntities.js +20 -0
- package/dist/server/handlers/toolHandlers/deleteEntities.js.map +1 -0
- package/dist/server/handlers/toolHandlers/index.d.ts +8 -0
- package/dist/server/handlers/toolHandlers/index.js +9 -0
- package/dist/server/handlers/toolHandlers/index.js.map +1 -0
- package/dist/server/handlers/toolHandlers/readGraph.d.ts +12 -0
- package/dist/server/handlers/toolHandlers/readGraph.js +20 -0
- package/dist/server/handlers/toolHandlers/readGraph.js.map +1 -0
- package/dist/server/setup.d.ts +8 -0
- package/dist/server/setup.js +48 -0
- package/dist/server/setup.js.map +1 -0
- package/dist/storage/FileStorageProvider.d.ts +125 -0
- package/dist/storage/FileStorageProvider.js +322 -0
- package/dist/storage/FileStorageProvider.js.map +1 -0
- package/dist/storage/SearchResultCache.d.ts +102 -0
- package/dist/storage/SearchResultCache.js +258 -0
- package/dist/storage/SearchResultCache.js.map +1 -0
- package/dist/storage/StorageProvider.d.ts +171 -0
- package/dist/storage/StorageProvider.js +46 -0
- package/dist/storage/StorageProvider.js.map +1 -0
- package/dist/storage/StorageProviderFactory.d.ts +63 -0
- package/dist/storage/StorageProviderFactory.js +113 -0
- package/dist/storage/StorageProviderFactory.js.map +1 -0
- package/dist/storage/VectorStoreFactory.d.ts +43 -0
- package/dist/storage/VectorStoreFactory.js +41 -0
- package/dist/storage/VectorStoreFactory.js.map +1 -0
- package/dist/storage/neo4j/Neo4jConfig.d.ts +37 -0
- package/dist/storage/neo4j/Neo4jConfig.js +13 -0
- package/dist/storage/neo4j/Neo4jConfig.js.map +1 -0
- package/dist/storage/neo4j/Neo4jConnectionManager.d.ts +40 -0
- package/dist/storage/neo4j/Neo4jConnectionManager.js +58 -0
- package/dist/storage/neo4j/Neo4jConnectionManager.js.map +1 -0
- package/dist/storage/neo4j/Neo4jSchemaManager.d.ts +74 -0
- package/dist/storage/neo4j/Neo4jSchemaManager.js +224 -0
- package/dist/storage/neo4j/Neo4jSchemaManager.js.map +1 -0
- package/dist/storage/neo4j/Neo4jStorageProvider.d.ts +225 -0
- package/dist/storage/neo4j/Neo4jStorageProvider.js +1900 -0
- package/dist/storage/neo4j/Neo4jStorageProvider.js.map +1 -0
- package/dist/storage/neo4j/Neo4jVectorStore.d.ts +80 -0
- package/dist/storage/neo4j/Neo4jVectorStore.js +396 -0
- package/dist/storage/neo4j/Neo4jVectorStore.js.map +1 -0
- package/dist/types/entity-embedding.d.ts +156 -0
- package/dist/types/entity-embedding.js +2 -0
- package/dist/types/entity-embedding.js.map +1 -0
- package/dist/types/relation.d.ts +77 -0
- package/dist/types/relation.js +93 -0
- package/dist/types/relation.js.map +1 -0
- package/dist/types/temporalEntity.d.ts +55 -0
- package/dist/types/temporalEntity.js +66 -0
- package/dist/types/temporalEntity.js.map +1 -0
- package/dist/types/temporalRelation.d.ts +60 -0
- package/dist/types/temporalRelation.js +89 -0
- package/dist/types/temporalRelation.js.map +1 -0
- package/dist/types/vector-index.d.ts +48 -0
- package/dist/types/vector-index.js +2 -0
- package/dist/types/vector-index.js.map +1 -0
- package/dist/types/vector-store.d.ts +16 -0
- package/dist/types/vector-store.js +2 -0
- package/dist/types/vector-store.js.map +1 -0
- package/dist/utils/fs.d.ts +2 -0
- package/dist/utils/fs.js +3 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/logger.d.ts +10 -0
- package/dist/utils/logger.js +35 -0
- package/dist/utils/logger.js.map +1 -0
- package/package.json +85 -0
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import { fs } from './utils/fs.js';
|
|
2
|
+
import type { StorageProvider } from './storage/StorageProvider.js';
|
|
3
|
+
import type { Relation } from './types/relation.js';
|
|
4
|
+
import type { EntityEmbedding } from './types/entity-embedding.js';
|
|
5
|
+
import type { EmbeddingJobManager } from './embeddings/EmbeddingJobManager.js';
|
|
6
|
+
import { type VectorStoreFactoryOptions } from './storage/VectorStoreFactory.js';
|
|
7
|
+
export interface Entity {
|
|
8
|
+
name: string;
|
|
9
|
+
entityType: string;
|
|
10
|
+
observations: string[];
|
|
11
|
+
embedding?: EntityEmbedding;
|
|
12
|
+
}
|
|
13
|
+
export { Relation } from './types/relation.js';
|
|
14
|
+
export { SemanticSearchOptions } from './types/entity-embedding.js';
|
|
15
|
+
export interface KnowledgeGraph {
|
|
16
|
+
entities: Entity[];
|
|
17
|
+
relations: Relation[];
|
|
18
|
+
total?: number;
|
|
19
|
+
timeTaken?: number;
|
|
20
|
+
diagnostics?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
export interface SearchResult {
|
|
23
|
+
entity: Entity;
|
|
24
|
+
score: number;
|
|
25
|
+
matches?: Array<{
|
|
26
|
+
field: string;
|
|
27
|
+
score: number;
|
|
28
|
+
textMatches?: Array<{
|
|
29
|
+
start: number;
|
|
30
|
+
end: number;
|
|
31
|
+
text: string;
|
|
32
|
+
}>;
|
|
33
|
+
}>;
|
|
34
|
+
explanation?: unknown;
|
|
35
|
+
}
|
|
36
|
+
export interface SearchResponse {
|
|
37
|
+
results: SearchResult[];
|
|
38
|
+
total: number;
|
|
39
|
+
facets?: Record<string, {
|
|
40
|
+
counts: Record<string, number>;
|
|
41
|
+
}>;
|
|
42
|
+
timeTaken: number;
|
|
43
|
+
}
|
|
44
|
+
interface KnowledgeGraphManagerOptions {
|
|
45
|
+
storageProvider?: StorageProvider;
|
|
46
|
+
memoryFilePath?: string;
|
|
47
|
+
embeddingJobManager?: EmbeddingJobManager;
|
|
48
|
+
vectorStoreOptions?: VectorStoreFactoryOptions;
|
|
49
|
+
}
|
|
50
|
+
export declare class KnowledgeGraphManager {
|
|
51
|
+
private memoryFilePath;
|
|
52
|
+
private storageProvider?;
|
|
53
|
+
private embeddingJobManager?;
|
|
54
|
+
private vectorStore?;
|
|
55
|
+
protected fsModule: typeof fs;
|
|
56
|
+
constructor(options?: KnowledgeGraphManagerOptions);
|
|
57
|
+
/**
|
|
58
|
+
* Initialize the vector store with the given options
|
|
59
|
+
*
|
|
60
|
+
* @param options - Options for the vector store
|
|
61
|
+
*/
|
|
62
|
+
private initializeVectorStore;
|
|
63
|
+
/**
|
|
64
|
+
* Ensure vector store is initialized
|
|
65
|
+
*
|
|
66
|
+
* @returns Promise that resolves when the vector store is initialized
|
|
67
|
+
*/
|
|
68
|
+
private ensureVectorStore;
|
|
69
|
+
/**
|
|
70
|
+
* Update an entity's embedding in both the storage provider and vector store
|
|
71
|
+
*
|
|
72
|
+
* @param entityName - Name of the entity
|
|
73
|
+
* @param embedding - The embedding to store
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
private updateEntityEmbedding;
|
|
77
|
+
/**
|
|
78
|
+
* Load the knowledge graph from storage
|
|
79
|
+
* @deprecated Direct file-based storage is deprecated. Use a StorageProvider implementation instead.
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
private loadGraph;
|
|
83
|
+
/**
|
|
84
|
+
* Save the knowledge graph to storage
|
|
85
|
+
* @deprecated Direct file-based storage is deprecated. Use a StorageProvider implementation instead.
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
private saveGraph;
|
|
89
|
+
createEntities(entities: Entity[]): Promise<Entity[]>;
|
|
90
|
+
createRelations(relations: Relation[]): Promise<Relation[]>;
|
|
91
|
+
deleteEntities(entityNames: string[]): Promise<void>;
|
|
92
|
+
deleteObservations(deletions: {
|
|
93
|
+
entityName: string;
|
|
94
|
+
observations: string[];
|
|
95
|
+
}[]): Promise<void>;
|
|
96
|
+
deleteRelations(relations: Relation[]): Promise<void>;
|
|
97
|
+
searchNodes(query: string): Promise<KnowledgeGraph>;
|
|
98
|
+
openNodes(names: string[]): Promise<KnowledgeGraph>;
|
|
99
|
+
/**
|
|
100
|
+
* Add observations to entities
|
|
101
|
+
* @param observations Array of observation objects
|
|
102
|
+
* @returns Promise resolving to array of added observations
|
|
103
|
+
*/
|
|
104
|
+
addObservations(observations: Array<{
|
|
105
|
+
entityName: string;
|
|
106
|
+
contents: string[];
|
|
107
|
+
strength?: number;
|
|
108
|
+
confidence?: number;
|
|
109
|
+
metadata?: Record<string, unknown>;
|
|
110
|
+
[key: string]: unknown;
|
|
111
|
+
}>): Promise<{
|
|
112
|
+
entityName: string;
|
|
113
|
+
addedObservations: string[];
|
|
114
|
+
}[]>;
|
|
115
|
+
/**
|
|
116
|
+
* Find entities that are semantically similar to the query
|
|
117
|
+
* @param query The query text to search for
|
|
118
|
+
* @param options Search options including limit and threshold
|
|
119
|
+
* @returns Promise resolving to an array of matches with scores
|
|
120
|
+
*/
|
|
121
|
+
findSimilarEntities(query: string, options?: {
|
|
122
|
+
limit?: number;
|
|
123
|
+
threshold?: number;
|
|
124
|
+
}): Promise<Array<{
|
|
125
|
+
name: string;
|
|
126
|
+
score: number;
|
|
127
|
+
}>>;
|
|
128
|
+
/**
|
|
129
|
+
* Read the entire knowledge graph
|
|
130
|
+
*
|
|
131
|
+
* This is an alias for loadGraph() for backward compatibility
|
|
132
|
+
* @returns The knowledge graph
|
|
133
|
+
*/
|
|
134
|
+
readGraph(): Promise<KnowledgeGraph>;
|
|
135
|
+
/**
|
|
136
|
+
* Search the knowledge graph with various options
|
|
137
|
+
*
|
|
138
|
+
* @param query The search query string
|
|
139
|
+
* @param options Search options
|
|
140
|
+
* @returns Promise resolving to a knowledge graph with search results
|
|
141
|
+
*/
|
|
142
|
+
search(query: string, options?: {
|
|
143
|
+
semanticSearch?: boolean;
|
|
144
|
+
hybridSearch?: boolean;
|
|
145
|
+
limit?: number;
|
|
146
|
+
threshold?: number;
|
|
147
|
+
minSimilarity?: number;
|
|
148
|
+
entityTypes?: string[];
|
|
149
|
+
facets?: string[];
|
|
150
|
+
offset?: number;
|
|
151
|
+
}): Promise<KnowledgeGraph>;
|
|
152
|
+
/**
|
|
153
|
+
* Perform semantic search on the knowledge graph
|
|
154
|
+
*
|
|
155
|
+
* @param query The search query string
|
|
156
|
+
* @param options Search options
|
|
157
|
+
* @returns Promise resolving to a knowledge graph with semantic search results
|
|
158
|
+
*/
|
|
159
|
+
private semanticSearch;
|
|
160
|
+
/**
|
|
161
|
+
* Get a specific relation by its from, to, and type identifiers
|
|
162
|
+
*
|
|
163
|
+
* @param from The name of the entity where the relation starts
|
|
164
|
+
* @param to The name of the entity where the relation ends
|
|
165
|
+
* @param relationType The type of the relation
|
|
166
|
+
* @returns The relation or null if not found
|
|
167
|
+
*/
|
|
168
|
+
getRelation(from: string, to: string, relationType: string): Promise<Relation | null>;
|
|
169
|
+
/**
|
|
170
|
+
* Update a relation with new properties
|
|
171
|
+
*
|
|
172
|
+
* @param relation The relation to update
|
|
173
|
+
* @returns The updated relation
|
|
174
|
+
*/
|
|
175
|
+
updateRelation(relation: Relation): Promise<Relation>;
|
|
176
|
+
/**
|
|
177
|
+
* Update an entity with new properties
|
|
178
|
+
*
|
|
179
|
+
* @param entityName The name of the entity to update
|
|
180
|
+
* @param updates Properties to update
|
|
181
|
+
* @returns The updated entity
|
|
182
|
+
*/
|
|
183
|
+
updateEntity(entityName: string, updates: Partial<Entity>): Promise<Entity>;
|
|
184
|
+
/**
|
|
185
|
+
* Get a version of the graph with confidences decayed based on time
|
|
186
|
+
*
|
|
187
|
+
* @returns Graph with decayed confidences
|
|
188
|
+
*/
|
|
189
|
+
getDecayedGraph(): Promise<KnowledgeGraph & {
|
|
190
|
+
decay_info?: Record<string, unknown>;
|
|
191
|
+
}>;
|
|
192
|
+
/**
|
|
193
|
+
* Get the history of an entity
|
|
194
|
+
*
|
|
195
|
+
* @param entityName The name of the entity to retrieve history for
|
|
196
|
+
* @returns Array of entity versions
|
|
197
|
+
*/
|
|
198
|
+
getEntityHistory(entityName: string): Promise<Entity[]>;
|
|
199
|
+
/**
|
|
200
|
+
* Get the history of a relation
|
|
201
|
+
*
|
|
202
|
+
* @param from The name of the entity where the relation starts
|
|
203
|
+
* @param to The name of the entity where the relation ends
|
|
204
|
+
* @param relationType The type of the relation
|
|
205
|
+
* @returns Array of relation versions
|
|
206
|
+
*/
|
|
207
|
+
getRelationHistory(from: string, to: string, relationType: string): Promise<Relation[]>;
|
|
208
|
+
/**
|
|
209
|
+
* Get the state of the knowledge graph at a specific point in time
|
|
210
|
+
*
|
|
211
|
+
* @param timestamp The timestamp (in milliseconds since epoch) to query the graph at
|
|
212
|
+
* @returns The knowledge graph as it existed at the specified time
|
|
213
|
+
*/
|
|
214
|
+
getGraphAtTime(timestamp: number): Promise<KnowledgeGraph>;
|
|
215
|
+
}
|