@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,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface representing a vector embedding for semantic search
|
|
3
|
+
*/
|
|
4
|
+
export interface EntityEmbedding {
|
|
5
|
+
/**
|
|
6
|
+
* The embedding vector
|
|
7
|
+
*/
|
|
8
|
+
vector: number[];
|
|
9
|
+
/**
|
|
10
|
+
* Name/version of embedding model used
|
|
11
|
+
*/
|
|
12
|
+
model: string;
|
|
13
|
+
/**
|
|
14
|
+
* Timestamp when embedding was last updated
|
|
15
|
+
*/
|
|
16
|
+
lastUpdated: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Search filter for advanced filtering
|
|
20
|
+
*/
|
|
21
|
+
export interface SearchFilter {
|
|
22
|
+
/**
|
|
23
|
+
* Field to filter on
|
|
24
|
+
*/
|
|
25
|
+
field: string;
|
|
26
|
+
/**
|
|
27
|
+
* Filter operation
|
|
28
|
+
*/
|
|
29
|
+
operator: 'eq' | 'ne' | 'gt' | 'lt' | 'contains';
|
|
30
|
+
/**
|
|
31
|
+
* Filter value
|
|
32
|
+
*/
|
|
33
|
+
value: any;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Extended SearchOptions interface with semantic search capabilities
|
|
37
|
+
*/
|
|
38
|
+
export interface SemanticSearchOptions {
|
|
39
|
+
/**
|
|
40
|
+
* Use vector similarity for search
|
|
41
|
+
*/
|
|
42
|
+
semanticSearch?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Combine keyword and semantic search
|
|
45
|
+
*/
|
|
46
|
+
hybridSearch?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Balance between keyword vs semantic (0.0-1.0)
|
|
49
|
+
*/
|
|
50
|
+
semanticWeight?: number;
|
|
51
|
+
/**
|
|
52
|
+
* Minimum similarity threshold
|
|
53
|
+
*/
|
|
54
|
+
minSimilarity?: number;
|
|
55
|
+
/**
|
|
56
|
+
* Apply query expansion
|
|
57
|
+
*/
|
|
58
|
+
expandQuery?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Include facet information in results
|
|
61
|
+
*/
|
|
62
|
+
includeFacets?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Facets to include (entityType, etc.)
|
|
65
|
+
*/
|
|
66
|
+
facets?: string[];
|
|
67
|
+
/**
|
|
68
|
+
* Include score explanations
|
|
69
|
+
*/
|
|
70
|
+
includeExplanations?: boolean;
|
|
71
|
+
/**
|
|
72
|
+
* Additional filters
|
|
73
|
+
*/
|
|
74
|
+
filters?: SearchFilter[];
|
|
75
|
+
/**
|
|
76
|
+
* Maximum number of results to return
|
|
77
|
+
*/
|
|
78
|
+
limit?: number;
|
|
79
|
+
/**
|
|
80
|
+
* Number of results to skip (for pagination)
|
|
81
|
+
*/
|
|
82
|
+
offset?: number;
|
|
83
|
+
/**
|
|
84
|
+
* Include document content in search (when available)
|
|
85
|
+
*/
|
|
86
|
+
includeDocuments?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Use search result caching
|
|
89
|
+
*/
|
|
90
|
+
useCache?: boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Match details for search results
|
|
94
|
+
*/
|
|
95
|
+
export interface SearchMatch {
|
|
96
|
+
/**
|
|
97
|
+
* Field that matched
|
|
98
|
+
*/
|
|
99
|
+
field: string;
|
|
100
|
+
/**
|
|
101
|
+
* Score for this field
|
|
102
|
+
*/
|
|
103
|
+
score: number;
|
|
104
|
+
/**
|
|
105
|
+
* Text match locations
|
|
106
|
+
*/
|
|
107
|
+
textMatches?: Array<{
|
|
108
|
+
start: number;
|
|
109
|
+
end: number;
|
|
110
|
+
text: string;
|
|
111
|
+
}>;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Search result with relevance information
|
|
115
|
+
*/
|
|
116
|
+
export interface SearchResult {
|
|
117
|
+
/**
|
|
118
|
+
* The matching entity
|
|
119
|
+
*/
|
|
120
|
+
entity: any;
|
|
121
|
+
/**
|
|
122
|
+
* Overall relevance score
|
|
123
|
+
*/
|
|
124
|
+
score: number;
|
|
125
|
+
/**
|
|
126
|
+
* Match details
|
|
127
|
+
*/
|
|
128
|
+
matches?: SearchMatch[];
|
|
129
|
+
/**
|
|
130
|
+
* Explanation of the scoring (if requested)
|
|
131
|
+
*/
|
|
132
|
+
explanation?: any;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Search response with results and metadata
|
|
136
|
+
*/
|
|
137
|
+
export interface SearchResponse {
|
|
138
|
+
/**
|
|
139
|
+
* Search results
|
|
140
|
+
*/
|
|
141
|
+
results: SearchResult[];
|
|
142
|
+
/**
|
|
143
|
+
* Total number of matching results
|
|
144
|
+
*/
|
|
145
|
+
total: number;
|
|
146
|
+
/**
|
|
147
|
+
* Facet information
|
|
148
|
+
*/
|
|
149
|
+
facets?: Record<string, {
|
|
150
|
+
counts: Record<string, number>;
|
|
151
|
+
}>;
|
|
152
|
+
/**
|
|
153
|
+
* Search execution time in ms
|
|
154
|
+
*/
|
|
155
|
+
timeTaken: number;
|
|
156
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-embedding.js","sourceRoot":"","sources":["../../src/types/entity-embedding.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata for relations providing additional context and information
|
|
3
|
+
*/
|
|
4
|
+
export interface RelationMetadata {
|
|
5
|
+
/**
|
|
6
|
+
* Array of relation IDs that this relation was inferred from
|
|
7
|
+
*/
|
|
8
|
+
inferredFrom?: string[];
|
|
9
|
+
/**
|
|
10
|
+
* Timestamp when the relation was last accessed/retrieved
|
|
11
|
+
*/
|
|
12
|
+
lastAccessed?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Timestamp when the relation was created
|
|
15
|
+
*/
|
|
16
|
+
createdAt: number;
|
|
17
|
+
/**
|
|
18
|
+
* Timestamp when the relation was last updated
|
|
19
|
+
*/
|
|
20
|
+
updatedAt: number;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Represents a relationship between two entities in the knowledge graph
|
|
24
|
+
*/
|
|
25
|
+
export interface Relation {
|
|
26
|
+
/**
|
|
27
|
+
* The source entity name (where the relation starts)
|
|
28
|
+
*/
|
|
29
|
+
from: string;
|
|
30
|
+
/**
|
|
31
|
+
* The target entity name (where the relation ends)
|
|
32
|
+
*/
|
|
33
|
+
to: string;
|
|
34
|
+
/**
|
|
35
|
+
* The type of relationship between the entities
|
|
36
|
+
*/
|
|
37
|
+
relationType: string;
|
|
38
|
+
/**
|
|
39
|
+
* Optional strength of the relationship (0.0-1.0)
|
|
40
|
+
* Higher values indicate stronger relationships
|
|
41
|
+
*/
|
|
42
|
+
strength?: number;
|
|
43
|
+
/**
|
|
44
|
+
* Optional confidence score (0.0-1.0)
|
|
45
|
+
* Represents how confident the system is about this relationship
|
|
46
|
+
* Particularly useful for inferred relations
|
|
47
|
+
*/
|
|
48
|
+
confidence?: number;
|
|
49
|
+
/**
|
|
50
|
+
* Optional metadata providing additional context about the relation
|
|
51
|
+
*/
|
|
52
|
+
metadata?: RelationMetadata;
|
|
53
|
+
}
|
|
54
|
+
export declare namespace Relation {
|
|
55
|
+
function isRelation(obj: any): boolean;
|
|
56
|
+
function hasStrength(obj: any): boolean;
|
|
57
|
+
function hasConfidence(obj: any): boolean;
|
|
58
|
+
function hasValidMetadata(obj: any): boolean;
|
|
59
|
+
}
|
|
60
|
+
export declare class RelationValidator {
|
|
61
|
+
/**
|
|
62
|
+
* Validates if an object conforms to the Relation interface
|
|
63
|
+
*/
|
|
64
|
+
static isRelation(obj: any): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Checks if a relation has a strength value
|
|
67
|
+
*/
|
|
68
|
+
static hasStrength(obj: any): boolean;
|
|
69
|
+
/**
|
|
70
|
+
* Checks if a relation has a confidence value
|
|
71
|
+
*/
|
|
72
|
+
static hasConfidence(obj: any): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Checks if a relation has valid metadata
|
|
75
|
+
*/
|
|
76
|
+
static hasValidMetadata(obj: any): boolean;
|
|
77
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Add static methods to the Relation interface for JavaScript tests
|
|
2
|
+
// This allows tests to access validation methods directly from the interface
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
4
|
+
export var Relation;
|
|
5
|
+
(function (Relation) {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
function isRelation(obj) {
|
|
8
|
+
return RelationValidator.isRelation(obj);
|
|
9
|
+
}
|
|
10
|
+
Relation.isRelation = isRelation;
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
function hasStrength(obj) {
|
|
13
|
+
return RelationValidator.hasStrength(obj);
|
|
14
|
+
}
|
|
15
|
+
Relation.hasStrength = hasStrength;
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
17
|
+
function hasConfidence(obj) {
|
|
18
|
+
return RelationValidator.hasConfidence(obj);
|
|
19
|
+
}
|
|
20
|
+
Relation.hasConfidence = hasConfidence;
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
function hasValidMetadata(obj) {
|
|
23
|
+
return RelationValidator.hasValidMetadata(obj);
|
|
24
|
+
}
|
|
25
|
+
Relation.hasValidMetadata = hasValidMetadata;
|
|
26
|
+
})(Relation || (Relation = {}));
|
|
27
|
+
// Concrete class for JavaScript tests
|
|
28
|
+
export class RelationValidator {
|
|
29
|
+
/**
|
|
30
|
+
* Validates if an object conforms to the Relation interface
|
|
31
|
+
*/
|
|
32
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
|
+
static isRelation(obj) {
|
|
34
|
+
return (obj &&
|
|
35
|
+
typeof obj.from === 'string' &&
|
|
36
|
+
typeof obj.to === 'string' &&
|
|
37
|
+
typeof obj.relationType === 'string' &&
|
|
38
|
+
(obj.strength === undefined || typeof obj.strength === 'number') &&
|
|
39
|
+
(obj.confidence === undefined || typeof obj.confidence === 'number') &&
|
|
40
|
+
(obj.metadata === undefined || typeof obj.metadata === 'object'));
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Checks if a relation has a strength value
|
|
44
|
+
*/
|
|
45
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
|
+
static hasStrength(obj) {
|
|
47
|
+
return (this.isRelation(obj) &&
|
|
48
|
+
typeof obj.strength === 'number' &&
|
|
49
|
+
obj.strength >= 0 &&
|
|
50
|
+
obj.strength <= 1);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Checks if a relation has a confidence value
|
|
54
|
+
*/
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
56
|
+
static hasConfidence(obj) {
|
|
57
|
+
return (this.isRelation(obj) &&
|
|
58
|
+
typeof obj.confidence === 'number' &&
|
|
59
|
+
obj.confidence >= 0 &&
|
|
60
|
+
obj.confidence <= 1);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Checks if a relation has valid metadata
|
|
64
|
+
*/
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
66
|
+
static hasValidMetadata(obj) {
|
|
67
|
+
if (!this.isRelation(obj) || !obj.metadata) {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
const metadata = obj.metadata;
|
|
71
|
+
// Required fields
|
|
72
|
+
if (typeof metadata.createdAt !== 'number' || typeof metadata.updatedAt !== 'number') {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
// Optional fields
|
|
76
|
+
if (metadata.lastAccessed !== undefined && typeof metadata.lastAccessed !== 'number') {
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
if (metadata.inferredFrom !== undefined) {
|
|
80
|
+
if (!Array.isArray(metadata.inferredFrom)) {
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
// Verify all items in inferredFrom are strings
|
|
84
|
+
for (const id of metadata.inferredFrom) {
|
|
85
|
+
if (typeof id !== 'string') {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=relation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"relation.js","sourceRoot":"","sources":["../../src/types/relation.ts"],"names":[],"mappings":"AA+DA,oEAAoE;AACpE,6EAA6E;AAC7E,2DAA2D;AAC3D,MAAM,KAAW,QAAQ,CAoBxB;AApBD,WAAiB,QAAQ;IACvB,8DAA8D;IAC9D,SAAgB,UAAU,CAAC,GAAQ;QACjC,OAAO,iBAAiB,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC3C,CAAC;IAFe,mBAAU,aAEzB,CAAA;IAED,8DAA8D;IAC9D,SAAgB,WAAW,CAAC,GAAQ;QAClC,OAAO,iBAAiB,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IAC5C,CAAC;IAFe,oBAAW,cAE1B,CAAA;IAED,8DAA8D;IAC9D,SAAgB,aAAa,CAAC,GAAQ;QACpC,OAAO,iBAAiB,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;IAC9C,CAAC;IAFe,sBAAa,gBAE5B,CAAA;IAED,8DAA8D;IAC9D,SAAgB,gBAAgB,CAAC,GAAQ;QACvC,OAAO,iBAAiB,CAAC,gBAAg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,CAAC,gBAAgB,CAAC,GAAQ;QAC9B,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;YAC3C,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,QAAQ,GAAG,GAAG,CAAC,QAAQ,CAAC;QAE9B,kBAAkB;QAClB,IAAI,OAAO,QAAQ,CAAC,SAAS,KAAK,QAAQ,IAAI,OAAO,QAAQ,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YACrF,OAAO,KAAK,CAAC;QACf,CAAC;QAED,kBAAkB;QAClB,IAAI,QAAQ,CAAC,YAAY,KAAK,SAAS,IAAI,OAAO,QAAQ,CAAC,YAAY,KAAK,QAAQ,EAAE,CAAC;YACrF,OAAO,KAAK,CAAC;QACf,CAAC;QAED,IAAI,QAAQ,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACxC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC;gBAC1C,OAAO,KAAK,CAAC;YACf,CAAC;YAED,+CAA+C;YAC/C,KAAK,MAAM,EAAE,IAAI,QAAQ,CAAC,YAAY,EAAE,CAAC;gBACvC,IAAI,OAAO,EAAE,KAAK,QAAQ,EAAE,CAAC;oBAC3B,OAAO,KAAK,CAAC;gBACf,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for entities with temporal metadata
|
|
3
|
+
*/
|
|
4
|
+
import type { Entity } from '../KnowledgeGraphManager.js';
|
|
5
|
+
/**
|
|
6
|
+
* Represents an entity with temporal awareness capabilities
|
|
7
|
+
* Extends the base Entity interface with time-based properties
|
|
8
|
+
*/
|
|
9
|
+
export interface TemporalEntity extends Entity {
|
|
10
|
+
/**
|
|
11
|
+
* Unique identifier for the entity
|
|
12
|
+
*/
|
|
13
|
+
id?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Timestamp when the entity was created (milliseconds since epoch)
|
|
16
|
+
*/
|
|
17
|
+
createdAt: number;
|
|
18
|
+
/**
|
|
19
|
+
* Timestamp when the entity was last updated (milliseconds since epoch)
|
|
20
|
+
*/
|
|
21
|
+
updatedAt: number;
|
|
22
|
+
/**
|
|
23
|
+
* Optional start time for the validity period (milliseconds since epoch)
|
|
24
|
+
*/
|
|
25
|
+
validFrom?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Optional end time for the validity period (milliseconds since epoch)
|
|
28
|
+
*/
|
|
29
|
+
validTo?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Version number, incremented with each update
|
|
32
|
+
*/
|
|
33
|
+
version: number;
|
|
34
|
+
/**
|
|
35
|
+
* Optional identifier of the system or user that made the change
|
|
36
|
+
*/
|
|
37
|
+
changedBy?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare namespace TemporalEntity {
|
|
40
|
+
function isTemporalEntity(obj: any): boolean;
|
|
41
|
+
function hasValidTimeRange(obj: any): boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* TemporalEntityValidator class with validation methods
|
|
45
|
+
*/
|
|
46
|
+
export declare class TemporalEntityValidator {
|
|
47
|
+
/**
|
|
48
|
+
* Validates if an object conforms to the TemporalEntity interface
|
|
49
|
+
*/
|
|
50
|
+
static isTemporalEntity(obj: any): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Checks if an entity has a valid temporal range
|
|
53
|
+
*/
|
|
54
|
+
static hasValidTimeRange(obj: any): boolean;
|
|
55
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// Add static methods to the TemporalEntity interface for JavaScript tests
|
|
2
|
+
// This allows tests to access validation methods directly from the interface
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
4
|
+
export var TemporalEntity;
|
|
5
|
+
(function (TemporalEntity) {
|
|
6
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7
|
+
function isTemporalEntity(obj) {
|
|
8
|
+
return TemporalEntityValidator.isTemporalEntity(obj);
|
|
9
|
+
}
|
|
10
|
+
TemporalEntity.isTemporalEntity = isTemporalEntity;
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
|
+
function hasValidTimeRange(obj) {
|
|
13
|
+
return TemporalEntityValidator.hasValidTimeRange(obj);
|
|
14
|
+
}
|
|
15
|
+
TemporalEntity.hasValidTimeRange = hasValidTimeRange;
|
|
16
|
+
})(TemporalEntity || (TemporalEntity = {}));
|
|
17
|
+
/**
|
|
18
|
+
* TemporalEntityValidator class with validation methods
|
|
19
|
+
*/
|
|
20
|
+
export class TemporalEntityValidator {
|
|
21
|
+
/**
|
|
22
|
+
* Validates if an object conforms to the TemporalEntity interface
|
|
23
|
+
*/
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
static isTemporalEntity(obj) {
|
|
26
|
+
// First ensure it's a valid Entity
|
|
27
|
+
if (!obj ||
|
|
28
|
+
typeof obj.name !== 'string' ||
|
|
29
|
+
typeof obj.entityType !== 'string' ||
|
|
30
|
+
!Array.isArray(obj.observations)) {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
// Then check temporal properties
|
|
34
|
+
if (typeof obj.createdAt !== 'number' ||
|
|
35
|
+
typeof obj.updatedAt !== 'number' ||
|
|
36
|
+
typeof obj.version !== 'number') {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
// Optional properties type checking
|
|
40
|
+
if (obj.validFrom !== undefined && typeof obj.validFrom !== 'number') {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
if (obj.validTo !== undefined && typeof obj.validTo !== 'number') {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (obj.changedBy !== undefined && typeof obj.changedBy !== 'string') {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Checks if an entity has a valid temporal range
|
|
53
|
+
*/
|
|
54
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
55
|
+
static hasValidTimeRange(obj) {
|
|
56
|
+
if (!this.isTemporalEntity(obj)) {
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
// If both are defined, validFrom must be before validTo
|
|
60
|
+
if (obj.validFrom !== undefined && obj.validTo !== undefined) {
|
|
61
|
+
return obj.validFrom <= obj.validTo;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=temporalEntity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporalEntity.js","sourceRoot":"","sources":["../../src/types/temporalEntity.ts"],"names":[],"mappings":"AA8CA,0EAA0E;AAC1E,6EAA6E;AAC7E,2DAA2D;AAC3D,MAAM,KAAW,cAAc,CAU9B;AAVD,WAAiB,cAAc;IAC7B,8DAA8D;IAC9D,SAAgB,gBAAgB,CAAC,GAAQ;QACvC,OAAO,uBAAuB,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IACvD,CAAC;IAFe,+BAAgB,mBAE/B,CAAA;IAED,8DAA8D;IAC9D,SAAgB,iBAAiB,CAAC,GAAQ;QACxC,OAAO,uBAAuB,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;IACxD,CAAC;IAFe,gCAAiB,oBAEhC,CAAA;AACH,CAAC,EAVgB,cAAc,KAAd,cAAc,QAU9B;AAED;;GAEG;AACH,MAAM,OAAO,uBAAuB;IAClC;;OAEG;IACH,8DAA8D;IAC9D,MAAM,CAAC,gBAAgB,CAAC,GAAQ;QAC9B,mCAAmC;QACnC,IACE,CAAC,GAAG;YACJ,OAAO,GAAG,CAAC,IAAI,KAAK,QAAQ;YAC5B,OAAO,GAAG,CAAC,UAAU,KAAK,QAAQ;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{ type Relation } from './relation.js';
|
|
5
|
+
/**
|
|
6
|
+
* Represents a relationship with temporal awareness capabilities
|
|
7
|
+
* Extends the base Relation interface with time-based properties
|
|
8
|
+
*/
|
|
9
|
+
export interface TemporalRelation extends Relation {
|
|
10
|
+
/**
|
|
11
|
+
* Unique identifier for the relation
|
|
12
|
+
*/
|
|
13
|
+
id?: string;
|
|
14
|
+
/**
|
|
15
|
+
* Timestamp when the relation was created (milliseconds since epoch)
|
|
16
|
+
*/
|
|
17
|
+
createdAt: number;
|
|
18
|
+
/**
|
|
19
|
+
* Timestamp when the relation was last updated (milliseconds since epoch)
|
|
20
|
+
*/
|
|
21
|
+
updatedAt: number;
|
|
22
|
+
/**
|
|
23
|
+
* Optional start time for the validity period (milliseconds since epoch)
|
|
24
|
+
*/
|
|
25
|
+
validFrom?: number;
|
|
26
|
+
/**
|
|
27
|
+
* Optional end time for the validity period (milliseconds since epoch)
|
|
28
|
+
*/
|
|
29
|
+
validTo?: number;
|
|
30
|
+
/**
|
|
31
|
+
* Version number, incremented with each update
|
|
32
|
+
*/
|
|
33
|
+
version: number;
|
|
34
|
+
/**
|
|
35
|
+
* Optional identifier of the system or user that made the change
|
|
36
|
+
*/
|
|
37
|
+
changedBy?: string;
|
|
38
|
+
}
|
|
39
|
+
export declare namespace TemporalRelation {
|
|
40
|
+
function isTemporalRelation(obj: unknown): boolean;
|
|
41
|
+
function hasValidTimeRange(obj: unknown): boolean;
|
|
42
|
+
function isCurrentlyValid(obj: unknown, now?: number): boolean;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* TemporalRelationValidator class with validation methods
|
|
46
|
+
*/
|
|
47
|
+
export declare class TemporalRelationValidator {
|
|
48
|
+
/**
|
|
49
|
+
* Validates if an object conforms to the TemporalRelation interface
|
|
50
|
+
*/
|
|
51
|
+
static isTemporalRelation(obj: unknown): boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Checks if a relation has a valid temporal range
|
|
54
|
+
*/
|
|
55
|
+
static hasValidTimeRange(obj: unknown): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Checks if a relation is currently valid based on its temporal range
|
|
58
|
+
*/
|
|
59
|
+
static isCurrentlyValid(obj: unknown, now?: number): boolean;
|
|
60
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for relations with temporal metadata
|
|
3
|
+
*/
|
|
4
|
+
import { RelationValidator } from './relation.js';
|
|
5
|
+
// Add static methods to the TemporalRelation interface for JavaScript tests
|
|
6
|
+
// This allows tests to access validation methods directly from the interface
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
8
|
+
export var TemporalRelation;
|
|
9
|
+
(function (TemporalRelation) {
|
|
10
|
+
function isTemporalRelation(obj) {
|
|
11
|
+
return TemporalRelationValidator.isTemporalRelation(obj);
|
|
12
|
+
}
|
|
13
|
+
TemporalRelation.isTemporalRelation = isTemporalRelation;
|
|
14
|
+
function hasValidTimeRange(obj) {
|
|
15
|
+
return TemporalRelationValidator.hasValidTimeRange(obj);
|
|
16
|
+
}
|
|
17
|
+
TemporalRelation.hasValidTimeRange = hasValidTimeRange;
|
|
18
|
+
function isCurrentlyValid(obj, now = Date.now()) {
|
|
19
|
+
return TemporalRelationValidator.isCurrentlyValid(obj, now);
|
|
20
|
+
}
|
|
21
|
+
TemporalRelation.isCurrentlyValid = isCurrentlyValid;
|
|
22
|
+
})(TemporalRelation || (TemporalRelation = {}));
|
|
23
|
+
/**
|
|
24
|
+
* TemporalRelationValidator class with validation methods
|
|
25
|
+
*/
|
|
26
|
+
export class TemporalRelationValidator {
|
|
27
|
+
/**
|
|
28
|
+
* Validates if an object conforms to the TemporalRelation interface
|
|
29
|
+
*/
|
|
30
|
+
static isTemporalRelation(obj) {
|
|
31
|
+
// First ensure it's a valid Relation
|
|
32
|
+
if (!RelationValidator.isRelation(obj)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
// Use type assertion after validation
|
|
36
|
+
const temporalObj = obj;
|
|
37
|
+
// Then check temporal properties
|
|
38
|
+
if (typeof temporalObj.createdAt !== 'number' ||
|
|
39
|
+
typeof temporalObj.updatedAt !== 'number' ||
|
|
40
|
+
typeof temporalObj.version !== 'number') {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
// Optional properties type checking
|
|
44
|
+
if (temporalObj.validFrom !== undefined && typeof temporalObj.validFrom !== 'number') {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
if (temporalObj.validTo !== undefined && typeof temporalObj.validTo !== 'number') {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
if (temporalObj.changedBy !== undefined && typeof temporalObj.changedBy !== 'string') {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Checks if a relation has a valid temporal range
|
|
57
|
+
*/
|
|
58
|
+
static hasValidTimeRange(obj) {
|
|
59
|
+
if (!this.isTemporalRelation(obj)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
// Use type assertion after validation
|
|
63
|
+
const temporalObj = obj;
|
|
64
|
+
// If both are defined, validFrom must be before validTo
|
|
65
|
+
if (temporalObj.validFrom !== undefined && temporalObj.validTo !== undefined) {
|
|
66
|
+
return temporalObj.validFrom <= temporalObj.validTo;
|
|
67
|
+
}
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Checks if a relation is currently valid based on its temporal range
|
|
72
|
+
*/
|
|
73
|
+
static isCurrentlyValid(obj, now = Date.now()) {
|
|
74
|
+
if (!this.isTemporalRelation(obj)) {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
// Use type assertion after validation
|
|
78
|
+
const temporalObj = obj;
|
|
79
|
+
// Check if current time is within validity period
|
|
80
|
+
if (temporalObj.validFrom !== undefined && now < temporalObj.validFrom) {
|
|
81
|
+
return false; // Before valid period
|
|
82
|
+
}
|
|
83
|
+
if (temporalObj.validTo !== undefined && now > temporalObj.validTo) {
|
|
84
|
+
return false; // After valid period
|
|
85
|
+
}
|
|
86
|
+
return true;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=temporalRelation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"temporalRelation.js","sourceRoot":"","sources":["../../src/types/temporalRelation.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAiB,MAAM,eAAe,CAAC;AA2CjE,4EAA4E;AAC5E,6EAA6E;AAC7E,2DAA2D;AAC3D,MAAM,KAAW,gBAAgB,CAYhC;AAZD,WAAiB,gBAAgB;IAC/B,SAAgB,kBAAkB,CAAC,GAAY;QAC7C,OAAO,yBAAyB,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC;IAC3D,CAAC;IAFe,mCAAkB,qBAEjC,CAAA;IAED,SAAgB,iBAAiB,CAAC,GAAY;QAC5C,OAAO,yBAAyB,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;IAC1D,CAAC;IAFe,kCAAiB,oBAEhC,CAAA;IAED,SAAgB,gBAAgB,CAAC,GAAY,EAAE,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE;QAC7D,OAAO,yBAAyB,CAAC,gBAAgB,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9D,CAAC;IAFe,iCAAgB,mBAE/B,CAAA;AACH,CAAC,EAZgB,gBAAgB,KAAhB,gBAAgB,QAYhC;AAED;;GAEG;AACH,MAAM,OAAO,yBAAyB;IACpC;;OAEG;IACH,MAAM,CAAC,kBAAkB,CAAC,GAAY;QACpC,qCAAqC;QACrC,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,sCAAsC;QACtC,MAAM,WAAW,GAAG,GAAuB,CAAC;QAE5C,iCA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CAAC;QAED,sCAAsC;QACtC,MAAM,WAAW,GAAG,GAAuB,CAAC;QAE5C,kDAAkD;QAClD,IAAI,WAAW,CAAC,SAAS,KAAK,SAAS,IAAI,GAAG,GAAG,WAAW,CAAC,SAAS,EAAE,CAAC;YACvE,OAAO,KAAK,CAAC,CAAC,sBAAsB;QACtC,CAAC;QAED,IAAI,WAAW,CAAC,OAAO,KAAK,SAAS,IAAI,GAAG,GAAG,WAAW,CAAC,OAAO,EAAE,CAAC;YACnE,OAAO,KAAK,CAAC,CAAC,qBAAqB;QACrC,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Interface for optimized vector index operations
|
|
3
|
+
*/
|
|
4
|
+
export interface VectorIndex {
|
|
5
|
+
/**
|
|
6
|
+
* Add a vector to the index
|
|
7
|
+
* @param id Unique identifier for the vector
|
|
8
|
+
* @param vector The vector to add
|
|
9
|
+
*/
|
|
10
|
+
addVector(id: string, vector: number[]): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Search for nearest neighbors
|
|
13
|
+
* @param vector The query vector
|
|
14
|
+
* @param limit Maximum number of results to return
|
|
15
|
+
* @returns Promise resolving to array of results with id and similarity score
|
|
16
|
+
*/
|
|
17
|
+
search(vector: number[], limit: number): Promise<{
|
|
18
|
+
id: string;
|
|
19
|
+
score: number;
|
|
20
|
+
}[]>;
|
|
21
|
+
/**
|
|
22
|
+
* Remove a vector from the index
|
|
23
|
+
* @param id ID of the vector to remove
|
|
24
|
+
*/
|
|
25
|
+
removeVector(id: string): Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Get index statistics
|
|
28
|
+
* @returns Object with index statistics
|
|
29
|
+
*/
|
|
30
|
+
getStats(): {
|
|
31
|
+
totalVectors: number;
|
|
32
|
+
dimensionality: number;
|
|
33
|
+
indexType: string;
|
|
34
|
+
memoryUsage: number;
|
|
35
|
+
approximateSearch?: boolean;
|
|
36
|
+
quantized?: boolean;
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Enable or disable approximate nearest neighbor search
|
|
40
|
+
* @param enable Whether to enable approximate search
|
|
41
|
+
*/
|
|
42
|
+
setApproximateSearch(enable: boolean): void;
|
|
43
|
+
/**
|
|
44
|
+
* Enable or disable vector quantization for memory optimization
|
|
45
|
+
* @param enable Whether to enable quantization
|
|
46
|
+
*/
|
|
47
|
+
setQuantization(enable: boolean): void;
|
|
48
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-index.js","sourceRoot":"","sources":["../../src/types/vector-index.ts"],"names":[],"mappings":""}
|