@grackle-ai/knowledge-core 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/chunker.d.ts +20 -0
- package/dist/chunker.d.ts.map +1 -0
- package/dist/chunker.js +7 -0
- package/dist/chunker.js.map +1 -0
- package/dist/client.d.ts +68 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +150 -0
- package/dist/client.js.map +1 -0
- package/dist/constants.d.ts +33 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +33 -0
- package/dist/constants.js.map +1 -0
- package/dist/edge-store.d.ts +32 -0
- package/dist/edge-store.d.ts.map +1 -0
- package/dist/edge-store.js +145 -0
- package/dist/edge-store.js.map +1 -0
- package/dist/embedder.d.ts +35 -0
- package/dist/embedder.d.ts.map +1 -0
- package/dist/embedder.js +7 -0
- package/dist/embedder.js.map +1 -0
- package/dist/expand.d.ts +42 -0
- package/dist/expand.d.ts.map +1 -0
- package/dist/expand.js +150 -0
- package/dist/expand.js.map +1 -0
- package/dist/index.d.ts +31 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/ingest.d.ts +23 -0
- package/dist/ingest.d.ts.map +1 -0
- package/dist/ingest.js +27 -0
- package/dist/ingest.js.map +1 -0
- package/dist/local-embedder.d.ts +25 -0
- package/dist/local-embedder.d.ts.map +1 -0
- package/dist/local-embedder.js +88 -0
- package/dist/local-embedder.js.map +1 -0
- package/dist/logger.d.ts +9 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +15 -0
- package/dist/logger.js.map +1 -0
- package/dist/node-store.d.ts +116 -0
- package/dist/node-store.d.ts.map +1 -0
- package/dist/node-store.js +268 -0
- package/dist/node-store.js.map +1 -0
- package/dist/pass-through-chunker.d.ts +16 -0
- package/dist/pass-through-chunker.d.ts.map +1 -0
- package/dist/pass-through-chunker.js +21 -0
- package/dist/pass-through-chunker.js.map +1 -0
- package/dist/schema.d.ts +23 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +73 -0
- package/dist/schema.js.map +1 -0
- package/dist/search.d.ts +43 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +123 -0
- package/dist/search.js.map +1 -0
- package/dist/transcript-chunker.d.ts +29 -0
- package/dist/transcript-chunker.d.ts.map +1 -0
- package/dist/transcript-chunker.js +142 -0
- package/dist/transcript-chunker.js.map +1 -0
- package/dist/types.d.ts +122 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +71 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -0
package/dist/expand.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Graph expansion — traverse the knowledge graph from a starting node
|
|
3
|
+
* to discover connected nodes within N hops.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { getSession } from "./client.js";
|
|
8
|
+
import { logger } from "./logger.js";
|
|
9
|
+
import { NODE_LABEL } from "./constants.js";
|
|
10
|
+
import { recordToNode, recordToEdge } from "./node-store.js";
|
|
11
|
+
import { EDGE_TYPE } from "./types.js";
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Constants
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
/** Default traversal depth. */
|
|
16
|
+
const DEFAULT_DEPTH = 1;
|
|
17
|
+
/** Known edge type values for runtime validation. */
|
|
18
|
+
const VALID_EDGE_TYPES = new Set(Object.values(EDGE_TYPE));
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
// Cypher
|
|
21
|
+
// ---------------------------------------------------------------------------
|
|
22
|
+
/**
|
|
23
|
+
* Build the Cypher query for variable-length path traversal.
|
|
24
|
+
*
|
|
25
|
+
* When edge types are specified, they are interpolated into the relationship
|
|
26
|
+
* pattern (e.g., `[:RELATES_TO|DEPENDS_ON*1..2]`). This is safe because
|
|
27
|
+
* values are validated against the closed {@link EdgeType} union.
|
|
28
|
+
*/
|
|
29
|
+
function buildExpandCypher(depth, edgeTypes) {
|
|
30
|
+
// Neo4j requires integer literals for variable-length ranges — cannot parameterize.
|
|
31
|
+
let relPattern;
|
|
32
|
+
if (edgeTypes && edgeTypes.length > 0) {
|
|
33
|
+
for (const t of edgeTypes) {
|
|
34
|
+
if (!VALID_EDGE_TYPES.has(t)) {
|
|
35
|
+
throw new Error(`Invalid edge type: "${t}". Must be one of: ${[...VALID_EDGE_TYPES].join(", ")}`);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
relPattern = `[:${edgeTypes.join("|")}*1..${depth}]`;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
relPattern = `[*1..${depth}]`;
|
|
42
|
+
}
|
|
43
|
+
return `
|
|
44
|
+
MATCH path = (start:${NODE_LABEL} {id: $startId})-${relPattern}-(neighbor:${NODE_LABEL})
|
|
45
|
+
WHERE neighbor.id <> $startId
|
|
46
|
+
UNWIND relationships(path) AS rel
|
|
47
|
+
WITH DISTINCT neighbor,
|
|
48
|
+
collect(DISTINCT {
|
|
49
|
+
fromId: startNode(rel).id,
|
|
50
|
+
toId: endNode(rel).id,
|
|
51
|
+
type: type(rel),
|
|
52
|
+
metadata: rel.metadata,
|
|
53
|
+
createdAt: rel.createdAt
|
|
54
|
+
}) AS rels
|
|
55
|
+
RETURN neighbor, rels`;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Merge two expansion results, deduplicating nodes by ID and edges by
|
|
59
|
+
* (fromId, toId, type) triple.
|
|
60
|
+
*/
|
|
61
|
+
function mergeResults(a, b) {
|
|
62
|
+
const nodeMap = new Map();
|
|
63
|
+
for (const node of [...a.nodes, ...b.nodes]) {
|
|
64
|
+
nodeMap.set(node.id, node);
|
|
65
|
+
}
|
|
66
|
+
const edgeSet = new Set();
|
|
67
|
+
const edges = [];
|
|
68
|
+
for (const edge of [...a.edges, ...b.edges]) {
|
|
69
|
+
const key = `${edge.fromId}:${edge.toId}:${edge.type}`;
|
|
70
|
+
if (!edgeSet.has(key)) {
|
|
71
|
+
edgeSet.add(key);
|
|
72
|
+
edges.push(edge);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return { nodes: [...nodeMap.values()], edges };
|
|
76
|
+
}
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Public API
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
/**
|
|
81
|
+
* Expand a single node: return its neighbors within N hops.
|
|
82
|
+
*
|
|
83
|
+
* @param nodeId - The starting node ID.
|
|
84
|
+
* @param options - Traversal depth and optional edge type filter.
|
|
85
|
+
* @returns Neighbor nodes and traversed edges (deduplicated).
|
|
86
|
+
*/
|
|
87
|
+
export async function expandNode(nodeId, options) {
|
|
88
|
+
const rawDepth = options?.depth ?? DEFAULT_DEPTH;
|
|
89
|
+
const depth = Number.isFinite(rawDepth) ? Math.max(1, Math.floor(rawDepth)) : DEFAULT_DEPTH;
|
|
90
|
+
const cypher = buildExpandCypher(depth, options?.edgeTypes);
|
|
91
|
+
const session = getSession();
|
|
92
|
+
try {
|
|
93
|
+
const result = await session.run(cypher, { startId: nodeId });
|
|
94
|
+
const nodeMap = new Map();
|
|
95
|
+
const edgeSet = new Set();
|
|
96
|
+
const edges = [];
|
|
97
|
+
for (const record of result.records) {
|
|
98
|
+
const neo4jNode = record.get("neighbor");
|
|
99
|
+
const node = recordToNode(neo4jNode.properties);
|
|
100
|
+
nodeMap.set(node.id, node);
|
|
101
|
+
const rawEdges = record.get("rels");
|
|
102
|
+
for (const raw of rawEdges) {
|
|
103
|
+
if (raw.fromId === null || raw.toId === null) {
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
const edge = recordToEdge(raw);
|
|
107
|
+
const key = `${edge.fromId}:${edge.toId}:${edge.type}`;
|
|
108
|
+
if (!edgeSet.has(key)) {
|
|
109
|
+
edgeSet.add(key);
|
|
110
|
+
edges.push(edge);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
logger.debug({ startId: nodeId, depth, nodes: nodeMap.size, edges: edges.length }, "Graph expansion completed");
|
|
115
|
+
return { nodes: [...nodeMap.values()], edges };
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
try {
|
|
119
|
+
await session.close();
|
|
120
|
+
}
|
|
121
|
+
catch (closeError) {
|
|
122
|
+
logger.warn({ err: closeError }, "Failed to close session after expandNode");
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Expand search results: return neighbors of all result nodes, deduplicated.
|
|
128
|
+
*
|
|
129
|
+
* Runs {@link expandNode} for each search result and merges the subgraphs,
|
|
130
|
+
* excluding the original search result nodes from the neighbor list.
|
|
131
|
+
*
|
|
132
|
+
* @param results - Search results from {@link knowledgeSearch}.
|
|
133
|
+
* @param options - Traversal depth and optional edge type filter.
|
|
134
|
+
* @returns Combined neighbor nodes and edges from all start nodes.
|
|
135
|
+
*/
|
|
136
|
+
export async function expandResults(results, options) {
|
|
137
|
+
if (results.length === 0) {
|
|
138
|
+
return { nodes: [], edges: [] };
|
|
139
|
+
}
|
|
140
|
+
const startIds = new Set(results.map((r) => r.node.id));
|
|
141
|
+
let merged = { nodes: [], edges: [] };
|
|
142
|
+
for (const result of results) {
|
|
143
|
+
const expansion = await expandNode(result.node.id, options);
|
|
144
|
+
merged = mergeResults(merged, expansion);
|
|
145
|
+
}
|
|
146
|
+
// Exclude the original search result nodes from the neighbor list
|
|
147
|
+
merged.nodes = merged.nodes.filter((n) => !startIds.has(n.id));
|
|
148
|
+
return merged;
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=expand.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expand.js","sourceRoot":"","sources":["../src/expand.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,aAA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AAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAE/D,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic knowledge graph SDK on top of Neo4j.
|
|
3
|
+
*
|
|
4
|
+
* Provides pluggable text embedding, content chunking, an ingestion
|
|
5
|
+
* pipeline, node/edge CRUD, semantic search, and graph traversal.
|
|
6
|
+
* Domain-agnostic — consumers define their own source types and categories.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export { openNeo4j, closeNeo4j, healthCheck, getSession, getDriver } from "./client.js";
|
|
11
|
+
export type { Neo4jClientConfig } from "./client.js";
|
|
12
|
+
export { initSchema, SCHEMA_STATEMENTS } from "./schema.js";
|
|
13
|
+
export { logger } from "./logger.js";
|
|
14
|
+
export * from "./types.js";
|
|
15
|
+
export { DEFAULT_NEO4J_URL, DEFAULT_NEO4J_USER, DEFAULT_NEO4J_DATABASE, NEO4J_MAX_POOL_SIZE, NEO4J_CONNECTION_ACQUISITION_TIMEOUT, NODE_LABEL, VECTOR_INDEX_NAME, EMBEDDING_DIMENSIONS, VECTOR_SIMILARITY_FUNCTION, } from "./constants.js";
|
|
16
|
+
export type { Embedder, EmbedderOptions, EmbeddingResult } from "./embedder.js";
|
|
17
|
+
export { createLocalEmbedder } from "./local-embedder.js";
|
|
18
|
+
export type { Chunk, Chunker } from "./chunker.js";
|
|
19
|
+
export { createPassThroughChunker } from "./pass-through-chunker.js";
|
|
20
|
+
export type { EmbeddedChunk } from "./ingest.js";
|
|
21
|
+
export { ingest } from "./ingest.js";
|
|
22
|
+
export type { TranscriptChunkerOptions } from "./transcript-chunker.js";
|
|
23
|
+
export { createTranscriptChunker } from "./transcript-chunker.js";
|
|
24
|
+
export { createReferenceNode, createNativeNode, getNode, deleteNode, updateNode, recordToNode, recordToEdge, } from "./node-store.js";
|
|
25
|
+
export type { CreateReferenceNodeInput, CreateNativeNodeInput, UpdateReferenceNodeInput, UpdateNativeNodeInput, UpdateNodeInput, NodeWithEdges, } from "./node-store.js";
|
|
26
|
+
export { createEdge, removeEdge } from "./edge-store.js";
|
|
27
|
+
export type { SearchOptions, SearchResult } from "./search.js";
|
|
28
|
+
export { knowledgeSearch } from "./search.js";
|
|
29
|
+
export type { ExpandOptions, ExpansionResult } from "./expand.js";
|
|
30
|
+
export { expandNode, expandResults } from "./expand.js";
|
|
31
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxF,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,oCAAoC,EACpC,UAAU,EACV,iBAAiB,EACjB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AACxB,YAAY,EAAE,QAAQ,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AACrE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,YAAY,EAAE,wBAAwB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,OAAO,EACP,UAAU,EACV,UAAU,EACV,YAAY,EACZ,YAAY,GACb,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,wBAAwB,EACxB,qBAAqB,EACrB,wBAAwB,EACxB,qBAAqB,EACrB,eAAe,EACf,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACzD,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic knowledge graph SDK on top of Neo4j.
|
|
3
|
+
*
|
|
4
|
+
* Provides pluggable text embedding, content chunking, an ingestion
|
|
5
|
+
* pipeline, node/edge CRUD, semantic search, and graph traversal.
|
|
6
|
+
* Domain-agnostic — consumers define their own source types and categories.
|
|
7
|
+
*
|
|
8
|
+
* @packageDocumentation
|
|
9
|
+
*/
|
|
10
|
+
export { openNeo4j, closeNeo4j, healthCheck, getSession, getDriver } from "./client.js";
|
|
11
|
+
export { initSchema, SCHEMA_STATEMENTS } from "./schema.js";
|
|
12
|
+
export { logger } from "./logger.js";
|
|
13
|
+
export * from "./types.js";
|
|
14
|
+
export { DEFAULT_NEO4J_URL, DEFAULT_NEO4J_USER, DEFAULT_NEO4J_DATABASE, NEO4J_MAX_POOL_SIZE, NEO4J_CONNECTION_ACQUISITION_TIMEOUT, NODE_LABEL, VECTOR_INDEX_NAME, EMBEDDING_DIMENSIONS, VECTOR_SIMILARITY_FUNCTION, } from "./constants.js";
|
|
15
|
+
export { createLocalEmbedder } from "./local-embedder.js";
|
|
16
|
+
export { createPassThroughChunker } from "./pass-through-chunker.js";
|
|
17
|
+
export { ingest } from "./ingest.js";
|
|
18
|
+
export { createTranscriptChunker } from "./transcript-chunker.js";
|
|
19
|
+
export { createReferenceNode, createNativeNode, getNode, deleteNode, updateNode, recordToNode, recordToEdge, } from "./node-store.js";
|
|
20
|
+
export { createEdge, removeEdge } from "./edge-store.js";
|
|
21
|
+
export { knowledgeSearch } from "./search.js";
|
|
22
|
+
export { expandNode, expandResults } from "./expand.js";
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExF,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAClB,sBAAsB,EACtB,mBAAmB,EACnB,oCAAoC,EACpC,UAAU,EACV,iBAAiB,EACjB,oBAAoB,EACpB,0BAA0B,GAC3B,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAE1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,2BAA2B,CAAC;AAErE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAClE,OAAO,EACL,mBAAmB,EACnB,gBAAgB,EAChB,OAAO,EACP,UAAU,EACV,UAAU,EACV,YAAY,EACZ,YAAY,GACb,MAAM,iBAAiB,CAAC;AASzB,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/ingest.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ingestion pipeline that chunks content and embeds each chunk.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { Chunk, Chunker } from "./chunker.js";
|
|
7
|
+
import type { Embedder } from "./embedder.js";
|
|
8
|
+
/** A chunk with its embedding vector attached. */
|
|
9
|
+
export interface EmbeddedChunk extends Chunk {
|
|
10
|
+
/** The embedding vector for this chunk's text. */
|
|
11
|
+
vector: number[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Chunk content and embed each chunk in a single pipeline.
|
|
15
|
+
*
|
|
16
|
+
* @param content - The raw text content to ingest.
|
|
17
|
+
* @param chunker - Splits the content into chunks.
|
|
18
|
+
* @param embedder - Produces embedding vectors for each chunk.
|
|
19
|
+
* @param metadata - Optional metadata passed through to the chunker.
|
|
20
|
+
* @returns An array of chunks with embedding vectors attached.
|
|
21
|
+
*/
|
|
22
|
+
export declare function ingest(content: string, chunker: Chunker, embedder: Embedder, metadata?: Record<string, unknown>): Promise<EmbeddedChunk[]>;
|
|
23
|
+
//# sourceMappingURL=ingest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest.d.ts","sourceRoot":"","sources":["../src/ingest.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9C,kDAAkD;AAClD,MAAM,WAAW,aAAc,SAAQ,KAAK;IAC1C,kDAAkD;IAClD,MAAM,EAAE,MAAM,EAAE,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAC1B,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GACjC,OAAO,CAAC,aAAa,EAAE,CAAC,CAc1B"}
|
package/dist/ingest.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ingestion pipeline that chunks content and embeds each chunk.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Chunk content and embed each chunk in a single pipeline.
|
|
8
|
+
*
|
|
9
|
+
* @param content - The raw text content to ingest.
|
|
10
|
+
* @param chunker - Splits the content into chunks.
|
|
11
|
+
* @param embedder - Produces embedding vectors for each chunk.
|
|
12
|
+
* @param metadata - Optional metadata passed through to the chunker.
|
|
13
|
+
* @returns An array of chunks with embedding vectors attached.
|
|
14
|
+
*/
|
|
15
|
+
export async function ingest(content, chunker, embedder, metadata) {
|
|
16
|
+
const chunks = chunker.chunk(content, metadata);
|
|
17
|
+
if (chunks.length === 0) {
|
|
18
|
+
return [];
|
|
19
|
+
}
|
|
20
|
+
const texts = chunks.map((c) => c.text);
|
|
21
|
+
const embeddings = await embedder.embedBatch(texts);
|
|
22
|
+
return chunks.map((chunk, i) => ({
|
|
23
|
+
...chunk,
|
|
24
|
+
vector: embeddings[i].vector,
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=ingest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ingest.js","sourceRoot":"","sources":["../src/ingest.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAWH;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,MAAM,CAC1B,OAAe,EACf,OAAgB,EAChB,QAAkB,EAClB,QAAkC;IAElC,MAAM,MAAM,GAAY,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IAEzD,IAAI,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACxB,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,KAAK,GAAa,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;IAClD,MAAM,UAAU,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;IAEpD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAC/B,GAAG,KAAK;QACR,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,MAAM;KAC7B,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local ONNX-based embedder using `@huggingface/transformers`.
|
|
3
|
+
*
|
|
4
|
+
* Downloads and caches a HuggingFace model on first use, then runs
|
|
5
|
+
* inference locally on CPU — no API keys or external services required.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { Embedder, EmbedderOptions } from "./embedder.js";
|
|
10
|
+
/**
|
|
11
|
+
* Create a local embedder that runs ONNX inference via `@huggingface/transformers`.
|
|
12
|
+
*
|
|
13
|
+
* The underlying pipeline is lazily initialized on the first call to
|
|
14
|
+
* {@link Embedder.embed | embed()} or {@link Embedder.embedBatch | embedBatch()}.
|
|
15
|
+
* This avoids blocking construction with a model download.
|
|
16
|
+
*
|
|
17
|
+
* When using the default model, dimensions are known upfront (384). When using
|
|
18
|
+
* a custom model without specifying dimensions, the value is inferred from the
|
|
19
|
+
* first embedding result.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Optional configuration for model selection and dimensions.
|
|
22
|
+
* @returns An {@link Embedder} instance backed by local ONNX inference.
|
|
23
|
+
*/
|
|
24
|
+
export declare function createLocalEmbedder(options?: EmbedderOptions): Embedder;
|
|
25
|
+
//# sourceMappingURL=local-embedder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-embedder.d.ts","sourceRoot":"","sources":["../src/local-embedder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAmB,MAAM,eAAe,CAAC;AAQhF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,CAAC,EAAE,eAAe,GAAG,QAAQ,CA6DvE"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Local ONNX-based embedder using `@huggingface/transformers`.
|
|
3
|
+
*
|
|
4
|
+
* Downloads and caches a HuggingFace model on first use, then runs
|
|
5
|
+
* inference locally on CPU — no API keys or external services required.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
/** Default model: small, fast, good general-purpose English embeddings. */
|
|
10
|
+
const DEFAULT_MODEL_ID = "Xenova/all-MiniLM-L6-v2";
|
|
11
|
+
/** Default embedding dimensions for the default model. */
|
|
12
|
+
const DEFAULT_DIMENSIONS = 384;
|
|
13
|
+
/**
|
|
14
|
+
* Create a local embedder that runs ONNX inference via `@huggingface/transformers`.
|
|
15
|
+
*
|
|
16
|
+
* The underlying pipeline is lazily initialized on the first call to
|
|
17
|
+
* {@link Embedder.embed | embed()} or {@link Embedder.embedBatch | embedBatch()}.
|
|
18
|
+
* This avoids blocking construction with a model download.
|
|
19
|
+
*
|
|
20
|
+
* When using the default model, dimensions are known upfront (384). When using
|
|
21
|
+
* a custom model without specifying dimensions, the value is inferred from the
|
|
22
|
+
* first embedding result.
|
|
23
|
+
*
|
|
24
|
+
* @param options - Optional configuration for model selection and dimensions.
|
|
25
|
+
* @returns An {@link Embedder} instance backed by local ONNX inference.
|
|
26
|
+
*/
|
|
27
|
+
export function createLocalEmbedder(options) {
|
|
28
|
+
const modelId = options?.modelId ?? DEFAULT_MODEL_ID;
|
|
29
|
+
let resolvedDimensions = options?.dimensions ?? (modelId === DEFAULT_MODEL_ID ? DEFAULT_DIMENSIONS : 0);
|
|
30
|
+
let pipelinePromise;
|
|
31
|
+
/**
|
|
32
|
+
* Lazily initialise the feature-extraction pipeline.
|
|
33
|
+
* Concurrent calls share the same promise so the model is loaded once.
|
|
34
|
+
* If initialisation fails, the cached promise is cleared so future calls can retry.
|
|
35
|
+
*/
|
|
36
|
+
function getPipeline() {
|
|
37
|
+
if (!pipelinePromise) {
|
|
38
|
+
pipelinePromise = initPipeline(modelId).catch((error) => {
|
|
39
|
+
pipelinePromise = undefined;
|
|
40
|
+
throw error;
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
return pipelinePromise;
|
|
44
|
+
}
|
|
45
|
+
/** Run inference for a single text and return its vector. */
|
|
46
|
+
async function embedOne(pipe, text) {
|
|
47
|
+
const output = await pipe(text, { pooling: "mean", normalize: true });
|
|
48
|
+
const vector = Array.from(output.data);
|
|
49
|
+
if (resolvedDimensions === 0) {
|
|
50
|
+
resolvedDimensions = vector.length;
|
|
51
|
+
}
|
|
52
|
+
else if (vector.length !== resolvedDimensions) {
|
|
53
|
+
throw new Error(`Dimension mismatch: expected ${resolvedDimensions}, got ${vector.length}. ` +
|
|
54
|
+
`Check that the model "${modelId}" produces ${resolvedDimensions}-dim vectors.`);
|
|
55
|
+
}
|
|
56
|
+
return { text, vector };
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
get dimensions() {
|
|
60
|
+
return resolvedDimensions;
|
|
61
|
+
},
|
|
62
|
+
async embed(text) {
|
|
63
|
+
const pipe = await getPipeline();
|
|
64
|
+
return embedOne(pipe, text);
|
|
65
|
+
},
|
|
66
|
+
async embedBatch(texts) {
|
|
67
|
+
if (texts.length === 0) {
|
|
68
|
+
return [];
|
|
69
|
+
}
|
|
70
|
+
const pipe = await getPipeline();
|
|
71
|
+
const results = [];
|
|
72
|
+
for (const text of texts) {
|
|
73
|
+
results.push(await embedOne(pipe, text));
|
|
74
|
+
}
|
|
75
|
+
return results;
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Dynamically import `@huggingface/transformers` and create the pipeline.
|
|
81
|
+
*
|
|
82
|
+
* Uses dynamic import so the heavy ONNX runtime is only loaded when needed.
|
|
83
|
+
*/
|
|
84
|
+
async function initPipeline(modelId) {
|
|
85
|
+
const { pipeline } = await import("@huggingface/transformers");
|
|
86
|
+
return pipeline("feature-extraction", modelId, { dtype: "fp32" });
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=local-embedder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"local-embedder.js","sourceRoot":"","sources":["../src/local-embedder.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,2EAA2E;AAC3E,MAAM,gBAAgB,GAAW,yBAAyB,CAAC;AAE3D,0DAA0D;AAC1D,MAAM,kBAAkB,GAAW,GAAG,CAAC;AAEvC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAyB;IAC3D,MAAM,OAAO,GAAW,OAAO,EAAE,OAAO,IAAI,gBAAgB,CAAC;IAC7D,IAAI,kBAAkB,GACpB,OAAO,EAAE,UAAU,IAAI,CAAC,OAAO,KAAK,gBAAgB,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAEjF,IAAI,eAA+D,CAAC;IAEpE;;;;OAIG;IACH,SA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YACD,MAAM,IAAI,GAAG,MAAM,WAAW,EAAE,CAAC;YACjC,MAAM,OAAO,GAAsB,EAAE,CAAC;YACtC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,OAAO,CAAC,IAAI,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;YAC3C,CAAC;YACD,OAAO,OAAO,CAAC;QACjB,CAAC;KACF,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,YAAY,CAAC,OAAe;IACzC,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,2BAA2B,CAAC,CAAC;IAC/D,OAAO,QAAQ,CAAC,oBAAoB,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;AACpE,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAa,EAAE,KAAK,MAAM,EAAE,MAAM,MAAM,CAAC;AAEzC,sDAAsD;AACtD,eAAO,MAAM,MAAM,EAAE,MAOnB,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structured logger for the knowledge graph subsystem.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import pino from "pino";
|
|
7
|
+
/** Pino logger instance for the knowledge package. */
|
|
8
|
+
export const logger = pino({
|
|
9
|
+
name: "grackle-knowledge",
|
|
10
|
+
level: process.env.LOG_LEVEL || "info",
|
|
11
|
+
transport: process.env.NODE_ENV !== "production"
|
|
12
|
+
? { target: "pino/file", options: { destination: 1 } }
|
|
13
|
+
: undefined,
|
|
14
|
+
});
|
|
15
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,IAAqB,MAAM,MAAM,CAAC;AAEzC,sDAAsD;AACtD,MAAM,CAAC,MAAM,MAAM,GAAW,IAAI,CAAC;IACjC,IAAI,EAAE,mBAAmB;IACzB,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,IAAI,MAAM;IACtC,SAAS,EACP,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;QACnC,CAAC,CAAC,EAAE,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE,WAAW,EAAE,CAAC,EAAE,EAAE;QACtD,CAAC,CAAC,SAAS;CAChB,CAAC,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,EAAE,MAAM,CAAC;IACf,uBAAuB;IACvB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oB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