@grackle-ai/knowledge 0.62.2 → 0.63.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/dist/index.d.ts +4 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -16
- package/dist/index.js.map +1 -1
- package/dist/reference-sync.d.ts +1 -2
- package/dist/reference-sync.d.ts.map +1 -1
- package/dist/reference-sync.js +1 -5
- package/dist/reference-sync.js.map +1 -1
- package/package.json +2 -5
- package/dist/chunker.d.ts +0 -20
- package/dist/chunker.d.ts.map +0 -1
- package/dist/chunker.js +0 -7
- package/dist/chunker.js.map +0 -1
- package/dist/client.d.ts +0 -68
- package/dist/client.d.ts.map +0 -1
- package/dist/client.js +0 -150
- package/dist/client.js.map +0 -1
- package/dist/constants.d.ts +0 -33
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js +0 -33
- package/dist/constants.js.map +0 -1
- package/dist/edge-store.d.ts +0 -32
- package/dist/edge-store.d.ts.map +0 -1
- package/dist/edge-store.js +0 -145
- package/dist/edge-store.js.map +0 -1
- package/dist/embedder.d.ts +0 -35
- package/dist/embedder.d.ts.map +0 -1
- package/dist/embedder.js +0 -7
- package/dist/embedder.js.map +0 -1
- package/dist/expand.d.ts +0 -42
- package/dist/expand.d.ts.map +0 -1
- package/dist/expand.js +0 -150
- package/dist/expand.js.map +0 -1
- package/dist/ingest.d.ts +0 -23
- package/dist/ingest.d.ts.map +0 -1
- package/dist/ingest.js +0 -27
- package/dist/ingest.js.map +0 -1
- package/dist/local-embedder.d.ts +0 -25
- package/dist/local-embedder.d.ts.map +0 -1
- package/dist/local-embedder.js +0 -88
- package/dist/local-embedder.js.map +0 -1
- package/dist/logger.d.ts +0 -9
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -15
- package/dist/logger.js.map +0 -1
- package/dist/node-store.d.ts +0 -116
- package/dist/node-store.d.ts.map +0 -1
- package/dist/node-store.js +0 -268
- package/dist/node-store.js.map +0 -1
- package/dist/pass-through-chunker.d.ts +0 -16
- package/dist/pass-through-chunker.d.ts.map +0 -1
- package/dist/pass-through-chunker.js +0 -21
- package/dist/pass-through-chunker.js.map +0 -1
- package/dist/schema.d.ts +0 -23
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -73
- package/dist/schema.js.map +0 -1
- package/dist/search.d.ts +0 -43
- package/dist/search.d.ts.map +0 -1
- package/dist/search.js +0 -123
- package/dist/search.js.map +0 -1
- package/dist/transcript-chunker.d.ts +0 -29
- package/dist/transcript-chunker.d.ts.map +0 -1
- package/dist/transcript-chunker.js +0 -142
- package/dist/transcript-chunker.js.map +0 -1
- package/dist/types.d.ts +0 -102
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -61
- package/dist/types.js.map +0 -1
package/dist/node-store.d.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Node CRUD operations for the knowledge graph.
|
|
3
|
-
*
|
|
4
|
-
* Provides create, read, update, and delete operations for both
|
|
5
|
-
* {@link ReferenceNode} and {@link NativeNode} types, backed by Neo4j.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import { type ReferenceSource, type NativeCategory, type KnowledgeNode, type KnowledgeEdge } from "./types.js";
|
|
10
|
-
/** Input for creating a reference node. Excludes auto-generated fields. */
|
|
11
|
-
export interface CreateReferenceNodeInput {
|
|
12
|
-
/** Which entity type this refers to. */
|
|
13
|
-
sourceType: ReferenceSource;
|
|
14
|
-
/** The ID of the entity in Grackle's relational DB. */
|
|
15
|
-
sourceId: string;
|
|
16
|
-
/** Human-readable label derived from the source. */
|
|
17
|
-
label: string;
|
|
18
|
-
/** Dense vector embedding for similarity search. */
|
|
19
|
-
embedding: number[];
|
|
20
|
-
/** Workspace scope (empty string = global). */
|
|
21
|
-
workspaceId: string;
|
|
22
|
-
}
|
|
23
|
-
/** Input for creating a native node. Excludes auto-generated fields. */
|
|
24
|
-
export interface CreateNativeNodeInput {
|
|
25
|
-
/** Subcategory of the native node. */
|
|
26
|
-
category: NativeCategory;
|
|
27
|
-
/** Title or summary. */
|
|
28
|
-
title: string;
|
|
29
|
-
/** Full content owned by this node. */
|
|
30
|
-
content: string;
|
|
31
|
-
/** Free-form tags for categorization. */
|
|
32
|
-
tags: string[];
|
|
33
|
-
/** Dense vector embedding for similarity search. */
|
|
34
|
-
embedding: number[];
|
|
35
|
-
/** Workspace scope (empty string = global). */
|
|
36
|
-
workspaceId: string;
|
|
37
|
-
}
|
|
38
|
-
/** Fields that can be updated on a reference node. */
|
|
39
|
-
export interface UpdateReferenceNodeInput {
|
|
40
|
-
/** Updated label. */
|
|
41
|
-
label?: string;
|
|
42
|
-
/** Updated source ID. */
|
|
43
|
-
sourceId?: string;
|
|
44
|
-
/** Updated embedding vector. */
|
|
45
|
-
embedding?: number[];
|
|
46
|
-
}
|
|
47
|
-
/** Fields that can be updated on a native node. */
|
|
48
|
-
export interface UpdateNativeNodeInput {
|
|
49
|
-
/** Updated title. */
|
|
50
|
-
title?: string;
|
|
51
|
-
/** Updated content. */
|
|
52
|
-
content?: string;
|
|
53
|
-
/** Updated tags. */
|
|
54
|
-
tags?: string[];
|
|
55
|
-
/** Updated embedding vector. */
|
|
56
|
-
embedding?: number[];
|
|
57
|
-
}
|
|
58
|
-
/** Union of update inputs for either node kind. */
|
|
59
|
-
export type UpdateNodeInput = UpdateReferenceNodeInput | UpdateNativeNodeInput;
|
|
60
|
-
/** A node together with all its edges. */
|
|
61
|
-
export interface NodeWithEdges {
|
|
62
|
-
/** The knowledge graph node. */
|
|
63
|
-
node: KnowledgeNode;
|
|
64
|
-
/** All edges connected to this node (both incoming and outgoing). */
|
|
65
|
-
edges: KnowledgeEdge[];
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Convert Neo4j node properties to a typed {@link KnowledgeNode}.
|
|
69
|
-
*
|
|
70
|
-
* Handles the discriminated union based on the `kind` property.
|
|
71
|
-
*/
|
|
72
|
-
export declare function recordToNode(properties: Record<string, unknown>): KnowledgeNode;
|
|
73
|
-
/**
|
|
74
|
-
* Convert a raw edge object from Cypher `collect()` to a {@link KnowledgeEdge}.
|
|
75
|
-
*
|
|
76
|
-
* @internal Exported for use by search and expand modules within this package.
|
|
77
|
-
*/
|
|
78
|
-
export declare function recordToEdge(raw: Record<string, unknown>): KnowledgeEdge;
|
|
79
|
-
/**
|
|
80
|
-
* Create a reference node in the knowledge graph.
|
|
81
|
-
*
|
|
82
|
-
* Generates a UUID and timestamps automatically.
|
|
83
|
-
*
|
|
84
|
-
* @returns The ID of the created node.
|
|
85
|
-
*/
|
|
86
|
-
export declare function createReferenceNode(input: CreateReferenceNodeInput): Promise<string>;
|
|
87
|
-
/**
|
|
88
|
-
* Create a native node in the knowledge graph.
|
|
89
|
-
*
|
|
90
|
-
* Generates a UUID and timestamps automatically.
|
|
91
|
-
*
|
|
92
|
-
* @returns The ID of the created node.
|
|
93
|
-
*/
|
|
94
|
-
export declare function createNativeNode(input: CreateNativeNodeInput): Promise<string>;
|
|
95
|
-
/**
|
|
96
|
-
* Get a node by ID, including all its edges.
|
|
97
|
-
*
|
|
98
|
-
* @returns The node and its edges, or `undefined` if the node was not found.
|
|
99
|
-
*/
|
|
100
|
-
export declare function getNode(id: string): Promise<NodeWithEdges | undefined>;
|
|
101
|
-
/**
|
|
102
|
-
* Delete a node and all its edges (`DETACH DELETE`).
|
|
103
|
-
*
|
|
104
|
-
* @returns `true` if a node was deleted, `false` if the node was not found.
|
|
105
|
-
*/
|
|
106
|
-
export declare function deleteNode(id: string): Promise<boolean>;
|
|
107
|
-
/**
|
|
108
|
-
* Update a node's mutable properties.
|
|
109
|
-
*
|
|
110
|
-
* Cannot change `kind`, `id`, `createdAt`, or `workspaceId`.
|
|
111
|
-
* Automatically updates the `updatedAt` timestamp.
|
|
112
|
-
*
|
|
113
|
-
* @returns The updated node, or `undefined` if the node was not found.
|
|
114
|
-
*/
|
|
115
|
-
export declare function updateNode(id: string, updates: UpdateNodeInput): Promise<KnowledgeNode | undefined>;
|
|
116
|
-
//# sourceMappingURL=node-store.d.ts.map
|
package/dist/node-store.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"node-store.d.ts","sourceRoot":"","sources":["../src/node-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EAGL,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,aAAa,EAEnB,MAAM,YAAY,CAAC;AAMpB,2EAA2E;AAC3E,MAAM,WAAW,wBAAwB;IACvC,wCAAwC;IACxC,UAAU,EAAE,eAAe,CAAC;IAC5B,uDAAuD;IACvD,QAAQ,EAAE,MAAM,CAAC;IACjB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,oDAAoD;IACpD,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wEAAwE;AACxE,MAAM,WAAW,qBAAqB;IACpC,sCAAsC;IACtC,QAAQ,EAAE,cAAc,CAAC;IACzB,wBAAwB;IACxB,KAAK,EAAE,MAAM,CAAC;IACd,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,oDAAoD;IACpD,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,+CAA+C;IAC/C,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,sDAAsD;AACtD,MAAM,WAAW,wBAAwB;IACvC,qBAAqB;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yBAAyB;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,mDAAmD;AACnD,MAAM,WAAW,qBAAqB;IACpC,qBAAqB;IACrB,KAAK,CAAC,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
/**
|
|
2
|
-
* Node CRUD operations for the knowledge graph.
|
|
3
|
-
*
|
|
4
|
-
* Provides create, read, update, and delete operations for both
|
|
5
|
-
* {@link ReferenceNode} and {@link NativeNode} types, backed by Neo4j.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import { randomUUID } from "node:crypto";
|
|
10
|
-
import { getSession } from "./client.js";
|
|
11
|
-
import { logger } from "./logger.js";
|
|
12
|
-
import { NODE_LABEL } from "./constants.js";
|
|
13
|
-
import { NODE_KIND, } from "./types.js";
|
|
14
|
-
// ---------------------------------------------------------------------------
|
|
15
|
-
// Cypher queries
|
|
16
|
-
// ---------------------------------------------------------------------------
|
|
17
|
-
const GET_NODE_WITH_EDGES_CYPHER = `
|
|
18
|
-
MATCH (n:${NODE_LABEL} {id: $id})
|
|
19
|
-
OPTIONAL MATCH (n)-[r]-(m:${NODE_LABEL})
|
|
20
|
-
WITH n, r, m
|
|
21
|
-
WHERE r IS NOT NULL
|
|
22
|
-
RETURN n,
|
|
23
|
-
collect({
|
|
24
|
-
fromId: CASE WHEN startNode(r) = n THEN n.id ELSE m.id END,
|
|
25
|
-
toId: CASE WHEN endNode(r) = n THEN n.id ELSE m.id END,
|
|
26
|
-
type: type(r),
|
|
27
|
-
metadata: r.metadata,
|
|
28
|
-
createdAt: r.createdAt
|
|
29
|
-
}) AS edges
|
|
30
|
-
UNION ALL
|
|
31
|
-
MATCH (n:${NODE_LABEL} {id: $id})
|
|
32
|
-
WHERE NOT (n)-[]-()
|
|
33
|
-
RETURN n, [] AS edges`;
|
|
34
|
-
const DELETE_NODE_CYPHER = `
|
|
35
|
-
MATCH (n:${NODE_LABEL} {id: $id})
|
|
36
|
-
DETACH DELETE n
|
|
37
|
-
RETURN count(n) AS deleted`;
|
|
38
|
-
const UPDATE_NODE_CYPHER = `
|
|
39
|
-
MATCH (n:${NODE_LABEL} {id: $id})
|
|
40
|
-
SET n += $updates
|
|
41
|
-
RETURN n`;
|
|
42
|
-
// ---------------------------------------------------------------------------
|
|
43
|
-
// Helpers
|
|
44
|
-
// ---------------------------------------------------------------------------
|
|
45
|
-
/**
|
|
46
|
-
* Convert Neo4j node properties to a typed {@link KnowledgeNode}.
|
|
47
|
-
*
|
|
48
|
-
* Handles the discriminated union based on the `kind` property.
|
|
49
|
-
*/
|
|
50
|
-
export function recordToNode(properties) {
|
|
51
|
-
const base = {
|
|
52
|
-
id: properties.id,
|
|
53
|
-
kind: properties.kind,
|
|
54
|
-
embedding: properties.embedding ?? [],
|
|
55
|
-
createdAt: properties.createdAt,
|
|
56
|
-
updatedAt: properties.updatedAt,
|
|
57
|
-
workspaceId: properties.workspaceId ?? "",
|
|
58
|
-
};
|
|
59
|
-
if (base.kind === NODE_KIND.REFERENCE) {
|
|
60
|
-
return {
|
|
61
|
-
...base,
|
|
62
|
-
kind: NODE_KIND.REFERENCE,
|
|
63
|
-
sourceType: properties.sourceType,
|
|
64
|
-
sourceId: properties.sourceId,
|
|
65
|
-
label: properties.label ?? "",
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
return {
|
|
69
|
-
...base,
|
|
70
|
-
kind: NODE_KIND.NATIVE,
|
|
71
|
-
category: properties.category,
|
|
72
|
-
title: properties.title ?? "",
|
|
73
|
-
content: properties.content ?? "",
|
|
74
|
-
tags: properties.tags ?? [],
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Convert a raw edge object from Cypher `collect()` to a {@link KnowledgeEdge}.
|
|
79
|
-
*
|
|
80
|
-
* @internal Exported for use by search and expand modules within this package.
|
|
81
|
-
*/
|
|
82
|
-
export function recordToEdge(raw) {
|
|
83
|
-
let metadata;
|
|
84
|
-
if (raw.metadata !== undefined && raw.metadata !== null) {
|
|
85
|
-
try {
|
|
86
|
-
metadata = JSON.parse(raw.metadata);
|
|
87
|
-
}
|
|
88
|
-
catch {
|
|
89
|
-
metadata = undefined;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
return {
|
|
93
|
-
fromId: raw.fromId,
|
|
94
|
-
toId: raw.toId,
|
|
95
|
-
type: raw.type,
|
|
96
|
-
metadata,
|
|
97
|
-
createdAt: raw.createdAt,
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
// ---------------------------------------------------------------------------
|
|
101
|
-
// Public API
|
|
102
|
-
// ---------------------------------------------------------------------------
|
|
103
|
-
/**
|
|
104
|
-
* Create a reference node in the knowledge graph.
|
|
105
|
-
*
|
|
106
|
-
* Generates a UUID and timestamps automatically.
|
|
107
|
-
*
|
|
108
|
-
* @returns The ID of the created node.
|
|
109
|
-
*/
|
|
110
|
-
export async function createReferenceNode(input) {
|
|
111
|
-
const id = randomUUID();
|
|
112
|
-
const now = new Date().toISOString();
|
|
113
|
-
const props = {
|
|
114
|
-
id,
|
|
115
|
-
kind: NODE_KIND.REFERENCE,
|
|
116
|
-
sourceType: input.sourceType,
|
|
117
|
-
sourceId: input.sourceId,
|
|
118
|
-
label: input.label,
|
|
119
|
-
embedding: input.embedding,
|
|
120
|
-
workspaceId: input.workspaceId,
|
|
121
|
-
createdAt: now,
|
|
122
|
-
updatedAt: now,
|
|
123
|
-
};
|
|
124
|
-
const session = getSession();
|
|
125
|
-
try {
|
|
126
|
-
await session.run(`CREATE (n:${NODE_LABEL} $props) RETURN n`, { props });
|
|
127
|
-
logger.debug({ nodeId: id, kind: NODE_KIND.REFERENCE }, "Created reference node");
|
|
128
|
-
return id;
|
|
129
|
-
}
|
|
130
|
-
finally {
|
|
131
|
-
try {
|
|
132
|
-
await session.close();
|
|
133
|
-
}
|
|
134
|
-
catch (closeError) {
|
|
135
|
-
logger.warn({ err: closeError }, "Failed to close session after createReferenceNode");
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Create a native node in the knowledge graph.
|
|
141
|
-
*
|
|
142
|
-
* Generates a UUID and timestamps automatically.
|
|
143
|
-
*
|
|
144
|
-
* @returns The ID of the created node.
|
|
145
|
-
*/
|
|
146
|
-
export async function createNativeNode(input) {
|
|
147
|
-
const id = randomUUID();
|
|
148
|
-
const now = new Date().toISOString();
|
|
149
|
-
const props = {
|
|
150
|
-
id,
|
|
151
|
-
kind: NODE_KIND.NATIVE,
|
|
152
|
-
category: input.category,
|
|
153
|
-
title: input.title,
|
|
154
|
-
content: input.content,
|
|
155
|
-
tags: input.tags,
|
|
156
|
-
embedding: input.embedding,
|
|
157
|
-
workspaceId: input.workspaceId,
|
|
158
|
-
createdAt: now,
|
|
159
|
-
updatedAt: now,
|
|
160
|
-
};
|
|
161
|
-
const session = getSession();
|
|
162
|
-
try {
|
|
163
|
-
await session.run(`CREATE (n:${NODE_LABEL} $props) RETURN n`, { props });
|
|
164
|
-
logger.debug({ nodeId: id, kind: NODE_KIND.NATIVE }, "Created native node");
|
|
165
|
-
return id;
|
|
166
|
-
}
|
|
167
|
-
finally {
|
|
168
|
-
try {
|
|
169
|
-
await session.close();
|
|
170
|
-
}
|
|
171
|
-
catch (closeError) {
|
|
172
|
-
logger.warn({ err: closeError }, "Failed to close session after createNativeNode");
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
/**
|
|
177
|
-
* Get a node by ID, including all its edges.
|
|
178
|
-
*
|
|
179
|
-
* @returns The node and its edges, or `undefined` if the node was not found.
|
|
180
|
-
*/
|
|
181
|
-
export async function getNode(id) {
|
|
182
|
-
const session = getSession();
|
|
183
|
-
try {
|
|
184
|
-
const result = await session.run(GET_NODE_WITH_EDGES_CYPHER, { id });
|
|
185
|
-
if (result.records.length === 0) {
|
|
186
|
-
return undefined;
|
|
187
|
-
}
|
|
188
|
-
const record = result.records[0];
|
|
189
|
-
const neo4jNode = record.get("n");
|
|
190
|
-
const rawEdges = record.get("edges");
|
|
191
|
-
const node = recordToNode(neo4jNode.properties);
|
|
192
|
-
const edges = rawEdges.map(recordToEdge);
|
|
193
|
-
return { node, edges };
|
|
194
|
-
}
|
|
195
|
-
finally {
|
|
196
|
-
try {
|
|
197
|
-
await session.close();
|
|
198
|
-
}
|
|
199
|
-
catch (closeError) {
|
|
200
|
-
logger.warn({ err: closeError }, "Failed to close session after getNode");
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
/**
|
|
205
|
-
* Delete a node and all its edges (`DETACH DELETE`).
|
|
206
|
-
*
|
|
207
|
-
* @returns `true` if a node was deleted, `false` if the node was not found.
|
|
208
|
-
*/
|
|
209
|
-
export async function deleteNode(id) {
|
|
210
|
-
const session = getSession();
|
|
211
|
-
try {
|
|
212
|
-
const result = await session.run(DELETE_NODE_CYPHER, { id });
|
|
213
|
-
const deleted = result.records[0]?.get("deleted");
|
|
214
|
-
if (deleted > 0) {
|
|
215
|
-
logger.debug({ nodeId: id }, "Deleted node");
|
|
216
|
-
}
|
|
217
|
-
return deleted > 0;
|
|
218
|
-
}
|
|
219
|
-
finally {
|
|
220
|
-
try {
|
|
221
|
-
await session.close();
|
|
222
|
-
}
|
|
223
|
-
catch (closeError) {
|
|
224
|
-
logger.warn({ err: closeError }, "Failed to close session after deleteNode");
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
/**
|
|
229
|
-
* Update a node's mutable properties.
|
|
230
|
-
*
|
|
231
|
-
* Cannot change `kind`, `id`, `createdAt`, or `workspaceId`.
|
|
232
|
-
* Automatically updates the `updatedAt` timestamp.
|
|
233
|
-
*
|
|
234
|
-
* @returns The updated node, or `undefined` if the node was not found.
|
|
235
|
-
*/
|
|
236
|
-
export async function updateNode(id, updates) {
|
|
237
|
-
// Strip immutable fields defensively.
|
|
238
|
-
const { ...mutableUpdates } = updates;
|
|
239
|
-
const forbidden = ["kind", "id", "createdAt", "workspaceId"];
|
|
240
|
-
for (const key of forbidden) {
|
|
241
|
-
delete mutableUpdates[key];
|
|
242
|
-
}
|
|
243
|
-
const patchedUpdates = {
|
|
244
|
-
...mutableUpdates,
|
|
245
|
-
updatedAt: new Date().toISOString(),
|
|
246
|
-
};
|
|
247
|
-
const session = getSession();
|
|
248
|
-
try {
|
|
249
|
-
const result = await session.run(UPDATE_NODE_CYPHER, {
|
|
250
|
-
id,
|
|
251
|
-
updates: patchedUpdates,
|
|
252
|
-
});
|
|
253
|
-
if (result.records.length === 0) {
|
|
254
|
-
return undefined;
|
|
255
|
-
}
|
|
256
|
-
const neo4jNode = result.records[0].get("n");
|
|
257
|
-
return recordToNode(neo4jNode.properties);
|
|
258
|
-
}
|
|
259
|
-
finally {
|
|
260
|
-
try {
|
|
261
|
-
await session.close();
|
|
262
|
-
}
|
|
263
|
-
catch (closeError) {
|
|
264
|
-
logger.warn({ err: closeError }, "Failed to close session after updateNode");
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
//# sourceMappingURL=node-store.js.map
|
package/dist/node-store.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"node-store.js","sourceRoot":"","sources":["../src/node-store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,SAAS,GAOV,MAAM,YAAY,CAAC;AAqEpB,8EAA8E;AAC9E,iBAAiB;AACjB,8EAA8E;AAE9E,MAAM,0BAA0B,GAAW;aAC9B,UAAU;8BACO,UAAU;;;;;;;;;;;;aAY3B,UAAU;;wBAEC,CAAC;AAEzB,MAAM,kBAAkB,GAAW;aACtB,UAAU;;6BAEM,CAAC;AAE9B,MAAM,kBAAkB,GAAW;aACtB,UAAU;;WAEZ,CAAC;AAEZ,8EAA8E;AAC9E,UAAU;AACV,8EAA8E;AAE9E;;;;GAIG;AACH,MAAM,UAAU,YAAY,C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MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;QAAC,OAAO,UAAU,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,0CAA0C,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;AACH,CAAC"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pass-through chunker that returns the entire input as a single chunk.
|
|
3
|
-
*
|
|
4
|
-
* Suitable for short content such as findings, decisions, and insights
|
|
5
|
-
* that do not need to be split before embedding.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import type { Chunker } from "./chunker.js";
|
|
10
|
-
/**
|
|
11
|
-
* Create a chunker that returns the input as a single chunk unchanged.
|
|
12
|
-
*
|
|
13
|
-
* @returns A {@link Chunker} that produces exactly one chunk per input.
|
|
14
|
-
*/
|
|
15
|
-
export declare function createPassThroughChunker(): Chunker;
|
|
16
|
-
//# sourceMappingURL=pass-through-chunker.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pass-through-chunker.d.ts","sourceRoot":"","sources":["../src/pass-through-chunker.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAS,MAAM,cAAc,CAAC;AAEnD;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,OAAO,CAMlD"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Pass-through chunker that returns the entire input as a single chunk.
|
|
3
|
-
*
|
|
4
|
-
* Suitable for short content such as findings, decisions, and insights
|
|
5
|
-
* that do not need to be split before embedding.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Create a chunker that returns the input as a single chunk unchanged.
|
|
11
|
-
*
|
|
12
|
-
* @returns A {@link Chunker} that produces exactly one chunk per input.
|
|
13
|
-
*/
|
|
14
|
-
export function createPassThroughChunker() {
|
|
15
|
-
return {
|
|
16
|
-
chunk(content, metadata) {
|
|
17
|
-
return [{ text: content, index: 0, metadata }];
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=pass-through-chunker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"pass-through-chunker.js","sourceRoot":"","sources":["../src/pass-through-chunker.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH;;;;GAIG;AACH,MAAM,UAAU,wBAAwB;IACtC,OAAO;QACL,KAAK,CAAC,OAAe,EAAE,QAAkC;YACvD,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAC;QACjD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/schema.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Neo4j schema initialization — constraints, indexes, and vector index.
|
|
3
|
-
*
|
|
4
|
-
* All statements use `IF NOT EXISTS` for idempotency and are safe to run
|
|
5
|
-
* on every application startup.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* Cypher statements for schema initialization.
|
|
11
|
-
*
|
|
12
|
-
* Exported so tests can verify the exact statements that will be executed.
|
|
13
|
-
*/
|
|
14
|
-
export declare const SCHEMA_STATEMENTS: Record<string, string>;
|
|
15
|
-
/**
|
|
16
|
-
* Initialize the Neo4j schema: constraints, property indexes, and the
|
|
17
|
-
* vector index.
|
|
18
|
-
*
|
|
19
|
-
* All statements are idempotent (`IF NOT EXISTS`). Call once at startup
|
|
20
|
-
* after {@link openNeo4j}.
|
|
21
|
-
*/
|
|
22
|
-
export declare function initSchema(): Promise<void>;
|
|
23
|
-
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CA4BpD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC,CAuBhD"}
|
package/dist/schema.js
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Neo4j schema initialization — constraints, indexes, and vector index.
|
|
3
|
-
*
|
|
4
|
-
* All statements use `IF NOT EXISTS` for idempotency and are safe to run
|
|
5
|
-
* on every application startup.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import { getSession } from "./client.js";
|
|
10
|
-
import { logger } from "./logger.js";
|
|
11
|
-
import { NODE_LABEL, VECTOR_INDEX_NAME, EMBEDDING_DIMENSIONS, VECTOR_SIMILARITY_FUNCTION, } from "./constants.js";
|
|
12
|
-
/**
|
|
13
|
-
* Cypher statements for schema initialization.
|
|
14
|
-
*
|
|
15
|
-
* Exported so tests can verify the exact statements that will be executed.
|
|
16
|
-
*/
|
|
17
|
-
export const SCHEMA_STATEMENTS = {
|
|
18
|
-
/** Uniqueness constraint on node ID. */
|
|
19
|
-
UNIQUE_NODE_ID: `CREATE CONSTRAINT knowledge_node_id_unique IF NOT EXISTS
|
|
20
|
-
FOR (n:${NODE_LABEL}) REQUIRE n.id IS UNIQUE`,
|
|
21
|
-
/** Index on the kind property for efficient filtering. */
|
|
22
|
-
INDEX_KIND: `CREATE INDEX knowledge_node_kind IF NOT EXISTS
|
|
23
|
-
FOR (n:${NODE_LABEL}) ON (n.kind)`,
|
|
24
|
-
/** Index on workspaceId for scoped queries. */
|
|
25
|
-
INDEX_WORKSPACE: `CREATE INDEX knowledge_node_workspace IF NOT EXISTS
|
|
26
|
-
FOR (n:${NODE_LABEL}) ON (n.workspaceId)`,
|
|
27
|
-
/** Composite index for reference node lookups by source. */
|
|
28
|
-
INDEX_SOURCE: `CREATE INDEX knowledge_node_source IF NOT EXISTS
|
|
29
|
-
FOR (n:${NODE_LABEL}) ON (n.sourceType, n.sourceId)`,
|
|
30
|
-
/** Vector index for embedding similarity search. */
|
|
31
|
-
VECTOR_INDEX: [
|
|
32
|
-
`CREATE VECTOR INDEX ${VECTOR_INDEX_NAME} IF NOT EXISTS`,
|
|
33
|
-
`FOR (n:${NODE_LABEL}) ON (n.embedding)`,
|
|
34
|
-
`OPTIONS {`,
|
|
35
|
-
` indexConfig: {`,
|
|
36
|
-
` \`vector.dimensions\`: ${EMBEDDING_DIMENSIONS},`,
|
|
37
|
-
` \`vector.similarity_function\`: '${VECTOR_SIMILARITY_FUNCTION}'`,
|
|
38
|
-
` }`,
|
|
39
|
-
`}`,
|
|
40
|
-
].join("\n"),
|
|
41
|
-
};
|
|
42
|
-
/**
|
|
43
|
-
* Initialize the Neo4j schema: constraints, property indexes, and the
|
|
44
|
-
* vector index.
|
|
45
|
-
*
|
|
46
|
-
* All statements are idempotent (`IF NOT EXISTS`). Call once at startup
|
|
47
|
-
* after {@link openNeo4j}.
|
|
48
|
-
*/
|
|
49
|
-
export async function initSchema() {
|
|
50
|
-
const session = getSession();
|
|
51
|
-
try {
|
|
52
|
-
for (const [name, cypher] of Object.entries(SCHEMA_STATEMENTS)) {
|
|
53
|
-
logger.debug({ statement: name }, "Running schema statement");
|
|
54
|
-
try {
|
|
55
|
-
await session.run(cypher);
|
|
56
|
-
}
|
|
57
|
-
catch (error) {
|
|
58
|
-
logger.error({ err: error, statement: name }, "Schema statement failed");
|
|
59
|
-
throw new Error(`Schema statement "${name}" failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
logger.info("Knowledge graph schema initialized");
|
|
63
|
-
}
|
|
64
|
-
finally {
|
|
65
|
-
try {
|
|
66
|
-
await session.close();
|
|
67
|
-
}
|
|
68
|
-
catch (closeError) {
|
|
69
|
-
logger.warn({ err: closeError }, "Failed to close Neo4j session after schema initialization");
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
//# sourceMappingURL=schema.js.map
|
package/dist/schema.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,UAAU,EACV,iBAAiB,EACjB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AAExB;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAA2B;IACvD,wCAAwC;IACxC,cAAc,EAAE;aACL,UAAU,0BAA0B;IAE/C,0DAA0D;IAC1D,UAAU,EAAE;aACD,UAAU,eAAe;IAEpC,+CAA+C;IAC/C,eAAe,EAAE;aACN,UAAU,sBAAsB;IAE3C,4DAA4D;IAC5D,YAAY,EAAE;aACH,UAAU,iCAAiC;IAEtD,oDAAoD;IACpD,YAAY,EAAE;QACZ,uBAAuB,iBAAiB,gBAAgB;QACxD,UAAU,UAAU,oBAAoB;QACxC,WAAW;QACX,kBAAkB;QAClB,8BAA8B,oBAAoB,GAAG;QACrD,wCAAwC,0BAA0B,GAAG;QACrE,KAAK;QACL,GAAG;KACJ,CAAC,IAAI,CAAC,IAAI,CAAC;CACb,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU;IAC9B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,IAAI,CAAC;QACH,KAAK,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,EAAE,CAAC;YAC/D,MAAM,CAAC,KAAK,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,0BAA0B,CAAC,CAAC;YAC9D,IAAI,CAAC;gBACH,MAAM,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YAC5B,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,MAAM,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE,yBAAyB,CAAC,CAAC;gBACzE,MAAM,IAAI,KAAK,CACb,qBAAqB,IAAI,aAAa,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,EAC9F,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;YACJ,CAAC;QACH,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,oCAAoC,CAAC,CAAC;IACpD,CAAC;YAAS,CAAC;QACT,IAAI,CAAC;YACH,MAAM,OAAO,CAAC,KAAK,EAAE,CAAC;QACxB,CAAC;QAAC,OAAO,UAAU,EAAE,CAAC;YACpB,MAAM,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,2DAA2D,CAAC,CAAC;QAChG,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/search.d.ts
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vector-based semantic search across the knowledge graph.
|
|
3
|
-
*
|
|
4
|
-
* Embeds a text query, runs k-NN vector search against Neo4j's vector index,
|
|
5
|
-
* and returns ranked results with similarity scores and immediate edges.
|
|
6
|
-
*
|
|
7
|
-
* @module
|
|
8
|
-
*/
|
|
9
|
-
import type { Embedder } from "./embedder.js";
|
|
10
|
-
import type { KnowledgeNode, KnowledgeEdge, NodeKind } from "./types.js";
|
|
11
|
-
/** Options for knowledge graph search. */
|
|
12
|
-
export interface SearchOptions {
|
|
13
|
-
/** Max results to return (default 10). */
|
|
14
|
-
limit?: number;
|
|
15
|
-
/** Filter to specific node kinds (reference, native, or both). */
|
|
16
|
-
nodeKinds?: NodeKind[];
|
|
17
|
-
/** Minimum similarity score threshold (default 0). Passed directly to the Cypher WHERE clause. */
|
|
18
|
-
minScore?: number;
|
|
19
|
-
/** Filter to a specific workspace. */
|
|
20
|
-
workspaceId?: string;
|
|
21
|
-
}
|
|
22
|
-
/** A search result: a node with its similarity score and immediate edges. */
|
|
23
|
-
export interface SearchResult {
|
|
24
|
-
/** The matched node. */
|
|
25
|
-
node: KnowledgeNode;
|
|
26
|
-
/** Cosine similarity score (0-1). */
|
|
27
|
-
score: number;
|
|
28
|
-
/** Edges connected to this node. */
|
|
29
|
-
edges: KnowledgeEdge[];
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Search the knowledge graph by semantic similarity.
|
|
33
|
-
*
|
|
34
|
-
* Embeds the query text, runs k-NN vector search in Neo4j, and returns
|
|
35
|
-
* ranked results with similarity scores and immediate edges.
|
|
36
|
-
*
|
|
37
|
-
* @param query - The text to search for.
|
|
38
|
-
* @param embedder - Produces the query embedding vector.
|
|
39
|
-
* @param options - Optional search filters and limits.
|
|
40
|
-
* @returns Ranked search results, highest similarity first.
|
|
41
|
-
*/
|
|
42
|
-
export declare function knowledgeSearch(query: string, embedder: Embedder, options?: SearchOptions): Promise<SearchResult[]>;
|
|
43
|
-
//# sourceMappingURL=search.d.ts.map
|
package/dist/search.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAOH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAMzE,0CAA0C;AAC1C,MAAM,WAAW,aAAa;IAC5B,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,kGAAkG;IAClG,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sCAAsC;IACtC,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,6EAA6E;AAC7E,MAAM,WAAW,YAAY;IAC3B,wBAAwB;IACxB,IAAI,EAAE,aAAa,CAAC;IACpB,qCAAqC;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,oCAAoC;IACpC,KAAK,EAAE,aAAa,EAAE,CAAC;CACxB;AAgED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,aAAa,GACtB,OAAO,CAAC,YAAY,EAAE,CAAC,CA8DzB"}
|