agent-memory-graph 0.1.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 +341 -0
- package/config/default.json +28 -0
- package/config/graph.config.json +28 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +303 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/plugin/entry.d.ts +3 -0
- package/dist/plugin/entry.d.ts.map +1 -0
- package/dist/plugin/entry.js +1652 -0
- package/dist/plugin/entry.js.map +1 -0
- package/dist/src/config/defaults.d.ts +8 -0
- package/dist/src/config/defaults.d.ts.map +1 -0
- package/dist/src/config/defaults.js +31 -0
- package/dist/src/config/defaults.js.map +1 -0
- package/dist/src/config/schema.d.ts +162 -0
- package/dist/src/config/schema.d.ts.map +1 -0
- package/dist/src/config/schema.js +39 -0
- package/dist/src/config/schema.js.map +1 -0
- package/dist/src/extract/dedup.d.ts +14 -0
- package/dist/src/extract/dedup.d.ts.map +1 -0
- package/dist/src/extract/dedup.js +79 -0
- package/dist/src/extract/dedup.js.map +1 -0
- package/dist/src/extract/extractor.d.ts +24 -0
- package/dist/src/extract/extractor.d.ts.map +1 -0
- package/dist/src/extract/extractor.js +162 -0
- package/dist/src/extract/extractor.js.map +1 -0
- package/dist/src/graph/engine.d.ts +90 -0
- package/dist/src/graph/engine.d.ts.map +1 -0
- package/dist/src/graph/engine.js +307 -0
- package/dist/src/graph/engine.js.map +1 -0
- package/dist/src/graph/schema.d.ts +12 -0
- package/dist/src/graph/schema.d.ts.map +1 -0
- package/dist/src/graph/schema.js +115 -0
- package/dist/src/graph/schema.js.map +1 -0
- package/dist/src/index.d.ts +129 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +174 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/search/hybrid.d.ts +22 -0
- package/dist/src/search/hybrid.d.ts.map +1 -0
- package/dist/src/search/hybrid.js +38 -0
- package/dist/src/search/hybrid.js.map +1 -0
- package/dist/src/search/natural-language.d.ts +20 -0
- package/dist/src/search/natural-language.d.ts.map +1 -0
- package/dist/src/search/natural-language.js +429 -0
- package/dist/src/search/natural-language.js.map +1 -0
- package/dist/src/sync/export.d.ts +12 -0
- package/dist/src/sync/export.d.ts.map +1 -0
- package/dist/src/sync/export.js +117 -0
- package/dist/src/sync/export.js.map +1 -0
- package/dist/src/sync/memory-md.d.ts +19 -0
- package/dist/src/sync/memory-md.d.ts.map +1 -0
- package/dist/src/sync/memory-md.js +78 -0
- package/dist/src/sync/memory-md.js.map +1 -0
- package/openclaw.plugin.json +55 -0
- package/package.json +90 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { type Entity, type Relationship, type GraphStats } from './graph/engine.js';
|
|
2
|
+
import { type Config } from './config/defaults.js';
|
|
3
|
+
import { type ExtractionResult } from './extract/extractor.js';
|
|
4
|
+
import { type SearchResult } from './search/hybrid.js';
|
|
5
|
+
import { type NLQueryResult } from './search/natural-language.js';
|
|
6
|
+
import { type ExportFormat } from './sync/export.js';
|
|
7
|
+
export interface MemoryGraphOptions {
|
|
8
|
+
/** Path to SQLite database file */
|
|
9
|
+
path?: string;
|
|
10
|
+
/** Path to config file (optional) */
|
|
11
|
+
configPath?: string;
|
|
12
|
+
/** Inline config override (optional) */
|
|
13
|
+
config?: Partial<Config>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* MemoryGraph — Domain-agnostic knowledge graph for AI agents.
|
|
17
|
+
*
|
|
18
|
+
* Zero-config, local-first, SQLite-powered.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { MemoryGraph } from 'agent-memory-graph';
|
|
23
|
+
*
|
|
24
|
+
* const graph = new MemoryGraph();
|
|
25
|
+
* await graph.ingest("Alice works on Project Atlas using Rust");
|
|
26
|
+
* const answer = await graph.ask("What does Alice work on?");
|
|
27
|
+
* console.log(answer);
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare class MemoryGraph {
|
|
31
|
+
private engine;
|
|
32
|
+
private config;
|
|
33
|
+
constructor(options?: MemoryGraphOptions);
|
|
34
|
+
/**
|
|
35
|
+
* Ingest text: extract entities and relationships, store in graph.
|
|
36
|
+
*/
|
|
37
|
+
ingest(text: string, options?: {
|
|
38
|
+
source?: string;
|
|
39
|
+
sessionId?: string;
|
|
40
|
+
}): Promise<ExtractionResult>;
|
|
41
|
+
/**
|
|
42
|
+
* Ask a natural language question against the graph.
|
|
43
|
+
*/
|
|
44
|
+
ask(question: string): Promise<NLQueryResult>;
|
|
45
|
+
/**
|
|
46
|
+
* Search entities by keyword.
|
|
47
|
+
*/
|
|
48
|
+
search(query: string, limit?: number): SearchResult[];
|
|
49
|
+
/**
|
|
50
|
+
* Add an entity manually.
|
|
51
|
+
*/
|
|
52
|
+
addEntity(name: string, type: string, properties?: Record<string, unknown>): Entity;
|
|
53
|
+
/**
|
|
54
|
+
* Add a relationship manually.
|
|
55
|
+
*/
|
|
56
|
+
addRelation(from: string, relation: string, to: string, options?: {
|
|
57
|
+
fromType?: string;
|
|
58
|
+
toType?: string;
|
|
59
|
+
}): Relationship;
|
|
60
|
+
/**
|
|
61
|
+
* Find an entity by name.
|
|
62
|
+
*/
|
|
63
|
+
findEntity(name: string, type?: string): Entity | null;
|
|
64
|
+
/**
|
|
65
|
+
* List entities, optionally filtered by type.
|
|
66
|
+
*/
|
|
67
|
+
listEntities(options?: {
|
|
68
|
+
type?: string;
|
|
69
|
+
limit?: number;
|
|
70
|
+
}): Entity[];
|
|
71
|
+
/**
|
|
72
|
+
* Delete an entity and its relationships.
|
|
73
|
+
*/
|
|
74
|
+
deleteEntity(nameOrId: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Find shortest path between two entities.
|
|
77
|
+
*/
|
|
78
|
+
findPath(from: string, to: string, maxHops?: number): {
|
|
79
|
+
path: string[];
|
|
80
|
+
relations: string[];
|
|
81
|
+
} | null;
|
|
82
|
+
/**
|
|
83
|
+
* Get all entities and relationships within N hops of an entity.
|
|
84
|
+
*/
|
|
85
|
+
neighborhood(entityName: string, hops?: number): {
|
|
86
|
+
entities: Entity[];
|
|
87
|
+
relationships: Relationship[];
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* Export graph to a format (json, mermaid, dot, csv).
|
|
91
|
+
*/
|
|
92
|
+
export(format: ExportFormat, options?: {
|
|
93
|
+
includeProperties?: boolean;
|
|
94
|
+
maxEntities?: number;
|
|
95
|
+
}): string;
|
|
96
|
+
/**
|
|
97
|
+
* Import from a MEMORY.md file or directory.
|
|
98
|
+
*/
|
|
99
|
+
importFrom(path: string): Promise<{
|
|
100
|
+
entities: number;
|
|
101
|
+
relationships: number;
|
|
102
|
+
}>;
|
|
103
|
+
/**
|
|
104
|
+
* Find and optionally merge duplicate entities.
|
|
105
|
+
*/
|
|
106
|
+
deduplicate(options?: {
|
|
107
|
+
threshold?: number;
|
|
108
|
+
autoMerge?: boolean;
|
|
109
|
+
}): Array<{
|
|
110
|
+
entity: string;
|
|
111
|
+
duplicateOf: string;
|
|
112
|
+
similarity: number;
|
|
113
|
+
}>;
|
|
114
|
+
/**
|
|
115
|
+
* Get graph statistics.
|
|
116
|
+
*/
|
|
117
|
+
stats(): GraphStats;
|
|
118
|
+
/**
|
|
119
|
+
* Close database connection.
|
|
120
|
+
*/
|
|
121
|
+
close(): void;
|
|
122
|
+
}
|
|
123
|
+
export type { Entity, Relationship, GraphStats } from './graph/engine.js';
|
|
124
|
+
export type { Config } from './config/schema.js';
|
|
125
|
+
export type { ExtractionResult, ExtractedEntity, ExtractedRelation } from './extract/extractor.js';
|
|
126
|
+
export type { SearchResult } from './search/hybrid.js';
|
|
127
|
+
export type { NLQueryResult } from './search/natural-language.js';
|
|
128
|
+
export type { ExportFormat } from './sync/export.js';
|
|
129
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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C;IAcpF;;OAEG;IACH,WAAW,CAAC,OAAO,CAAC,EAAE;QAAE,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IAiBtI;;OAEG;IACH,KAAK,IAAI,UAAU;IAInB;;OAEG;IACH,KAAK,IAAI,IAAI;CAGd;AAGD,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC1E,YAAY,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACnG,YAAY,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AACvD,YAAY,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAClE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { GraphEngine } from './graph/engine.js';
|
|
2
|
+
import { loadConfig } from './config/defaults.js';
|
|
3
|
+
import { extractFromText } from './extract/extractor.js';
|
|
4
|
+
import { hybridSearch } from './search/hybrid.js';
|
|
5
|
+
import { naturalLanguageQuery } from './search/natural-language.js';
|
|
6
|
+
import { exportGraph } from './sync/export.js';
|
|
7
|
+
import { importFromMemoryMd, importFromDirectory } from './sync/memory-md.js';
|
|
8
|
+
import { findDuplicates, mergeEntities } from './extract/dedup.js';
|
|
9
|
+
/**
|
|
10
|
+
* MemoryGraph — Domain-agnostic knowledge graph for AI agents.
|
|
11
|
+
*
|
|
12
|
+
* Zero-config, local-first, SQLite-powered.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* import { MemoryGraph } from 'agent-memory-graph';
|
|
17
|
+
*
|
|
18
|
+
* const graph = new MemoryGraph();
|
|
19
|
+
* await graph.ingest("Alice works on Project Atlas using Rust");
|
|
20
|
+
* const answer = await graph.ask("What does Alice work on?");
|
|
21
|
+
* console.log(answer);
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export class MemoryGraph {
|
|
25
|
+
engine;
|
|
26
|
+
config;
|
|
27
|
+
constructor(options = {}) {
|
|
28
|
+
this.config = loadConfig(options.configPath);
|
|
29
|
+
// Apply inline overrides
|
|
30
|
+
if (options.config) {
|
|
31
|
+
this.config = { ...this.config, ...options.config };
|
|
32
|
+
}
|
|
33
|
+
const dbPath = options.path ?? this.config.storage.path;
|
|
34
|
+
this.engine = new GraphEngine(dbPath);
|
|
35
|
+
}
|
|
36
|
+
// ─── Core API ──────────────────────────────────────────────────
|
|
37
|
+
/**
|
|
38
|
+
* Ingest text: extract entities and relationships, store in graph.
|
|
39
|
+
*/
|
|
40
|
+
async ingest(text, options = {}) {
|
|
41
|
+
const result = await extractFromText(text, this.config);
|
|
42
|
+
// Store entities
|
|
43
|
+
for (const entity of result.entities) {
|
|
44
|
+
this.engine.addEntity(entity.name, entity.type, entity.properties ?? {}, {
|
|
45
|
+
source: options.source,
|
|
46
|
+
confidence: entity.confidence,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// Store relationships
|
|
50
|
+
for (const rel of result.relationships) {
|
|
51
|
+
this.engine.addRelation(rel.from, rel.relation, rel.to, {
|
|
52
|
+
source: options.source,
|
|
53
|
+
confidence: rel.confidence,
|
|
54
|
+
fromType: rel.fromType,
|
|
55
|
+
toType: rel.toType,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
// Log extraction
|
|
59
|
+
this.engine.logExtraction(text, result.entities, result.relationships, options.sessionId);
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Ask a natural language question against the graph.
|
|
64
|
+
*/
|
|
65
|
+
async ask(question) {
|
|
66
|
+
return naturalLanguageQuery(question, this.engine, this.config);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Search entities by keyword.
|
|
70
|
+
*/
|
|
71
|
+
search(query, limit) {
|
|
72
|
+
return hybridSearch(this.engine, query, {
|
|
73
|
+
...this.config,
|
|
74
|
+
query: { ...this.config.query, maxResults: limit ?? this.config.query.maxResults },
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
// ─── Entity Management ─────────────────────────────────────────
|
|
78
|
+
/**
|
|
79
|
+
* Add an entity manually.
|
|
80
|
+
*/
|
|
81
|
+
addEntity(name, type, properties = {}) {
|
|
82
|
+
return this.engine.addEntity(name, type, properties);
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Add a relationship manually.
|
|
86
|
+
*/
|
|
87
|
+
addRelation(from, relation, to, options) {
|
|
88
|
+
return this.engine.addRelation(from, relation, to, options);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Find an entity by name.
|
|
92
|
+
*/
|
|
93
|
+
findEntity(name, type) {
|
|
94
|
+
return this.engine.findEntityByName(name, type);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* List entities, optionally filtered by type.
|
|
98
|
+
*/
|
|
99
|
+
listEntities(options) {
|
|
100
|
+
return this.engine.listEntities(options);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Delete an entity and its relationships.
|
|
104
|
+
*/
|
|
105
|
+
deleteEntity(nameOrId) {
|
|
106
|
+
const entity = this.engine.getEntity(nameOrId) ?? this.engine.findEntityByName(nameOrId);
|
|
107
|
+
if (!entity)
|
|
108
|
+
return false;
|
|
109
|
+
return this.engine.deleteEntity(entity.id);
|
|
110
|
+
}
|
|
111
|
+
// ─── Graph Operations ──────────────────────────────────────────
|
|
112
|
+
/**
|
|
113
|
+
* Find shortest path between two entities.
|
|
114
|
+
*/
|
|
115
|
+
findPath(from, to, maxHops) {
|
|
116
|
+
return this.engine.findPath(from, to, maxHops ?? this.config.query.maxHops);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Get all entities and relationships within N hops of an entity.
|
|
120
|
+
*/
|
|
121
|
+
neighborhood(entityName, hops = 1) {
|
|
122
|
+
return this.engine.getNeighborhood(entityName, hops);
|
|
123
|
+
}
|
|
124
|
+
// ─── Import / Export ───────────────────────────────────────────
|
|
125
|
+
/**
|
|
126
|
+
* Export graph to a format (json, mermaid, dot, csv).
|
|
127
|
+
*/
|
|
128
|
+
export(format, options) {
|
|
129
|
+
return exportGraph(this.engine, { format, ...options });
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Import from a MEMORY.md file or directory.
|
|
133
|
+
*/
|
|
134
|
+
async importFrom(path) {
|
|
135
|
+
const { statSync } = await import('node:fs');
|
|
136
|
+
const stat = statSync(path);
|
|
137
|
+
if (stat.isDirectory()) {
|
|
138
|
+
const result = await importFromDirectory(path, this.engine, this.config);
|
|
139
|
+
return { entities: result.entities, relationships: result.relationships };
|
|
140
|
+
}
|
|
141
|
+
return importFromMemoryMd(path, this.engine, this.config);
|
|
142
|
+
}
|
|
143
|
+
// ─── Maintenance ───────────────────────────────────────────────
|
|
144
|
+
/**
|
|
145
|
+
* Find and optionally merge duplicate entities.
|
|
146
|
+
*/
|
|
147
|
+
deduplicate(options) {
|
|
148
|
+
const threshold = options?.threshold ?? this.config.deduplication.similarityThreshold;
|
|
149
|
+
const duplicates = findDuplicates(this.engine, threshold);
|
|
150
|
+
if (options?.autoMerge) {
|
|
151
|
+
for (const dup of duplicates) {
|
|
152
|
+
mergeEntities(this.engine, dup.duplicateOf.id, dup.entity.id);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return duplicates.map(d => ({
|
|
156
|
+
entity: d.entity.name,
|
|
157
|
+
duplicateOf: d.duplicateOf.name,
|
|
158
|
+
similarity: d.similarity,
|
|
159
|
+
}));
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get graph statistics.
|
|
163
|
+
*/
|
|
164
|
+
stats() {
|
|
165
|
+
return this.engine.stats();
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Close database connection.
|
|
169
|
+
*/
|
|
170
|
+
close() {
|
|
171
|
+
this.engine.close();
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmD,MAAM,mBAAmB,CAAC;AACjG,OAAO,EAAE,UAAU,EAAe,MAAM,sBAAsB,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAyB,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,YAAY,EAAqB,MAAM,oBAAoB,CAAC;AACrE,OAAO,EAAE,oBAAoB,EAAsB,MAAM,8BAA8B,CAAC;AACxF,OAAO,EAAE,WAAW,EAAqB,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAWnE;;;;;;;;;;;;;;GAcG;AACH,MAAM,OAAO,WAAW;IACd,MAAM,CAAc;IACpB,MAAM,CAAS;IAEvB,YAAY,UAA8B,EAAE;QAC1C,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAE7C,yBAAyB;QACzB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;YACnB,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,CAAC,MAAM,EAAY,CAAC;QAChE,CAAC;QAED,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC;QACxD,I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SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,mBAAmB,CAAC;QACtF,MAAM,UAAU,GAAG,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;QAE1D,IAAI,OAAO,EAAE,SAAS,EAAE,CAAC;YACvB,KAAK,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;gBAC7B,aAAa,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,WAAW,CAAC,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YAChE,CAAC;QACH,CAAC;QAED,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;YAC1B,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI;YACrB,WAAW,EAAE,CAAC,CAAC,WAAW,CAAC,IAAI;YAC/B,UAAU,EAAE,CAAC,CAAC,UAAU;SACzB,CAAC,CAAC,CAAC;IACN,CAAC;IAED;;OAEG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Config } from '../config/schema.js';
|
|
2
|
+
import { GraphEngine } from '../graph/engine.js';
|
|
3
|
+
export interface SearchResult {
|
|
4
|
+
entity: {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
properties: Record<string, unknown>;
|
|
9
|
+
};
|
|
10
|
+
relations: Array<{
|
|
11
|
+
direction: 'outgoing' | 'incoming';
|
|
12
|
+
relation: string;
|
|
13
|
+
target: string;
|
|
14
|
+
targetType: string;
|
|
15
|
+
}>;
|
|
16
|
+
score?: number;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Hybrid search: combines FTS + graph context.
|
|
20
|
+
*/
|
|
21
|
+
export declare function hybridSearch(engine: GraphEngine, query: string, config: Config): SearchResult[];
|
|
22
|
+
//# sourceMappingURL=hybrid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hybrid.d.ts","sourceRoot":"","sources":["../../../src/search/hybrid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE;QACN,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACrC,CAAC;IACF,SAAS,EAAE,KAAK,CAAC;QACf,SAAS,EAAE,UAAU,GAAG,UAAU,CAAC;QACnC,QAAQ,EAAE,MAAM,CAAC;QACjB,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC,CAAC;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM,GACb,YAAY,EAAE,CAsChB"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hybrid search: combines FTS + graph context.
|
|
3
|
+
*/
|
|
4
|
+
export function hybridSearch(engine, query, config) {
|
|
5
|
+
const limit = config.query.maxResults;
|
|
6
|
+
// Step 1: FTS search for matching entities
|
|
7
|
+
const entities = engine.searchEntities(query, limit);
|
|
8
|
+
// Step 2: Enrich with relationship context
|
|
9
|
+
const results = entities.map(entity => {
|
|
10
|
+
const outgoing = engine.getRelationsFrom(entity.id);
|
|
11
|
+
const incoming = engine.getRelationsTo(entity.id);
|
|
12
|
+
const relations = [
|
|
13
|
+
...outgoing.map(r => ({
|
|
14
|
+
direction: 'outgoing',
|
|
15
|
+
relation: r.relation,
|
|
16
|
+
target: r.to_name,
|
|
17
|
+
targetType: r.to_type,
|
|
18
|
+
})),
|
|
19
|
+
...incoming.map(r => ({
|
|
20
|
+
direction: 'incoming',
|
|
21
|
+
relation: r.relation,
|
|
22
|
+
target: r.from_name,
|
|
23
|
+
targetType: r.from_type,
|
|
24
|
+
})),
|
|
25
|
+
];
|
|
26
|
+
return {
|
|
27
|
+
entity: {
|
|
28
|
+
id: entity.id,
|
|
29
|
+
name: entity.name,
|
|
30
|
+
type: entity.type,
|
|
31
|
+
properties: entity.properties,
|
|
32
|
+
},
|
|
33
|
+
relations,
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
return results;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=hybrid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hybrid.js","sourceRoot":"","sources":["../../../src/search/hybrid.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,MAAM,UAAU,YAAY,CAC1B,MAAmB,EACnB,KAAa,EACb,MAAc;IAEd,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC;IAEtC,2CAA2C;IAC3C,MAAM,QAAQ,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAErD,2CAA2C;IAC3C,MAAM,OAAO,GAAmB,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE;QACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,gBAAgB,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QACpD,MAAM,QAAQ,GAAG,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;QAElD,MAAM,SAAS,GAAG;YAChB,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACpB,SAAS,EAAE,UAAmB;gBAC9B,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,MAAM,EAAE,CAAC,CAAC,OAAO;gBACjB,UAAU,EAAE,CAAC,CAAC,OAAO;aACtB,CAAC,CAAC;YACH,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;gBACpB,SAAS,EAAE,UAAmB;gBAC9B,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,MAAM,EAAE,CAAC,CAAC,SAAS;gBACnB,UAAU,EAAE,CAAC,CAAC,SAAS;aACxB,CAAC,CAAC;SACJ,CAAC;QAEF,OAAO;YACL,MAAM,EAAE;gBACN,EAAE,EAAE,MAAM,CAAC,EAAE;gBACb,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,IAAI,EAAE,MAAM,CAAC,IAAI;gBACjB,UAAU,EAAE,MAAM,CAAC,UAAU;aAC9B;YACD,SAAS;SACV,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Config } from '../config/schema.js';
|
|
2
|
+
import { GraphEngine } from '../graph/engine.js';
|
|
3
|
+
export interface NLQueryResult {
|
|
4
|
+
answer: string;
|
|
5
|
+
entities: Array<{
|
|
6
|
+
name: string;
|
|
7
|
+
type: string;
|
|
8
|
+
}>;
|
|
9
|
+
paths?: Array<{
|
|
10
|
+
path: string[];
|
|
11
|
+
relations: string[];
|
|
12
|
+
}>;
|
|
13
|
+
confidence: number;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Translate a natural language question into graph operations and return an answer.
|
|
17
|
+
* Uses pattern matching for common queries, falls back to entity-name extraction.
|
|
18
|
+
*/
|
|
19
|
+
export declare function naturalLanguageQuery(question: string, engine: GraphEngine, config: Config): Promise<NLQueryResult>;
|
|
20
|
+
//# sourceMappingURL=natural-language.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"natural-language.d.ts","sourceRoot":"","sources":["../../../src/search/natural-language.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAChD,KAAK,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,EAAE,CAAC;QAAC,SAAS,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IACvD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;GAGG;AACH,wBAAsB,oBAAoB,CACxC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,WAAW,EACnB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,aAAa,CAAC,CAiGxB"}
|