memento-mcp-server 1.11.1 → 1.12.0-a
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.en.md +21 -6
- package/README.md +38 -7
- package/dist/algorithms/hybrid-search-engine.d.ts +34 -1
- package/dist/algorithms/hybrid-search-engine.d.ts.map +1 -1
- package/dist/algorithms/hybrid-search-engine.js +186 -17
- package/dist/algorithms/hybrid-search-engine.js.map +1 -1
- package/dist/algorithms/search-ranking.d.ts +15 -1
- package/dist/algorithms/search-ranking.d.ts.map +1 -1
- package/dist/algorithms/search-ranking.js +41 -4
- package/dist/algorithms/search-ranking.js.map +1 -1
- package/dist/config/environment.d.ts.map +1 -1
- package/dist/config/environment.js +4 -0
- package/dist/config/environment.js.map +1 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/config/index.js +6 -0
- package/dist/config/index.js.map +1 -1
- package/dist/config/ranking-weights-loader.d.ts +37 -0
- package/dist/config/ranking-weights-loader.d.ts.map +1 -0
- package/dist/config/ranking-weights-loader.js +109 -0
- package/dist/config/ranking-weights-loader.js.map +1 -0
- package/dist/constants/relation-constants.d.ts +95 -0
- package/dist/constants/relation-constants.d.ts.map +1 -0
- package/dist/constants/relation-constants.js +95 -0
- package/dist/constants/relation-constants.js.map +1 -0
- package/dist/database/migration/migrations/005-relation-engine-schema.d.ts +65 -0
- package/dist/database/migration/migrations/005-relation-engine-schema.d.ts.map +1 -0
- package/dist/database/migration/migrations/005-relation-engine-schema.js +295 -0
- package/dist/database/migration/migrations/005-relation-engine-schema.js.map +1 -0
- package/dist/database/migration/migrations/005-relation-engine-schema.sql +64 -0
- package/dist/services/anchor/anchor-interfaces.d.ts +1 -0
- package/dist/services/anchor/anchor-interfaces.d.ts.map +1 -1
- package/dist/services/anchor/anchor-interfaces.js.map +1 -1
- package/dist/services/anchor/anchor-search-service.d.ts +16 -0
- package/dist/services/anchor/anchor-search-service.d.ts.map +1 -1
- package/dist/services/anchor/anchor-search-service.js +136 -17
- package/dist/services/anchor/anchor-search-service.js.map +1 -1
- package/dist/services/batch-scheduler.d.ts +11 -0
- package/dist/services/batch-scheduler.d.ts.map +1 -1
- package/dist/services/batch-scheduler.js +99 -0
- package/dist/services/batch-scheduler.js.map +1 -1
- package/dist/services/llm-based-relation-extractor.d.ts +156 -0
- package/dist/services/llm-based-relation-extractor.d.ts.map +1 -0
- package/dist/services/llm-based-relation-extractor.js +1350 -0
- package/dist/services/llm-based-relation-extractor.js.map +1 -0
- package/dist/services/relation-extractor.d.ts +73 -0
- package/dist/services/relation-extractor.d.ts.map +1 -0
- package/dist/services/relation-extractor.js +231 -0
- package/dist/services/relation-extractor.js.map +1 -0
- package/dist/services/relation-graph.d.ts +275 -0
- package/dist/services/relation-graph.d.ts.map +1 -0
- package/dist/services/relation-graph.js +869 -0
- package/dist/services/relation-graph.js.map +1 -0
- package/dist/services/relation-quality-validator.d.ts +211 -0
- package/dist/services/relation-quality-validator.d.ts.map +1 -0
- package/dist/services/relation-quality-validator.js +415 -0
- package/dist/services/relation-quality-validator.js.map +1 -0
- package/dist/services/rule-based-relation-extractor.d.ts +66 -0
- package/dist/services/rule-based-relation-extractor.d.ts.map +1 -0
- package/dist/services/rule-based-relation-extractor.js +258 -0
- package/dist/services/rule-based-relation-extractor.js.map +1 -0
- package/dist/tools/add-relation-tool.d.ts +34 -0
- package/dist/tools/add-relation-tool.d.ts.map +1 -0
- package/dist/tools/add-relation-tool.js +163 -0
- package/dist/tools/add-relation-tool.js.map +1 -0
- package/dist/tools/extract-relations-tool.d.ts +28 -0
- package/dist/tools/extract-relations-tool.d.ts.map +1 -0
- package/dist/tools/extract-relations-tool.js +159 -0
- package/dist/tools/extract-relations-tool.js.map +1 -0
- package/dist/tools/get-relations-tool.d.ts +34 -0
- package/dist/tools/get-relations-tool.d.ts.map +1 -0
- package/dist/tools/get-relations-tool.js +155 -0
- package/dist/tools/get-relations-tool.js.map +1 -0
- package/dist/tools/index.d.ts +6 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +16 -2
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/remember-tool.d.ts +17 -0
- package/dist/tools/remember-tool.d.ts.map +1 -1
- package/dist/tools/remember-tool.js +195 -26
- package/dist/tools/remember-tool.js.map +1 -1
- package/dist/tools/remove-relation-tool.d.ts +45 -0
- package/dist/tools/remove-relation-tool.d.ts.map +1 -0
- package/dist/tools/remove-relation-tool.js +142 -0
- package/dist/tools/remove-relation-tool.js.map +1 -0
- package/dist/tools/search-local-tool.d.ts.map +1 -1
- package/dist/tools/search-local-tool.js +10 -3
- package/dist/tools/search-local-tool.js.map +1 -1
- package/dist/tools/types.d.ts +2 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/tools/visualize-relations-tool.d.ts +46 -0
- package/dist/tools/visualize-relations-tool.d.ts.map +1 -0
- package/dist/tools/visualize-relations-tool.js +157 -0
- package/dist/tools/visualize-relations-tool.js.map +1 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/relation-graph.d.ts +215 -0
- package/dist/types/relation-graph.d.ts.map +1 -0
- package/dist/types/relation-graph.js +6 -0
- package/dist/types/relation-graph.js.map +1 -0
- package/dist/types/relation.d.ts +112 -0
- package/dist/types/relation.d.ts.map +1 -0
- package/dist/types/relation.js +67 -0
- package/dist/types/relation.js.map +1 -0
- package/dist/utils/cache-key-generator.d.ts +63 -0
- package/dist/utils/cache-key-generator.d.ts.map +1 -0
- package/dist/utils/cache-key-generator.js +76 -0
- package/dist/utils/cache-key-generator.js.map +1 -0
- package/dist/utils/database.d.ts.map +1 -1
- package/dist/utils/database.js +37 -17
- package/dist/utils/database.js.map +1 -1
- package/dist/utils/relation-visualizer.d.ts +81 -0
- package/dist/utils/relation-visualizer.d.ts.map +1 -0
- package/dist/utils/relation-visualizer.js +239 -0
- package/dist/utils/relation-visualizer.js.map +1 -0
- package/dist/utils/type-guards.d.ts +100 -0
- package/dist/utils/type-guards.d.ts.map +1 -0
- package/dist/utils/type-guards.js +144 -0
- package/dist/utils/type-guards.js.map +1 -0
- package/package.json +7 -2
- package/scripts/generate-relation-report.ts +481 -0
- package/scripts/weekly-relation-validation.ts +423 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration: 005 - Relation Engine Schema
|
|
3
|
+
* Description: Create memory_relation and relation_type_registry tables for semantic relation engine
|
|
4
|
+
* Version: 5.0
|
|
5
|
+
* Date: 2025-01-XX
|
|
6
|
+
*/
|
|
7
|
+
import type Database from 'better-sqlite3';
|
|
8
|
+
import type { Migration } from '../types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Relation Engine Schema Migration
|
|
11
|
+
*
|
|
12
|
+
* This migration:
|
|
13
|
+
* 1. Creates memory_relation table for storing semantic relations between memories
|
|
14
|
+
* 2. Creates relation_type_registry table for managing relation types
|
|
15
|
+
* 3. Creates indexes for performance optimization
|
|
16
|
+
* 4. Inserts initial relation types (CAUSES, DEPENDS_ON, FOLLOWS, CONTRASTS_WITH, REFERENCES, BELONGS_TO)
|
|
17
|
+
* 5. Migrates existing memory_link data to memory_relation
|
|
18
|
+
*/
|
|
19
|
+
export declare class RelationEngineSchemaMigration implements Migration {
|
|
20
|
+
version: string;
|
|
21
|
+
name: string;
|
|
22
|
+
description: string;
|
|
23
|
+
/**
|
|
24
|
+
* Load SQL file content
|
|
25
|
+
*/
|
|
26
|
+
private loadSQLFile;
|
|
27
|
+
/**
|
|
28
|
+
* Execute SQL script
|
|
29
|
+
* Removes transaction commands (BEGIN TRANSACTION, COMMIT) as MigrationRunner manages transactions
|
|
30
|
+
*/
|
|
31
|
+
private executeSQL;
|
|
32
|
+
/**
|
|
33
|
+
* Check if table exists
|
|
34
|
+
*/
|
|
35
|
+
private tableExists;
|
|
36
|
+
/**
|
|
37
|
+
* Check if index exists
|
|
38
|
+
*/
|
|
39
|
+
private indexExists;
|
|
40
|
+
/**
|
|
41
|
+
* Check if column exists in table
|
|
42
|
+
*/
|
|
43
|
+
private columnExists;
|
|
44
|
+
/**
|
|
45
|
+
* Map old memory_link relation_type to new memory_relation relation_type
|
|
46
|
+
*/
|
|
47
|
+
private mapRelationType;
|
|
48
|
+
/**
|
|
49
|
+
* Validate before migration
|
|
50
|
+
*/
|
|
51
|
+
validateBefore(db: Database.Database): Promise<void>;
|
|
52
|
+
/**
|
|
53
|
+
* Execute migration (Up)
|
|
54
|
+
*/
|
|
55
|
+
up(db: Database.Database): Promise<void>;
|
|
56
|
+
/**
|
|
57
|
+
* Rollback migration (Down)
|
|
58
|
+
*/
|
|
59
|
+
down(db: Database.Database): Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Validate after migration
|
|
62
|
+
*/
|
|
63
|
+
validateAfter(db: Database.Database): Promise<void>;
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=005-relation-engine-schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"005-relation-engine-schema.d.ts","sourceRoot":"","sources":["../../../../src/database/migration/migrations/005-relation-engine-schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAI3C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAM7C;;;;;;;;;GASG;AACH,qBAAa,6BAA8B,YAAW,SAAS;IAC7D,OAAO,SAAS;IAChB,IAAI,SAA4B;IAChC,WAAW,SAA2F;IAEtG;;OAEG;IACH,OAAO,CAAC,WAAW;IAKnB;;;OAGG;IACH,OAAO,CAAC,UAAU;IAsBlB;;OAEG;IACH,OAAO,CAAC,WAAW;IAQnB;;OAEG;IACH,OAAO,CAAC,WAAW;IAQnB;;OAEG;IACH,OAAO,CAAC,YAAY;IAKpB;;OAEG;IACH,OAAO,CAAC,eAAe;IAUvB;;OAEG;IACG,cAAc,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IA4B1D;;OAEG;IACG,EAAE,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAkE9C;;OAEG;IACG,IAAI,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;IAwBhD;;OAEG;IACG,aAAa,CAAC,EAAE,EAAE,QAAQ,CAAC,QAAQ,GAAG,OAAO,CAAC,IAAI,CAAC;CAsH1D"}
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Migration: 005 - Relation Engine Schema
|
|
3
|
+
* Description: Create memory_relation and relation_type_registry tables for semantic relation engine
|
|
4
|
+
* Version: 5.0
|
|
5
|
+
* Date: 2025-01-XX
|
|
6
|
+
*/
|
|
7
|
+
import { readFileSync } from 'fs';
|
|
8
|
+
import { join, dirname } from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
import { DependencyValidator } from '../dependency-validator.js';
|
|
11
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
12
|
+
const __dirname = dirname(__filename);
|
|
13
|
+
/**
|
|
14
|
+
* Relation Engine Schema Migration
|
|
15
|
+
*
|
|
16
|
+
* This migration:
|
|
17
|
+
* 1. Creates memory_relation table for storing semantic relations between memories
|
|
18
|
+
* 2. Creates relation_type_registry table for managing relation types
|
|
19
|
+
* 3. Creates indexes for performance optimization
|
|
20
|
+
* 4. Inserts initial relation types (CAUSES, DEPENDS_ON, FOLLOWS, CONTRASTS_WITH, REFERENCES, BELONGS_TO)
|
|
21
|
+
* 5. Migrates existing memory_link data to memory_relation
|
|
22
|
+
*/
|
|
23
|
+
export class RelationEngineSchemaMigration {
|
|
24
|
+
version = '5.0';
|
|
25
|
+
name = 'relation-engine-schema';
|
|
26
|
+
description = 'Create memory_relation and relation_type_registry tables for semantic relation engine';
|
|
27
|
+
/**
|
|
28
|
+
* Load SQL file content
|
|
29
|
+
*/
|
|
30
|
+
loadSQLFile(filename) {
|
|
31
|
+
const filePath = join(__dirname, filename);
|
|
32
|
+
return readFileSync(filePath, 'utf-8');
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Execute SQL script
|
|
36
|
+
* Removes transaction commands (BEGIN TRANSACTION, COMMIT) as MigrationRunner manages transactions
|
|
37
|
+
*/
|
|
38
|
+
executeSQL(db, sql) {
|
|
39
|
+
// MigrationRunner가 트랜잭션을 관리하므로 SQL에서 트랜잭션 명령 제거
|
|
40
|
+
let cleanedSQL = sql
|
|
41
|
+
// BEGIN TRANSACTION 제거
|
|
42
|
+
.replace(/BEGIN\s+TRANSACTION\s*;/gi, '')
|
|
43
|
+
// COMMIT 제거
|
|
44
|
+
.replace(/COMMIT\s*;/gi, '')
|
|
45
|
+
// PRAGMA foreign_keys 명령은 유지 (트랜잭션 외부에서도 작동)
|
|
46
|
+
.trim();
|
|
47
|
+
// 빈 줄 제거 및 정리
|
|
48
|
+
cleanedSQL = cleanedSQL
|
|
49
|
+
.split('\n')
|
|
50
|
+
.map(line => line.trim())
|
|
51
|
+
.filter(line => line.length > 0)
|
|
52
|
+
.join('\n');
|
|
53
|
+
if (cleanedSQL.length > 0) {
|
|
54
|
+
db.exec(cleanedSQL);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if table exists
|
|
59
|
+
*/
|
|
60
|
+
tableExists(db, tableName) {
|
|
61
|
+
const result = db.prepare(`
|
|
62
|
+
SELECT name FROM sqlite_master
|
|
63
|
+
WHERE type='table' AND name=?
|
|
64
|
+
`).get(tableName);
|
|
65
|
+
return !!result;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if index exists
|
|
69
|
+
*/
|
|
70
|
+
indexExists(db, indexName) {
|
|
71
|
+
const result = db.prepare(`
|
|
72
|
+
SELECT name FROM sqlite_master
|
|
73
|
+
WHERE type='index' AND name=?
|
|
74
|
+
`).get(indexName);
|
|
75
|
+
return !!result;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Check if column exists in table
|
|
79
|
+
*/
|
|
80
|
+
columnExists(db, tableName, columnName) {
|
|
81
|
+
const columns = db.prepare(`PRAGMA table_info(${tableName})`).all();
|
|
82
|
+
return columns.some(col => col.name === columnName);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Map old memory_link relation_type to new memory_relation relation_type
|
|
86
|
+
*/
|
|
87
|
+
mapRelationType(oldType) {
|
|
88
|
+
const mapping = {
|
|
89
|
+
'cause_of': 'CAUSES',
|
|
90
|
+
'derived_from': 'DEPENDS_ON',
|
|
91
|
+
'contradicts': 'CONTRASTS_WITH'
|
|
92
|
+
// 'duplicates'는 새로운 관계 유형으로 처리하지 않음 (제거)
|
|
93
|
+
};
|
|
94
|
+
return mapping[oldType] || null;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Validate before migration
|
|
98
|
+
*/
|
|
99
|
+
async validateBefore(db) {
|
|
100
|
+
// Check if memory_item table exists (required for foreign key)
|
|
101
|
+
if (!this.tableExists(db, 'memory_item')) {
|
|
102
|
+
throw new Error('memory_item table does not exist. Cannot proceed with migration.');
|
|
103
|
+
}
|
|
104
|
+
// Check if migration has already been applied
|
|
105
|
+
if (this.tableExists(db, 'memento_schema_version')) {
|
|
106
|
+
const version = db.prepare(`
|
|
107
|
+
SELECT version FROM memento_schema_version WHERE version = ?
|
|
108
|
+
`).get('5.0');
|
|
109
|
+
if (version) {
|
|
110
|
+
throw new Error('Migration 005 has already been applied. Current schema version: 5.0');
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Check if memory_relation table already exists (should not exist)
|
|
114
|
+
if (this.tableExists(db, 'memory_relation')) {
|
|
115
|
+
throw new Error('memory_relation table already exists. Migration may have been partially applied.');
|
|
116
|
+
}
|
|
117
|
+
// Check if relation_type_registry table already exists (should not exist)
|
|
118
|
+
if (this.tableExists(db, 'relation_type_registry')) {
|
|
119
|
+
throw new Error('relation_type_registry table already exists. Migration may have been partially applied.');
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Execute migration (Up)
|
|
124
|
+
*/
|
|
125
|
+
async up(db) {
|
|
126
|
+
// 1. Load and execute SQL script
|
|
127
|
+
const sqlScript = this.loadSQLFile('005-relation-engine-schema.sql');
|
|
128
|
+
this.executeSQL(db, sqlScript);
|
|
129
|
+
// 2. Migrate existing memory_link data to memory_relation
|
|
130
|
+
if (this.tableExists(db, 'memory_link')) {
|
|
131
|
+
const memoryLinks = db.prepare(`
|
|
132
|
+
SELECT source_id, target_id, relation_type, created_at
|
|
133
|
+
FROM memory_link
|
|
134
|
+
`).all();
|
|
135
|
+
const insertStmt = db.prepare(`
|
|
136
|
+
INSERT INTO memory_relation (source_id, target_id, relation_type, confidence, created_at, updated_at, metadata)
|
|
137
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)
|
|
138
|
+
`);
|
|
139
|
+
let migratedCount = 0;
|
|
140
|
+
for (const link of memoryLinks) {
|
|
141
|
+
const newRelationType = this.mapRelationType(link.relation_type);
|
|
142
|
+
// 매핑되지 않은 관계 유형은 건너뜀 (예: 'duplicates')
|
|
143
|
+
if (!newRelationType) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
// 기본 신뢰도는 0.7, 메타데이터에 마이그레이션 정보 추가
|
|
147
|
+
const metadata = JSON.stringify({
|
|
148
|
+
extraction_method: 'migration',
|
|
149
|
+
migration_source: 'memory_link',
|
|
150
|
+
original_relation_type: link.relation_type,
|
|
151
|
+
migrated_at: new Date().toISOString()
|
|
152
|
+
});
|
|
153
|
+
try {
|
|
154
|
+
insertStmt.run(link.source_id, link.target_id, newRelationType, 0.7, // default confidence
|
|
155
|
+
link.created_at, link.created_at, // updated_at = created_at initially
|
|
156
|
+
metadata);
|
|
157
|
+
migratedCount++;
|
|
158
|
+
}
|
|
159
|
+
catch (error) {
|
|
160
|
+
// UNIQUE 제약 위반 시 무시 (이미 존재하는 관계)
|
|
161
|
+
if (error instanceof Error && error.message.includes('UNIQUE')) {
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
throw error;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
console.log(`[Migration 005] Migrated ${migratedCount} relations from memory_link to memory_relation`);
|
|
168
|
+
}
|
|
169
|
+
// Note: Schema version is recorded by MigrationRunner, not here
|
|
170
|
+
// MigrationRunner.recordVersion() will be called after successful migration
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Rollback migration (Down)
|
|
174
|
+
*/
|
|
175
|
+
async down(db) {
|
|
176
|
+
// Drop indexes first
|
|
177
|
+
const indexes = [
|
|
178
|
+
'idx_memory_relation_source',
|
|
179
|
+
'idx_memory_relation_target',
|
|
180
|
+
'idx_memory_relation_type',
|
|
181
|
+
'idx_memory_relation_confidence',
|
|
182
|
+
'idx_memory_relation_source_type',
|
|
183
|
+
'idx_memory_relation_target_type',
|
|
184
|
+
'idx_relation_type_registry_category'
|
|
185
|
+
];
|
|
186
|
+
for (const indexName of indexes) {
|
|
187
|
+
db.exec(`DROP INDEX IF EXISTS ${indexName}`);
|
|
188
|
+
}
|
|
189
|
+
// Drop tables
|
|
190
|
+
db.exec('DROP TABLE IF EXISTS memory_relation');
|
|
191
|
+
db.exec('DROP TABLE IF EXISTS relation_type_registry');
|
|
192
|
+
// Remove schema version record
|
|
193
|
+
db.prepare('DELETE FROM memento_schema_version WHERE version = ?').run('5.0');
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Validate after migration
|
|
197
|
+
*/
|
|
198
|
+
async validateAfter(db) {
|
|
199
|
+
// Verify memory_relation table exists
|
|
200
|
+
if (!this.tableExists(db, 'memory_relation')) {
|
|
201
|
+
throw new Error('memory_relation table was not created');
|
|
202
|
+
}
|
|
203
|
+
// Verify relation_type_registry table exists
|
|
204
|
+
if (!this.tableExists(db, 'relation_type_registry')) {
|
|
205
|
+
throw new Error('relation_type_registry table was not created');
|
|
206
|
+
}
|
|
207
|
+
// Verify memory_relation table structure (check columns)
|
|
208
|
+
const relationColumns = db.prepare(`PRAGMA table_info(memory_relation)`).all();
|
|
209
|
+
const relationColumnNames = relationColumns.map(col => col.name);
|
|
210
|
+
const requiredRelationColumns = [
|
|
211
|
+
'id',
|
|
212
|
+
'source_id',
|
|
213
|
+
'target_id',
|
|
214
|
+
'relation_type',
|
|
215
|
+
'confidence',
|
|
216
|
+
'created_at',
|
|
217
|
+
'updated_at',
|
|
218
|
+
'metadata'
|
|
219
|
+
];
|
|
220
|
+
for (const column of requiredRelationColumns) {
|
|
221
|
+
if (!relationColumnNames.includes(column)) {
|
|
222
|
+
throw new Error(`Column ${column} was not created in memory_relation table`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
// Verify relation_type_registry table structure (check columns)
|
|
226
|
+
const registryColumns = db.prepare(`PRAGMA table_info(relation_type_registry)`).all();
|
|
227
|
+
const registryColumnNames = registryColumns.map(col => col.name);
|
|
228
|
+
const requiredRegistryColumns = [
|
|
229
|
+
'type_name',
|
|
230
|
+
'category',
|
|
231
|
+
'description',
|
|
232
|
+
'applicable_types',
|
|
233
|
+
'default_confidence',
|
|
234
|
+
'search_boost',
|
|
235
|
+
'created_at'
|
|
236
|
+
];
|
|
237
|
+
for (const column of requiredRegistryColumns) {
|
|
238
|
+
if (!registryColumnNames.includes(column)) {
|
|
239
|
+
throw new Error(`Column ${column} was not created in relation_type_registry table`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
// Verify indexes were created
|
|
243
|
+
const requiredIndexes = [
|
|
244
|
+
'idx_memory_relation_source',
|
|
245
|
+
'idx_memory_relation_target',
|
|
246
|
+
'idx_memory_relation_type',
|
|
247
|
+
'idx_memory_relation_confidence',
|
|
248
|
+
'idx_memory_relation_source_type',
|
|
249
|
+
'idx_memory_relation_target_type',
|
|
250
|
+
'idx_relation_type_registry_category'
|
|
251
|
+
];
|
|
252
|
+
for (const index of requiredIndexes) {
|
|
253
|
+
if (!this.indexExists(db, index)) {
|
|
254
|
+
throw new Error(`Index ${index} was not created`);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
// Verify initial relation types were inserted
|
|
258
|
+
const relationTypes = db.prepare(`
|
|
259
|
+
SELECT type_name FROM relation_type_registry
|
|
260
|
+
`).all();
|
|
261
|
+
const expectedTypes = ['CAUSES', 'DEPENDS_ON', 'FOLLOWS', 'CONTRASTS_WITH', 'REFERENCES', 'BELONGS_TO'];
|
|
262
|
+
const actualTypes = relationTypes.map(r => r.type_name);
|
|
263
|
+
for (const expectedType of expectedTypes) {
|
|
264
|
+
if (!actualTypes.includes(expectedType)) {
|
|
265
|
+
throw new Error(`Relation type ${expectedType} was not inserted into registry`);
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
// Verify UNIQUE constraint exists on memory_relation
|
|
269
|
+
const uniqueCheck = db.prepare(`
|
|
270
|
+
SELECT sql FROM sqlite_master
|
|
271
|
+
WHERE type='table' AND name='memory_relation'
|
|
272
|
+
`).get();
|
|
273
|
+
if (!uniqueCheck || !uniqueCheck.sql.includes('UNIQUE(source_id, target_id, relation_type)')) {
|
|
274
|
+
throw new Error('UNIQUE constraint on (source_id, target_id, relation_type) was not created');
|
|
275
|
+
}
|
|
276
|
+
// Verify foreign key constraints
|
|
277
|
+
const tableInfo = db.prepare(`
|
|
278
|
+
SELECT sql FROM sqlite_master
|
|
279
|
+
WHERE type='table' AND name='memory_relation'
|
|
280
|
+
`).get();
|
|
281
|
+
if (!tableInfo || !tableInfo.sql.includes('FOREIGN KEY') || !tableInfo.sql.includes('ON DELETE CASCADE')) {
|
|
282
|
+
throw new Error('Foreign key constraint with ON DELETE CASCADE was not created');
|
|
283
|
+
}
|
|
284
|
+
// Verify existing dependencies are intact using DependencyValidator
|
|
285
|
+
const dependencyReport = await DependencyValidator.validateAll(db);
|
|
286
|
+
if (!dependencyReport.success) {
|
|
287
|
+
const errors = dependencyReport.results
|
|
288
|
+
.filter(r => !r.success)
|
|
289
|
+
.map(r => `${r.name}: ${r.error}`)
|
|
290
|
+
.join('; ');
|
|
291
|
+
throw new Error(`Dependency validation failed: ${errors}`);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
//# sourceMappingURL=005-relation-engine-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"005-relation-engine-schema.js","sourceRoot":"","sources":["../../../../src/database/migration/migrations/005-relation-engine-schema.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAClC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,KAAK,CAAC;AAEpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAEjE,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC;;;;;;;;;GASG;AACH,MAAM,OAAO,6BAA6B;IACxC,OAAO,GAAG,KAAK,CAAC;IAChB,IAAI,GAAG,wBAAwB,CAAC;IAChC,WAAW,GAAG,uFAAuF,CAAC;IAEtG;;OAEG;IACK,WAAW,CAAC,QAAgB;QAClC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;QAC3C,OAAO,YAAY,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACzC,CAAC;IAED;;;OAGG;IACK,UAAU,CAAC,EAAqB,EAAE,GAAW;QACnD,gDAAgD;QAChD,IAAI,UAAU,GAAG,GAAG;YAClB,uBAAuB;aACtB,OAAO,CAAC,2BAA2B,EAAE,EAAE,CAAC;YACzC,YAAY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AAE,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;iBACvB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC;iBACjC,IAAI,CAAC,IAAI,CAAC,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,iCAAiC,MAAM,EAAE,CAAC,CAAC;QAC7D,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
-- Migration: 005 - Relation Engine Schema
|
|
2
|
+
-- Description: Create memory_relation and relation_type_registry tables for semantic relation engine
|
|
3
|
+
-- Version: 5.0
|
|
4
|
+
-- Date: 2025-01-XX
|
|
5
|
+
|
|
6
|
+
-- 1. Create memory_relation table
|
|
7
|
+
CREATE TABLE IF NOT EXISTS memory_relation (
|
|
8
|
+
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
9
|
+
source_id TEXT NOT NULL,
|
|
10
|
+
target_id TEXT NOT NULL,
|
|
11
|
+
relation_type TEXT NOT NULL,
|
|
12
|
+
confidence REAL NOT NULL DEFAULT 0.7 CHECK (confidence >= 0.0 AND confidence <= 1.0),
|
|
13
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
14
|
+
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
15
|
+
metadata TEXT, -- JSON: extraction method, timestamp, cyclic flag, refinement history
|
|
16
|
+
FOREIGN KEY (source_id) REFERENCES memory_item(id) ON DELETE CASCADE,
|
|
17
|
+
FOREIGN KEY (target_id) REFERENCES memory_item(id) ON DELETE CASCADE,
|
|
18
|
+
UNIQUE(source_id, target_id, relation_type)
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
-- 2. Create relation_type_registry table
|
|
22
|
+
CREATE TABLE IF NOT EXISTS relation_type_registry (
|
|
23
|
+
type_name TEXT PRIMARY KEY,
|
|
24
|
+
category TEXT NOT NULL, -- 'Causal', 'Temporal', 'Structural', 'Semantic'
|
|
25
|
+
description TEXT,
|
|
26
|
+
applicable_types TEXT, -- JSON array: ['episodic', 'semantic'] etc.
|
|
27
|
+
default_confidence REAL DEFAULT 0.7,
|
|
28
|
+
search_boost REAL DEFAULT 1.0, -- Search ranking weight
|
|
29
|
+
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
-- 3. Create indexes for memory_relation table
|
|
33
|
+
CREATE INDEX idx_memory_relation_source ON memory_relation(source_id);
|
|
34
|
+
CREATE INDEX idx_memory_relation_target ON memory_relation(target_id);
|
|
35
|
+
CREATE INDEX idx_memory_relation_type ON memory_relation(relation_type);
|
|
36
|
+
CREATE INDEX idx_memory_relation_confidence ON memory_relation(confidence);
|
|
37
|
+
CREATE INDEX idx_memory_relation_source_type ON memory_relation(source_id, relation_type);
|
|
38
|
+
CREATE INDEX idx_memory_relation_target_type ON memory_relation(target_id, relation_type);
|
|
39
|
+
|
|
40
|
+
-- 4. Create index for relation_type_registry table
|
|
41
|
+
CREATE INDEX idx_relation_type_registry_category ON relation_type_registry(category);
|
|
42
|
+
|
|
43
|
+
-- 5. Insert initial relation types into registry
|
|
44
|
+
-- Causal (인과 관계군)
|
|
45
|
+
INSERT INTO relation_type_registry (type_name, category, description, applicable_types, default_confidence, search_boost)
|
|
46
|
+
VALUES ('CAUSES', 'Causal', '인과 관계: 한 기억이 다른 기억의 원인이 되는 관계', '["episodic", "semantic"]', 0.7, 1.2);
|
|
47
|
+
|
|
48
|
+
-- Temporal (시간 관계군)
|
|
49
|
+
INSERT INTO relation_type_registry (type_name, category, description, applicable_types, default_confidence, search_boost)
|
|
50
|
+
VALUES ('FOLLOWS', 'Temporal', '시간적 순서: 한 기억이 다른 기억 이후에 발생하는 관계', '["episodic", "procedural"]', 0.7, 1.0);
|
|
51
|
+
|
|
52
|
+
-- Structural (구조 관계군)
|
|
53
|
+
INSERT INTO relation_type_registry (type_name, category, description, applicable_types, default_confidence, search_boost)
|
|
54
|
+
VALUES ('DEPENDS_ON', 'Structural', '의존 관계: 한 기억이 다른 기억에 의존하는 관계', '["semantic", "procedural"]', 0.7, 1.1);
|
|
55
|
+
|
|
56
|
+
INSERT INTO relation_type_registry (type_name, category, description, applicable_types, default_confidence, search_boost)
|
|
57
|
+
VALUES ('BELONGS_TO', 'Structural', '포함 관계: 한 기억이 다른 기억에 속하는 관계', '["semantic", "episodic"]', 0.7, 1.0);
|
|
58
|
+
|
|
59
|
+
-- Semantic (의미 관계군)
|
|
60
|
+
INSERT INTO relation_type_registry (type_name, category, description, applicable_types, default_confidence, search_boost)
|
|
61
|
+
VALUES ('CONTRASTS_WITH', 'Semantic', '대조 관계: 한 기억이 다른 기억과 대조되는 관계', '["semantic", "episodic"]', 0.7, 0.9);
|
|
62
|
+
|
|
63
|
+
INSERT INTO relation_type_registry (type_name, category, description, applicable_types, default_confidence, search_boost)
|
|
64
|
+
VALUES ('REFERENCES', 'Semantic', '참조 관계: 한 기억이 다른 기억을 참조하는 관계', '["working", "episodic", "semantic", "procedural"]', 0.7, 0.8);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anchor-interfaces.d.ts","sourceRoot":"","sources":["../../../src/services/anchor/anchor-interfaces.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAK3C;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,UAAU,CAAC;IACjB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC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|
+
{"version":3,"file":"anchor-interfaces.js","sourceRoot":"","sources":["../../../src/services/anchor/anchor-interfaces.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmJH;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IACpC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED;;GAEG;AACH,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC5C,YAAY,QAAgB;QAC1B,KAAK,CAAC,mBAAmB,QAAQ,aAAa,CAAC,CAAC;QAChD,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF"}
|
|
@@ -7,6 +7,7 @@ import type Database from 'better-sqlite3';
|
|
|
7
7
|
import type { HybridSearchEngine } from '../../algorithms/hybrid-search-engine.js';
|
|
8
8
|
import type { VectorSearchEngine } from '../../algorithms/vector-search-engine.js';
|
|
9
9
|
import type { IAnchorCacheService, IAnchorSearchService, IAnchorManager, SearchOptions, SearchResult, AnchorSlot } from './anchor-interfaces.js';
|
|
10
|
+
import { RelationGraph } from '../relation-graph.js';
|
|
10
11
|
/**
|
|
11
12
|
* Anchor Search Service 구현
|
|
12
13
|
*/
|
|
@@ -16,10 +17,15 @@ export declare class AnchorSearchService implements IAnchorSearchService {
|
|
|
16
17
|
private hybridSearchEngine;
|
|
17
18
|
private vectorSearchEngine;
|
|
18
19
|
private queryEmbeddingService;
|
|
20
|
+
private relationGraph;
|
|
19
21
|
/**
|
|
20
22
|
* 생성자
|
|
21
23
|
*/
|
|
22
24
|
constructor(cacheService: IAnchorCacheService);
|
|
25
|
+
/**
|
|
26
|
+
* RelationGraph 설정 (선택적)
|
|
27
|
+
*/
|
|
28
|
+
setRelationGraph(relationGraph: RelationGraph): void;
|
|
23
29
|
/**
|
|
24
30
|
* 데이터베이스 설정
|
|
25
31
|
*/
|
|
@@ -59,9 +65,19 @@ export declare class AnchorSearchService implements IAnchorSearchService {
|
|
|
59
65
|
/**
|
|
60
66
|
* memory_link 테이블을 활용한 직접 연결된 메모리 조회
|
|
61
67
|
*/
|
|
68
|
+
/**
|
|
69
|
+
* 연결된 메모리 조회
|
|
70
|
+
* 관계 그래프가 있으면 우선 사용, 없으면 memory_link 사용
|
|
71
|
+
*/
|
|
62
72
|
private getLinkedMemories;
|
|
73
|
+
/**
|
|
74
|
+
* 관계 유형별 부스트 가중치 반환
|
|
75
|
+
*/
|
|
76
|
+
private getRelationTypeBoost;
|
|
63
77
|
/**
|
|
64
78
|
* 검색 결과 랭킹 점수 계산
|
|
79
|
+
* 관계 그래프와 벡터 유사도를 결합한 하이브리드 hop 점수 계산
|
|
80
|
+
* 관계가 있는 기억에 우선순위 부여
|
|
65
81
|
*/
|
|
66
82
|
private calculateRankingScore;
|
|
67
83
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"anchor-search-service.d.ts","sourceRoot":"","sources":["../../../src/services/anchor/anchor-search-service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAEnF,OAAO,KAAK,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,cAAc,EAAE,aAAa,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"anchor-search-service.d.ts","sourceRoot":"","sources":["../../../src/services/anchor/anchor-search-service.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,QAAQ,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AACnF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CA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