hana-kgvector 0.2.11 → 0.2.12
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.md +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +149 -63
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -274,6 +274,7 @@ Retrieve relevant context from the graph.
|
|
|
274
274
|
| `graphName` | `string` | Required | RDF named graph identifier (e.g., `"my_knowledge_graph"`) |
|
|
275
275
|
| `vectorTableName` | `string` | Auto-generated | Custom table name for vector storage |
|
|
276
276
|
| `documentNodesTableName` | `string` | Auto-generated | Custom table name for document nodes |
|
|
277
|
+
| `sqlBatchSize` | `number` | `500` | Prepared statement batch size for vector/document table writes. Can also be set with `HANA_KGVECTOR_SQL_BATCH_SIZE` |
|
|
277
278
|
| `resetTables` | `boolean` | `false` | Drop and recreate tables on init (dev/test only) |
|
|
278
279
|
|
|
279
280
|
### Graph Discovery
|
package/dist/index.d.ts
CHANGED
|
@@ -187,6 +187,8 @@ interface HanaPropertyGraphStoreOptions {
|
|
|
187
187
|
documentNodesTableName?: string;
|
|
188
188
|
/** Optional, unused for dimensionless REAL_VECTOR columns (kept for backward compat logging). */
|
|
189
189
|
vectorDimension?: number;
|
|
190
|
+
/** SQL execBatch chunk size for vector/document table writes. Defaults to HANA_KGVECTOR_SQL_BATCH_SIZE or 500. */
|
|
191
|
+
sqlBatchSize?: number;
|
|
190
192
|
/** If true, will DROP and recreate tables on init (intended for tests/dev only). */
|
|
191
193
|
resetTables?: boolean;
|
|
192
194
|
}
|
|
@@ -195,13 +197,18 @@ declare class HanaPropertyGraphStore implements PropertyGraphStore {
|
|
|
195
197
|
private readonly graphName;
|
|
196
198
|
private readonly vectorTableName;
|
|
197
199
|
private readonly documentNodesTableName;
|
|
200
|
+
private readonly sqlBatchSize;
|
|
198
201
|
private readonly resetTables;
|
|
199
202
|
private initialized;
|
|
200
203
|
readonly supportsVectorQueries = true;
|
|
201
204
|
readonly supportsStructuredQueries = true;
|
|
202
205
|
constructor(conn: HanaConnection, options: HanaPropertyGraphStoreOptions);
|
|
206
|
+
private resolveSqlBatchSize;
|
|
203
207
|
private ensureInitialized;
|
|
204
208
|
private exec;
|
|
209
|
+
private execBatch;
|
|
210
|
+
private uniqueBy;
|
|
211
|
+
private sanitizeRecord;
|
|
205
212
|
private sparqlExecute;
|
|
206
213
|
private entityToUri;
|
|
207
214
|
private relationToTriples;
|
package/dist/index.js
CHANGED
|
@@ -222,6 +222,7 @@ var HanaPropertyGraphStore = class {
|
|
|
222
222
|
graphName;
|
|
223
223
|
vectorTableName;
|
|
224
224
|
documentNodesTableName;
|
|
225
|
+
sqlBatchSize;
|
|
225
226
|
resetTables;
|
|
226
227
|
initialized = false;
|
|
227
228
|
supportsVectorQueries = true;
|
|
@@ -231,8 +232,14 @@ var HanaPropertyGraphStore = class {
|
|
|
231
232
|
this.graphName = options.graphName;
|
|
232
233
|
this.vectorTableName = options.vectorTableName ?? `${options.graphName.replace(/[^a-zA-Z0-9]/g, "_")}_VECTORS`;
|
|
233
234
|
this.documentNodesTableName = options.documentNodesTableName ?? `${options.graphName.replace(/[^a-zA-Z0-9]/g, "_")}_NODES`;
|
|
235
|
+
this.sqlBatchSize = this.resolveSqlBatchSize(options.sqlBatchSize);
|
|
234
236
|
this.resetTables = options.resetTables ?? false;
|
|
235
237
|
}
|
|
238
|
+
resolveSqlBatchSize(configured) {
|
|
239
|
+
const raw = configured ?? Number(process.env.HANA_KGVECTOR_SQL_BATCH_SIZE);
|
|
240
|
+
if (!Number.isFinite(raw) || raw <= 0) return 500;
|
|
241
|
+
return Math.floor(raw);
|
|
242
|
+
}
|
|
236
243
|
async ensureInitialized() {
|
|
237
244
|
if (this.initialized) return;
|
|
238
245
|
if (this.resetTables) {
|
|
@@ -299,6 +306,56 @@ var HanaPropertyGraphStore = class {
|
|
|
299
306
|
}
|
|
300
307
|
});
|
|
301
308
|
}
|
|
309
|
+
async execBatch(sql, paramRows) {
|
|
310
|
+
if (paramRows.length === 0) return;
|
|
311
|
+
if (typeof this.conn.prepare !== "function") {
|
|
312
|
+
for (const params of paramRows) {
|
|
313
|
+
await this.exec(sql, params);
|
|
314
|
+
}
|
|
315
|
+
return;
|
|
316
|
+
}
|
|
317
|
+
for (let i = 0; i < paramRows.length; i += this.sqlBatchSize) {
|
|
318
|
+
const chunk = paramRows.slice(i, i + this.sqlBatchSize);
|
|
319
|
+
const stmt = await new Promise((resolve, reject) => {
|
|
320
|
+
this.conn.prepare(sql, (err, prepared) => {
|
|
321
|
+
if (err) reject(err);
|
|
322
|
+
else resolve(prepared);
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
try {
|
|
326
|
+
if (typeof stmt.execBatch !== "function") {
|
|
327
|
+
for (const params of chunk) {
|
|
328
|
+
await this.exec(sql, params);
|
|
329
|
+
}
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
await new Promise((resolve, reject) => {
|
|
333
|
+
stmt.execBatch(chunk, (err) => {
|
|
334
|
+
if (err) reject(err);
|
|
335
|
+
else resolve();
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
} finally {
|
|
339
|
+
try {
|
|
340
|
+
stmt.drop?.();
|
|
341
|
+
} catch {
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
uniqueBy(items, getId) {
|
|
347
|
+
const byId = /* @__PURE__ */ new Map();
|
|
348
|
+
for (const item of items) {
|
|
349
|
+
byId.set(getId(item), item);
|
|
350
|
+
}
|
|
351
|
+
return Array.from(byId.values());
|
|
352
|
+
}
|
|
353
|
+
sanitizeRecord(record) {
|
|
354
|
+
const safeRecord = { ...record ?? {} };
|
|
355
|
+
delete safeRecord.kg_nodes;
|
|
356
|
+
delete safeRecord.kg_relations;
|
|
357
|
+
return safeRecord;
|
|
358
|
+
}
|
|
302
359
|
async sparqlExecute(sparql, headers = "") {
|
|
303
360
|
try {
|
|
304
361
|
const streamMod = await import("@sap/hana-client/extension/Stream");
|
|
@@ -356,46 +413,54 @@ var HanaPropertyGraphStore = class {
|
|
|
356
413
|
async upsertNodes(nodes) {
|
|
357
414
|
await this.ensureInitialized();
|
|
358
415
|
if (nodes.length === 0) return;
|
|
359
|
-
const
|
|
416
|
+
const uniqueNodes = this.uniqueBy(nodes, (node) => node.id);
|
|
417
|
+
const triples = uniqueNodes.map((n) => this.entityToTriples(n)).join("\n");
|
|
360
418
|
const sparql = `INSERT DATA { GRAPH <${this.graphName}> { ${triples} } }`;
|
|
361
419
|
await this.sparqlExecute(sparql);
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
const
|
|
367
|
-
UPSERT ${this.vectorTableName} (id, node_type, label, name, properties, embedding)
|
|
368
|
-
VALUES (?, 'entity', ?, ?, ?, TO_REAL_VECTOR(?))
|
|
369
|
-
WITH PRIMARY KEY
|
|
370
|
-
` : `
|
|
371
|
-
UPSERT ${this.vectorTableName} (id, node_type, label, name, properties)
|
|
372
|
-
VALUES (?, 'entity', ?, ?, ?)
|
|
373
|
-
WITH PRIMARY KEY
|
|
374
|
-
`;
|
|
375
|
-
const params = [
|
|
376
|
-
node.id,
|
|
377
|
-
node.label,
|
|
378
|
-
node.name,
|
|
379
|
-
JSON.stringify(safeProps)
|
|
380
|
-
];
|
|
420
|
+
const rowsWithEmbedding = [];
|
|
421
|
+
const rowsWithoutEmbedding = [];
|
|
422
|
+
for (const node of uniqueNodes) {
|
|
423
|
+
const safeProps = this.sanitizeRecord(node.properties);
|
|
424
|
+
const row = [node.id, node.label, node.name, JSON.stringify(safeProps)];
|
|
381
425
|
if (node.embedding) {
|
|
382
|
-
|
|
426
|
+
rowsWithEmbedding.push([...row, JSON.stringify(node.embedding)]);
|
|
427
|
+
} else {
|
|
428
|
+
rowsWithoutEmbedding.push(row);
|
|
383
429
|
}
|
|
384
|
-
await this.exec(sql, params);
|
|
385
430
|
}
|
|
431
|
+
await this.execBatch(
|
|
432
|
+
`
|
|
433
|
+
UPSERT ${this.vectorTableName} (id, node_type, label, name, properties)
|
|
434
|
+
VALUES (?, 'entity', ?, ?, ?)
|
|
435
|
+
WITH PRIMARY KEY
|
|
436
|
+
`,
|
|
437
|
+
rowsWithoutEmbedding
|
|
438
|
+
);
|
|
439
|
+
await this.execBatch(
|
|
440
|
+
`
|
|
441
|
+
UPSERT ${this.vectorTableName} (id, node_type, label, name, properties, embedding)
|
|
442
|
+
VALUES (?, 'entity', ?, ?, ?, TO_REAL_VECTOR(?))
|
|
443
|
+
WITH PRIMARY KEY
|
|
444
|
+
`,
|
|
445
|
+
rowsWithEmbedding
|
|
446
|
+
);
|
|
386
447
|
}
|
|
387
448
|
async upsertRelations(relations) {
|
|
388
449
|
await this.ensureInitialized();
|
|
389
450
|
if (relations.length === 0) return;
|
|
451
|
+
const uniqueRelations = this.uniqueBy(
|
|
452
|
+
relations,
|
|
453
|
+
(rel) => rel.id ?? `${rel.sourceId}_${rel.label}_${rel.targetId}`
|
|
454
|
+
);
|
|
390
455
|
const nodeIds = /* @__PURE__ */ new Set();
|
|
391
|
-
for (const rel of
|
|
456
|
+
for (const rel of uniqueRelations) {
|
|
392
457
|
nodeIds.add(rel.sourceId);
|
|
393
458
|
nodeIds.add(rel.targetId);
|
|
394
459
|
}
|
|
395
460
|
const existingNodes = await this.get({ ids: Array.from(nodeIds) });
|
|
396
461
|
const nodeMap = new Map(existingNodes.map((n) => [n.id, n]));
|
|
397
462
|
const lines = [];
|
|
398
|
-
for (const rel of
|
|
463
|
+
for (const rel of uniqueRelations) {
|
|
399
464
|
const subj = nodeMap.get(rel.sourceId);
|
|
400
465
|
const obj = nodeMap.get(rel.targetId);
|
|
401
466
|
if (subj && obj) {
|
|
@@ -408,7 +473,8 @@ var HanaPropertyGraphStore = class {
|
|
|
408
473
|
console.warn(`[HanaPropertyGraphStore] SPARQL INSERT for relations failed (non-fatal):`, err?.message ?? err);
|
|
409
474
|
});
|
|
410
475
|
}
|
|
411
|
-
|
|
476
|
+
const relationRows = [];
|
|
477
|
+
for (const rel of uniqueRelations) {
|
|
412
478
|
const relId = rel.id ?? `${rel.sourceId}_${rel.label}_${rel.targetId}`;
|
|
413
479
|
const safeProps = {
|
|
414
480
|
sourceId: rel.sourceId,
|
|
@@ -417,12 +483,7 @@ var HanaPropertyGraphStore = class {
|
|
|
417
483
|
};
|
|
418
484
|
delete safeProps.kg_nodes;
|
|
419
485
|
delete safeProps.kg_relations;
|
|
420
|
-
|
|
421
|
-
UPSERT ${this.vectorTableName} (id, node_type, label, name, properties, source_id, target_id)
|
|
422
|
-
VALUES (?, 'relation', ?, ?, ?, ?, ?)
|
|
423
|
-
WITH PRIMARY KEY
|
|
424
|
-
`;
|
|
425
|
-
await this.exec(sql, [
|
|
486
|
+
relationRows.push([
|
|
426
487
|
relId,
|
|
427
488
|
rel.label,
|
|
428
489
|
`${rel.sourceId} -> ${rel.targetId}`,
|
|
@@ -431,6 +492,14 @@ var HanaPropertyGraphStore = class {
|
|
|
431
492
|
rel.targetId
|
|
432
493
|
]);
|
|
433
494
|
}
|
|
495
|
+
await this.execBatch(
|
|
496
|
+
`
|
|
497
|
+
UPSERT ${this.vectorTableName} (id, node_type, label, name, properties, source_id, target_id)
|
|
498
|
+
VALUES (?, 'relation', ?, ?, ?, ?, ?)
|
|
499
|
+
WITH PRIMARY KEY
|
|
500
|
+
`,
|
|
501
|
+
relationRows
|
|
502
|
+
);
|
|
434
503
|
}
|
|
435
504
|
async get(opts) {
|
|
436
505
|
await this.ensureInitialized();
|
|
@@ -591,41 +660,58 @@ var HanaPropertyGraphStore = class {
|
|
|
591
660
|
}
|
|
592
661
|
async upsertDocumentNodes(nodes) {
|
|
593
662
|
await this.ensureInitialized();
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
const
|
|
605
|
-
node.id,
|
|
606
|
-
node.text,
|
|
607
|
-
JSON.stringify(safeMetadata ?? {}),
|
|
608
|
-
node.hash ?? null
|
|
609
|
-
];
|
|
610
|
-
if (node.embedding) {
|
|
611
|
-
docParams.push(JSON.stringify(node.embedding));
|
|
612
|
-
}
|
|
613
|
-
await this.exec(docSql, docParams);
|
|
614
|
-
const vecSql = node.embedding ? `
|
|
615
|
-
UPSERT ${this.vectorTableName} (id, node_type, label, name, properties, embedding)
|
|
616
|
-
VALUES (?, 'document', 'DOCUMENT', ?, ?, TO_REAL_VECTOR(?))
|
|
617
|
-
WITH PRIMARY KEY
|
|
618
|
-
` : `
|
|
619
|
-
UPSERT ${this.vectorTableName} (id, node_type, label, name, properties)
|
|
620
|
-
VALUES (?, 'document', 'DOCUMENT', ?, ?)
|
|
621
|
-
WITH PRIMARY KEY
|
|
622
|
-
`;
|
|
623
|
-
const vecParams = [node.id, node.id, JSON.stringify(safeMetadata ?? {})];
|
|
663
|
+
if (nodes.length === 0) return;
|
|
664
|
+
const uniqueNodes = this.uniqueBy(nodes, (node) => node.id);
|
|
665
|
+
const docRowsWithEmbedding = [];
|
|
666
|
+
const docRowsWithoutEmbedding = [];
|
|
667
|
+
const vectorRowsWithEmbedding = [];
|
|
668
|
+
const vectorRowsWithoutEmbedding = [];
|
|
669
|
+
for (const node of uniqueNodes) {
|
|
670
|
+
const safeMetadata = this.sanitizeRecord(node.metadata);
|
|
671
|
+
const metadataJson = JSON.stringify(safeMetadata ?? {});
|
|
672
|
+
const docRow = [node.id, node.text, metadataJson, node.hash ?? null];
|
|
673
|
+
const vectorRow = [node.id, node.id, metadataJson];
|
|
624
674
|
if (node.embedding) {
|
|
625
|
-
|
|
675
|
+
const embeddingJson = JSON.stringify(node.embedding);
|
|
676
|
+
docRowsWithEmbedding.push([...docRow, embeddingJson]);
|
|
677
|
+
vectorRowsWithEmbedding.push([...vectorRow, embeddingJson]);
|
|
678
|
+
} else {
|
|
679
|
+
docRowsWithoutEmbedding.push(docRow);
|
|
680
|
+
vectorRowsWithoutEmbedding.push(vectorRow);
|
|
626
681
|
}
|
|
627
|
-
await this.exec(vecSql, vecParams);
|
|
628
682
|
}
|
|
683
|
+
await this.execBatch(
|
|
684
|
+
`
|
|
685
|
+
UPSERT ${this.documentNodesTableName} (id, text, metadata, hash, embedding)
|
|
686
|
+
VALUES (?, ?, ?, ?, TO_REAL_VECTOR(?))
|
|
687
|
+
WITH PRIMARY KEY
|
|
688
|
+
`,
|
|
689
|
+
docRowsWithEmbedding
|
|
690
|
+
);
|
|
691
|
+
await this.execBatch(
|
|
692
|
+
`
|
|
693
|
+
UPSERT ${this.documentNodesTableName} (id, text, metadata, hash, embedding)
|
|
694
|
+
VALUES (?, ?, ?, ?, NULL)
|
|
695
|
+
WITH PRIMARY KEY
|
|
696
|
+
`,
|
|
697
|
+
docRowsWithoutEmbedding
|
|
698
|
+
);
|
|
699
|
+
await this.execBatch(
|
|
700
|
+
`
|
|
701
|
+
UPSERT ${this.vectorTableName} (id, node_type, label, name, properties, embedding)
|
|
702
|
+
VALUES (?, 'document', 'DOCUMENT', ?, ?, TO_REAL_VECTOR(?))
|
|
703
|
+
WITH PRIMARY KEY
|
|
704
|
+
`,
|
|
705
|
+
vectorRowsWithEmbedding
|
|
706
|
+
);
|
|
707
|
+
await this.execBatch(
|
|
708
|
+
`
|
|
709
|
+
UPSERT ${this.vectorTableName} (id, node_type, label, name, properties)
|
|
710
|
+
VALUES (?, 'document', 'DOCUMENT', ?, ?)
|
|
711
|
+
WITH PRIMARY KEY
|
|
712
|
+
`,
|
|
713
|
+
vectorRowsWithoutEmbedding
|
|
714
|
+
);
|
|
629
715
|
}
|
|
630
716
|
async getDocumentNodes(ids) {
|
|
631
717
|
await this.ensureInitialized();
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hana/parse-host-port.ts","../src/hana/connection.ts","../src/hana/sparql-store.ts","../src/hana/graph-discovery.ts","../src/graph/types.ts","../src/graph/hana-property-graph-store.ts","../src/graph/pg-retriever.ts","../src/graph/retrievers/base.ts","../src/graph/retrievers/vector-context.ts","../src/graph/extractors/implicit.ts","../src/graph/property-graph-index.ts","../src/graph/extractors/schema-llm.ts","../src/graph/extractors/adjacency-linker.ts"],"sourcesContent":["export function parseHostPort(\n host: string,\n fallbackPort: number\n): { host: string; port: number } {\n const idx = host.lastIndexOf(\":\");\n if (idx > -1 && idx < host.length - 1) {\n const maybePort = Number(host.slice(idx + 1));\n if (!Number.isNaN(maybePort) && maybePort > 0) {\n return { host: host.slice(0, idx), port: maybePort };\n }\n }\n\n return { host, port: fallbackPort };\n}\n","import { parseHostPort } from \"./parse-host-port\";\nimport type { HanaConnection, HanaConnectionConfig } from \"./types\";\n\nexport async function createHanaConnection(\n config: HanaConnectionConfig\n): Promise<HanaConnection> {\n let hana: any;\n try {\n const hanaModule = await import(\"@sap/hana-client\");\n hana = (hanaModule as any).default || hanaModule;\n } catch {\n throw new Error(\n \"@sap/hana-client is not available. Ensure it is installed and pnpm build scripts are approved (pnpm approve-builds).\"\n );\n }\n\n const fallbackPort = config.port ?? 443;\n const { host, port } = parseHostPort(config.host, fallbackPort);\n\n const conn: HanaConnection = hana.createConnection();\n\n await new Promise<void>((resolve, reject) => {\n conn.connect(\n {\n serverNode: `${host}:${port}`,\n uid: config.user,\n pwd: config.password,\n encrypt: config.encrypt ?? true,\n sslValidateCertificate: config.sslValidateCertificate ?? true\n },\n (err?: unknown) => (err ? reject(err) : resolve())\n );\n });\n\n return conn;\n}\n\nexport async function hanaExec<T = unknown>(\n conn: HanaConnection,\n sql: string\n): Promise<T> {\n return await new Promise<T>((resolve, reject) => {\n conn.exec(sql, (err: unknown, result: unknown) => {\n if (err) return reject(err);\n resolve(result as T);\n });\n });\n}\n","import type { HanaConnection } from \"./types\";\n\nexport type SparqlExecuteResult = unknown;\n\nexport class HanaSparqlStore {\n private readonly conn: HanaConnection;\n\n constructor(conn: HanaConnection) {\n this.conn = conn;\n }\n\n async execute(options: {\n sparql: string;\n headers?: string;\n defaultGraphUri?: string;\n }): Promise<SparqlExecuteResult> {\n const headerLines: string[] = [];\n\n if (options.defaultGraphUri) {\n headerLines.push(`rqx-default-graph-uri: ${options.defaultGraphUri}`);\n }\n\n if (options.headers) {\n headerLines.push(options.headers.trim());\n }\n\n const hdrs = headerLines.length ? `${headerLines.join(\"\\r\\n\")}\\r\\n` : \"\";\n\n const sql = \"CALL SPARQL_EXECUTE(?, ?, ?, ?)\";\n\n return await new Promise((resolve, reject) => {\n // @sap/hana-client supports conn.exec with parameter arrays.\n // We intentionally keep the result as unknown; callers can parse the XML/JSON depending on HANA return mode.\n (this.conn as any).exec(sql, [options.sparql, hdrs, \"\", null], (err: unknown, result: unknown) => {\n if (err) return reject(err);\n resolve(result);\n });\n });\n }\n\n async loadTurtle(options: {\n turtle: string;\n graphName: string;\n filename?: string;\n }): Promise<SparqlExecuteResult> {\n const requestHdrs = [\n \"rqx-load-protocol: true\",\n options.filename ? `rqx-load-filename: ${options.filename}` : undefined,\n `rqx-load-graphname: ${options.graphName}`\n ]\n .filter(Boolean)\n .join(\"\\r\\n\");\n\n return await this.execute({ sparql: options.turtle, headers: requestHdrs });\n }\n}\n","import type { HanaConnection } from \"./types\";\nimport { hanaExec } from \"./connection\";\n\nexport type HanaKgGraphTableSuffix = \"VECTORS\" | \"NODES\" | \"IMAGES\";\n\nexport type GraphTables = {\n vectorsTable: string;\n nodesTable: string;\n imagesTable: string;\n};\n\nexport type HanaKgGraphInfo = {\n graphName: string;\n hasVectors: boolean;\n hasNodes: boolean;\n hasImages: boolean;\n vectorsCount?: number;\n nodesCount?: number;\n imagesCount?: number;\n};\n\nexport function getGraphTables(graphName: string): GraphTables {\n return {\n vectorsTable: `${graphName}_VECTORS`,\n nodesTable: `${graphName}_NODES`,\n imagesTable: `${graphName}_IMAGES`,\n };\n}\n\nfunction escapeSqlStringLiteral(value: string): string {\n return value.replace(/'/g, \"''\");\n}\n\nfunction normalizeRequirement(req: HanaKgGraphTableSuffix): HanaKgGraphTableSuffix {\n return req.toUpperCase() as HanaKgGraphTableSuffix;\n}\n\nexport async function listGraphs(\n conn: HanaConnection,\n opts?: {\n schema?: string;\n require?: HanaKgGraphTableSuffix[];\n includeCounts?: boolean;\n limit?: number;\n }\n): Promise<HanaKgGraphInfo[]> {\n const schemaFilter = opts?.schema ? ` = '${escapeSqlStringLiteral(opts.schema)}'` : \" = CURRENT_SCHEMA\";\n\n // Discover by our naming convention in a single pass.\n // Note: `_` is a wildcard in LIKE, so we must escape it.\n const rows = (await hanaExec<any[]>(\n conn,\n `SELECT TABLE_NAME\n FROM SYS.TABLES\n WHERE SCHEMA_NAME${schemaFilter}\n AND (\n TABLE_NAME LIKE '%\\\\_VECTORS' ESCAPE '\\\\'\n OR TABLE_NAME LIKE '%\\\\_NODES' ESCAPE '\\\\'\n OR TABLE_NAME LIKE '%\\\\_IMAGES' ESCAPE '\\\\'\n )`\n )) as Array<{ TABLE_NAME?: string; table_name?: string }>;\n\n const tableNames = new Set(\n (rows ?? []).map((r) => String(r.TABLE_NAME ?? r.table_name ?? \"\").toUpperCase()).filter(Boolean)\n );\n\n const stems = new Set<string>();\n for (const t of tableNames) {\n if (t.endsWith(\"_VECTORS\")) {\n stems.add(t.slice(0, -\"_VECTORS\".length));\n }\n }\n\n const infos: HanaKgGraphInfo[] = [];\n for (const stem of stems) {\n const { vectorsTable, nodesTable, imagesTable } = getGraphTables(stem);\n infos.push({\n graphName: stem,\n hasVectors: tableNames.has(vectorsTable),\n hasNodes: tableNames.has(nodesTable),\n hasImages: tableNames.has(imagesTable),\n });\n }\n\n if (opts?.includeCounts) {\n // Only count tables that exist; use quoted identifiers to be robust.\n // NOTE: Table names come from SYS.TABLES results, so this is not user input.\n const schemaName = opts?.schema ? String(opts.schema).toUpperCase() : undefined;\n\n const countTable = async (tableName: string): Promise<number> => {\n const fq = schemaName\n ? `\"${schemaName.replace(/\"/g, '\"\"')}\".\"${tableName.replace(/\"/g, '\"\"')}\"`\n : `\"${tableName.replace(/\"/g, '\"\"')}\"`;\n const res = (await hanaExec<any[]>(conn, `SELECT COUNT(*) AS CNT FROM ${fq}`)) as any[];\n const row = res?.[0];\n const cnt = row?.CNT ?? row?.cnt ?? Object.values(row ?? {})[0];\n return Number(cnt ?? 0);\n };\n\n for (const info of infos) {\n const { vectorsTable, nodesTable, imagesTable } = getGraphTables(info.graphName);\n\n if (info.hasVectors) {\n info.vectorsCount = await countTable(vectorsTable);\n }\n if (info.hasNodes) {\n info.nodesCount = await countTable(nodesTable);\n }\n if (info.hasImages) {\n info.imagesCount = await countTable(imagesTable);\n }\n }\n }\n\n const requireList = (opts?.require ?? []).map(normalizeRequirement);\n const filtered = requireList.length\n ? infos.filter((i) =>\n requireList.every((req) => {\n if (req === \"VECTORS\") return i.hasVectors;\n if (req === \"NODES\") return i.hasNodes;\n if (req === \"IMAGES\") return i.hasImages;\n return false;\n })\n )\n : infos;\n\n filtered.sort((a, b) => a.graphName.localeCompare(b.graphName));\n\n if (opts?.limit !== undefined) {\n return filtered.slice(0, Math.max(0, opts.limit));\n }\n\n return filtered;\n}\n","import { z } from \"zod\";\n\nexport const TRIPLET_SOURCE_KEY = \"triplet_source_id\";\nexport const KG_NODES_KEY = \"kg_nodes\";\nexport const KG_RELATIONS_KEY = \"kg_relations\";\nexport const VECTOR_SOURCE_KEY = \"vector_source_id\";\nexport const KG_SOURCE_REL = \"HAS_SOURCE\";\n\n// Structural adjacency relations (not semantic)\nexport const STRUCT_SAME_PAGE = \"ON_SAME_PAGE\";\nexport const STRUCT_ADJACENT = \"ADJACENT_TO\";\nexport const STRUCT_CONTAINS = \"CONTAINS\";\n\nexport const EntityNodeSchema = z.object({\n id: z.string(),\n label: z.string(),\n name: z.string(),\n properties: z.record(z.unknown()).default({}),\n embedding: z.array(z.number()).optional(),\n});\n\nexport type EntityNode = z.infer<typeof EntityNodeSchema>;\n\nexport const RelationSchema = z.object({\n id: z.string().optional(),\n label: z.string(),\n sourceId: z.string(),\n targetId: z.string(),\n properties: z.record(z.unknown()).default({}),\n});\n\nexport type Relation = z.infer<typeof RelationSchema>;\n\nexport type Triplet = [EntityNode, Relation, EntityNode];\n\nexport type LabelledNode = EntityNode;\n\nexport interface NodeWithScore {\n node: {\n id: string;\n text: string;\n metadata: Record<string, unknown>;\n refDocId?: string;\n };\n score: number;\n}\n\nexport interface QueryBundle {\n queryStr: string;\n embedding?: number[];\n embeddingStrs?: string[];\n}\n\nexport function createEntityNode(opts: {\n label: string;\n name: string;\n properties?: Record<string, unknown>;\n embedding?: number[];\n}): EntityNode {\n const id = `${opts.label.toUpperCase()}_${opts.name.replace(/\\s+/g, \"_\").toUpperCase()}`;\n return {\n id,\n label: opts.label,\n name: opts.name,\n properties: opts.properties ?? {},\n embedding: opts.embedding,\n };\n}\n\nexport function createRelation(opts: {\n label: string;\n sourceId: string;\n targetId: string;\n properties?: Record<string, unknown>;\n}): Relation {\n return {\n id: `${opts.sourceId}_${opts.label}_${opts.targetId}`,\n label: opts.label,\n sourceId: opts.sourceId,\n targetId: opts.targetId,\n properties: opts.properties ?? {},\n };\n}\n\nexport function tripletToString(triplet: Triplet, includeProperties = false): string {\n const [subj, rel, obj] = triplet;\n if (includeProperties) {\n return `${subj.name} (${subj.label}) -[${rel.label}]-> ${obj.name} (${obj.label})`;\n }\n return `${subj.id} -> ${rel.label} -> ${obj.id}`;\n}\n","import type { HanaConnection } from \"../hana/types\";\nimport type { PropertyGraphStore, VectorStoreQuery } from \"./property-graph-store\";\nimport type { EntityNode, Relation, Triplet, LabelledNode } from \"./types\";\nimport { TRIPLET_SOURCE_KEY, KG_SOURCE_REL } from \"./types\";\n\ntype DocumentNode = {\n id: string;\n text: string;\n metadata: Record<string, unknown>;\n embedding?: number[];\n hash?: string;\n};\n\nexport interface HanaPropertyGraphStoreOptions {\n graphName: string;\n vectorTableName?: string;\n documentNodesTableName?: string;\n /** Optional, unused for dimensionless REAL_VECTOR columns (kept for backward compat logging). */\n vectorDimension?: number;\n /** If true, will DROP and recreate tables on init (intended for tests/dev only). */\n resetTables?: boolean;\n}\n\nexport class HanaPropertyGraphStore implements PropertyGraphStore {\n private readonly conn: HanaConnection;\n private readonly graphName: string;\n private readonly vectorTableName: string;\n private readonly documentNodesTableName: string;\n private readonly resetTables: boolean;\n private initialized = false;\n\n readonly supportsVectorQueries = true;\n readonly supportsStructuredQueries = true;\n\n constructor(conn: HanaConnection, options: HanaPropertyGraphStoreOptions) {\n this.conn = conn;\n this.graphName = options.graphName;\n this.vectorTableName = options.vectorTableName ?? `${options.graphName.replace(/[^a-zA-Z0-9]/g, \"_\")}_VECTORS`;\n this.documentNodesTableName = options.documentNodesTableName ?? `${options.graphName.replace(/[^a-zA-Z0-9]/g, \"_\")}_NODES`;\n this.resetTables = options.resetTables ?? false;\n }\n\n private async ensureInitialized(): Promise<void> {\n if (this.initialized) return;\n\n // Optional destructive reset intended for tests/dev. This is OFF by default.\n if (this.resetTables) {\n await this.exec(`DROP TABLE ${this.vectorTableName}`).catch(() => {});\n await this.exec(`DROP TABLE ${this.documentNodesTableName}`).catch(() => {});\n\n // Also clear the RDF named graph to avoid accumulating triples across test runs.\n // (Tables are recreated, but the KG graph would otherwise persist.)\n await this.sparqlExecute(`CLEAR GRAPH <${this.graphName}>`).catch(() => {});\n }\n\n // HANA does not support \"IF NOT EXISTS\" for CREATE TABLE. We try to create and ignore the\n // \"name exists\" error, but surface any other errors.\n const createVectorTable = `\n CREATE COLUMN TABLE ${this.vectorTableName} (\n id NVARCHAR(512) PRIMARY KEY,\n node_type NVARCHAR(64),\n label NVARCHAR(128),\n name NVARCHAR(512),\n properties NCLOB,\n source_id NVARCHAR(512),\n target_id NVARCHAR(512),\n embedding REAL_VECTOR\n )\n `;\n await this.exec(createVectorTable).catch((err: any) => {\n const message = String(err?.message ?? \"\");\n // Handle \"duplicate table name\" or \"already exists\"\n if (!/exists|duplicate table name/i.test(message)) {\n throw err;\n }\n });\n\n // Migrate existing tables that lack the source_id / target_id columns.\n await this.exec(`ALTER TABLE ${this.vectorTableName} ADD (source_id NVARCHAR(512), target_id NVARCHAR(512))`).catch((err: any) => {\n const message = String(err?.message ?? \"\");\n // Ignore if columns already exist\n if (!/duplicate column|already exists/i.test(message)) {\n throw err;\n }\n });\n\n const createDocumentTable = `\n CREATE COLUMN TABLE ${this.documentNodesTableName} (\n id NVARCHAR(512) PRIMARY KEY,\n text NCLOB,\n metadata NCLOB,\n hash NVARCHAR(64),\n embedding REAL_VECTOR\n )\n `;\n await this.exec(createDocumentTable).catch((err: any) => {\n const message = String(err?.message ?? \"\");\n if (!/exists|duplicate table name/i.test(message)) {\n throw err;\n }\n });\n\n this.initialized = true;\n }\n\n private async exec(sql: string, params?: unknown[]): Promise<unknown[]> {\n return new Promise((resolve, reject) => {\n if (params && params.length > 0) {\n (this.conn as any).exec(sql, params, (err: unknown, result: unknown) => {\n if (err) reject(err);\n else resolve(result as unknown[]);\n });\n } else {\n this.conn.exec(sql, (err: unknown, result: unknown) => {\n if (err) reject(err);\n else resolve(result as unknown[]);\n });\n }\n });\n }\n\n private async sparqlExecute(sparql: string, headers = \"\"): Promise<unknown> {\n // Some HANA environments require OUT parameters (e.g. RESPONSE) to be bound.\n // The @sap/hana-client driver provides a proc statement helper which correctly\n // handles OUT params *without* requiring you to pass them in the params array.\n try {\n const streamMod = await import(\"@sap/hana-client/extension/Stream\");\n const Stream = (streamMod as any).default ?? streamMod;\n\n return await new Promise<unknown>((resolve, reject) => {\n Stream.createProcStatement(this.conn as any, \"CALL SPARQL_EXECUTE(?, ?, ?, ?)\", (err: any, stmt: any) => {\n if (err) return reject(err);\n stmt.exec([sparql, headers], (err2: any, scalarParams: any) => {\n // scalarParams contains OUT params by name (e.g. RESPONSE)\n if (err2) return reject(err2);\n resolve(scalarParams);\n });\n });\n });\n } catch {\n // Fallback (may fail on systems requiring bound OUT params)\n return await new Promise<unknown>((resolve, reject) => {\n (this.conn as any).exec(\n \"CALL SPARQL_EXECUTE(?, ?, ?, ?)\",\n // Important: only pass IN params; OUT params are placeholders in SQL.\n [sparql, headers],\n (err: unknown, result: unknown) => {\n if (err) reject(err);\n else resolve(result);\n }\n );\n });\n }\n }\n\n private entityToUri(node: EntityNode): string {\n return `<urn:hkv:${this.graphName}:${node.label}:${encodeURIComponent(node.id)}>`;\n }\n\n private relationToTriples(rel: Relation, subj: EntityNode, obj: EntityNode): string {\n const subjUri = this.entityToUri(subj);\n const objUri = this.entityToUri(obj);\n const predUri = `<urn:hkv:rel:${rel.label}>`;\n return `${subjUri} ${predUri} ${objUri} .`;\n }\n\n private entityToTriples(node: EntityNode): string {\n const uri = this.entityToUri(node);\n const lines: string[] = [];\n lines.push(`${uri} a <urn:hkv:type:${node.label}> .`);\n lines.push(`${uri} <urn:hkv:prop:name> \"${this.escapeLiteral(node.name)}\" .`);\n\n for (const [key, value] of Object.entries(node.properties)) {\n if (value !== undefined && value !== null) {\n const strVal = typeof value === \"string\" ? value : String(value);\n // Skip overly large properties in RDF — they are already stored in the vectors table\n if (strVal.length > 5000) continue;\n const escaped = this.escapeLiteral(strVal);\n lines.push(`${uri} <urn:hkv:prop:${key}> \"${escaped}\" .`);\n }\n }\n\n return lines.join(\"\\n\");\n }\n\n private escapeLiteral(s: string): string {\n return s\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, \"\\\\n\")\n .replace(/\\r/g, \"\\\\r\")\n .replace(/\\t/g, \"\\\\t\");\n }\n\n async upsertNodes(nodes: EntityNode[]): Promise<void> {\n await this.ensureInitialized();\n if (nodes.length === 0) return;\n\n const triples = nodes.map((n) => this.entityToTriples(n)).join(\"\\n\");\n const sparql = `INSERT DATA { GRAPH <${this.graphName}> { ${triples} } }`;\n await this.sparqlExecute(sparql);\n\n for (const node of nodes) {\n // Defensive: prevent circular references from being serialized into NCLOB\n const safeProps: Record<string, unknown> = { ...(node.properties ?? {}) };\n delete (safeProps as any).kg_nodes;\n delete (safeProps as any).kg_relations;\n\n const sql = node.embedding\n ? `\n UPSERT ${this.vectorTableName} (id, node_type, label, name, properties, embedding)\n VALUES (?, 'entity', ?, ?, ?, TO_REAL_VECTOR(?))\n WITH PRIMARY KEY\n `\n : `\n UPSERT ${this.vectorTableName} (id, node_type, label, name, properties)\n VALUES (?, 'entity', ?, ?, ?)\n WITH PRIMARY KEY\n `;\n const params: unknown[] = [\n node.id,\n node.label,\n node.name,\n JSON.stringify(safeProps),\n ];\n if (node.embedding) {\n params.push(JSON.stringify(node.embedding));\n }\n await this.exec(sql, params);\n }\n }\n\n async upsertRelations(relations: Relation[]): Promise<void> {\n await this.ensureInitialized();\n if (relations.length === 0) return;\n\n const nodeIds = new Set<string>();\n for (const rel of relations) {\n nodeIds.add(rel.sourceId);\n nodeIds.add(rel.targetId);\n }\n\n const existingNodes = await this.get({ ids: Array.from(nodeIds) });\n const nodeMap = new Map(existingNodes.map((n) => [n.id, n]));\n\n // Write to RDF graph (backward compat — kept for installations that use SPARQL)\n const lines: string[] = [];\n for (const rel of relations) {\n const subj = nodeMap.get(rel.sourceId);\n const obj = nodeMap.get(rel.targetId);\n if (subj && obj) {\n lines.push(this.relationToTriples(rel, subj, obj));\n }\n }\n\n if (lines.length > 0) {\n const sparql = `INSERT DATA { GRAPH <${this.graphName}> { ${lines.join(\"\\n\")} } }`;\n await this.sparqlExecute(sparql).catch((err: any) => {\n // SPARQL may fail if KG Engine is not enabled — log but don't block\n console.warn(`[HanaPropertyGraphStore] SPARQL INSERT for relations failed (non-fatal):`, err?.message ?? err);\n });\n }\n\n // Write to _VECTORS table for reliable SQL-based querying via getRelMap()\n for (const rel of relations) {\n const relId = rel.id ?? `${rel.sourceId}_${rel.label}_${rel.targetId}`;\n const safeProps: Record<string, unknown> = {\n sourceId: rel.sourceId,\n targetId: rel.targetId,\n ...(rel.properties ?? {}),\n };\n delete (safeProps as any).kg_nodes;\n delete (safeProps as any).kg_relations;\n\n const sql = `\n UPSERT ${this.vectorTableName} (id, node_type, label, name, properties, source_id, target_id)\n VALUES (?, 'relation', ?, ?, ?, ?, ?)\n WITH PRIMARY KEY\n `;\n await this.exec(sql, [\n relId,\n rel.label,\n `${rel.sourceId} -> ${rel.targetId}`,\n JSON.stringify(safeProps),\n rel.sourceId,\n rel.targetId,\n ]);\n }\n }\n\n async get(opts: { ids: string[] }): Promise<LabelledNode[]> {\n await this.ensureInitialized();\n if (opts.ids.length === 0) return [];\n\n const rows = (await this.exec(\n `SELECT id, label, name, properties FROM ${this.vectorTableName} WHERE id IN (${opts.ids.map(() => \"?\").join(\",\")})`,\n opts.ids\n )) as any[];\n\n return (rows ?? []).map((r) => ({\n id: r.ID ?? r.id,\n label: r.LABEL ?? r.label,\n name: r.NAME ?? r.name,\n properties: JSON.parse(r.PROPERTIES ?? r.properties ?? \"{}\"),\n }));\n }\n\n async getRelMap(opts: {\n nodes: LabelledNode[];\n depth?: number;\n limit?: number;\n ignoreRels?: string[];\n }): Promise<Triplet[]> {\n await this.ensureInitialized();\n if (opts.nodes.length === 0) return [];\n\n const nodeIds = opts.nodes.map((n) => n.id);\n const depth = opts.depth ?? 1;\n const limit = opts.limit ?? 100;\n const ignoreRels = opts.ignoreRels ?? [KG_SOURCE_REL];\n const ignoreRelSet = new Set(ignoreRels);\n\n const triplets: Triplet[] = [];\n const seenKeys = new Set<string>();\n const nodeMap = new Map(opts.nodes.map((n) => [n.id, n]));\n\n // --- SQL path: query _VECTORS WHERE node_type='relation' ---\n const placeholders = nodeIds.map(() => \"?\").join(\",\");\n const sqlRelQuery = `\n SELECT id, label, name, properties, source_id, target_id\n FROM ${this.vectorTableName}\n WHERE node_type = 'relation'\n AND (source_id IN (${placeholders}) OR target_id IN (${placeholders}))\n LIMIT ?\n `;\n const sqlParams = [...nodeIds, ...nodeIds, limit];\n\n try {\n const sqlRows = (await this.exec(sqlRelQuery, sqlParams)) as any[];\n for (const row of sqlRows ?? []) {\n const relLabel = row.LABEL ?? row.label;\n const sourceId = row.SOURCE_ID ?? row.source_id;\n const targetId = row.TARGET_ID ?? row.target_id;\n\n if (ignoreRelSet.has(relLabel)) continue;\n\n const key = `${sourceId}|${relLabel}|${targetId}`;\n if (seenKeys.has(key)) continue;\n seenKeys.add(key);\n\n let subj = nodeMap.get(sourceId);\n let obj = nodeMap.get(targetId);\n\n if (!subj) {\n subj = { id: sourceId, label: \"UNKNOWN\", name: sourceId, properties: {} };\n }\n if (!obj) {\n obj = { id: targetId, label: \"UNKNOWN\", name: targetId, properties: {} };\n }\n\n const rel: Relation = {\n id: row.ID ?? row.id,\n label: relLabel,\n sourceId,\n targetId,\n properties: JSON.parse(row.PROPERTIES ?? row.properties ?? \"{}\"),\n };\n\n triplets.push([subj, rel, obj]);\n }\n } catch (err: any) {\n console.warn(`[HanaPropertyGraphStore] SQL relation query failed (falling back to SPARQL only):`, err?.message ?? err);\n }\n\n // --- SPARQL path: query RDF graph (backward compat) ---\n try {\n const filterClause = nodeIds\n .map((id) => `CONTAINS(STR(?s), \"${encodeURIComponent(id)}\") || CONTAINS(STR(?o), \"${encodeURIComponent(id)}\")`)\n .join(\" || \");\n\n const ignoreFilter = ignoreRels.length > 0\n ? `FILTER(${ignoreRels.map((r) => `!CONTAINS(STR(?p), \"${r}\")`).join(\" && \")})`\n : \"\";\n\n const sparql = `\n SELECT ?s ?p ?o\n FROM <${this.graphName}>\n WHERE {\n ?s ?p ?o .\n FILTER(${filterClause})\n ${ignoreFilter}\n }\n LIMIT ${limit}\n `;\n\n const result = await this.exec(\n `SELECT * FROM SPARQL_TABLE('${sparql.replace(/'/g, \"''\")}')`\n ) as any[];\n\n for (const row of result ?? []) {\n const sUri = row.S ?? row.s;\n const pUri = row.P ?? row.p;\n const oUri = row.O ?? row.o;\n\n const sId = this.extractIdFromUri(sUri);\n const oId = this.extractIdFromUri(oUri);\n const relLabel = this.extractRelLabelFromUri(pUri);\n\n const key = `${sId}|${relLabel}|${oId}`;\n if (seenKeys.has(key)) continue;\n seenKeys.add(key);\n\n let subj = nodeMap.get(sId);\n let obj = nodeMap.get(oId);\n\n if (!subj) {\n subj = { id: sId, label: \"UNKNOWN\", name: sId, properties: {} };\n }\n if (!obj) {\n obj = { id: oId, label: \"UNKNOWN\", name: oId, properties: {} };\n }\n\n const rel: Relation = {\n label: relLabel,\n sourceId: sId,\n targetId: oId,\n properties: {},\n };\n\n triplets.push([subj, rel, obj]);\n }\n } catch (err: any) {\n // SPARQL may fail if KG Engine is not enabled — log but don't block\n console.warn(`[HanaPropertyGraphStore] SPARQL relation query failed (non-fatal):`, err?.message ?? err);\n }\n\n return triplets;\n }\n\n private extractIdFromUri(uri: string): string {\n // URI format: <urn:hkv:graphName:label:id> or just the content without angle brackets\n // The ID is the last segment after the label (second-to-last segment)\n const cleanUri = uri.replace(/^<|>$/g, \"\");\n const parts = cleanUri.split(\":\");\n // ID is the last part, decode it\n if (parts.length >= 2) {\n return decodeURIComponent(parts[parts.length - 1]);\n }\n return uri;\n }\n\n private extractRelLabelFromUri(uri: string): string {\n const match = uri.match(/urn:hkv:rel:(.+)>?$/);\n return match ? match[1].replace(/>$/, \"\") : uri;\n }\n\n async delete(opts: { ids: string[] }): Promise<void> {\n await this.ensureInitialized();\n if (opts.ids.length === 0) return;\n\n for (const id of opts.ids) {\n await this.exec(`DELETE FROM ${this.vectorTableName} WHERE id = ?`, [id]);\n }\n }\n\n async vectorQuery(query: VectorStoreQuery): Promise<[LabelledNode[], number[]]> {\n await this.ensureInitialized();\n\n const sql = `\n SELECT id, label, name, properties,\n COSINE_SIMILARITY(embedding, TO_REAL_VECTOR(?)) AS score\n FROM ${this.vectorTableName}\n WHERE embedding IS NOT NULL\n ORDER BY score DESC\n LIMIT ?\n `;\n\n const rows = (await this.exec(sql, [\n JSON.stringify(query.queryEmbedding),\n query.similarityTopK,\n ])) as any[];\n\n const nodes: LabelledNode[] = [];\n const scores: number[] = [];\n\n for (const row of rows ?? []) {\n nodes.push({\n id: row.ID ?? row.id,\n label: row.LABEL ?? row.label,\n name: row.NAME ?? row.name,\n properties: JSON.parse(row.PROPERTIES ?? row.properties ?? \"{}\"),\n });\n scores.push(row.SCORE ?? row.score ?? 0);\n }\n\n return [nodes, scores];\n }\n\n async upsertDocumentNodes(nodes: DocumentNode[]): Promise<void> {\n await this.ensureInitialized();\n for (const node of nodes) {\n // Remove circular references from metadata before serialization\n const { metadata, ...rest } = node;\n const safeMetadata = { ...metadata };\n delete (safeMetadata as any).kg_nodes;\n delete (safeMetadata as any).kg_relations;\n\n // Write to _NODES table (text + metadata storage)\n const docSql = `\n UPSERT ${this.documentNodesTableName} (id, text, metadata, hash, embedding)\n VALUES (?, ?, ?, ?, ${node.embedding ? \"TO_REAL_VECTOR(?)\" : \"NULL\"})\n WITH PRIMARY KEY\n `;\n const docParams: unknown[] = [\n node.id,\n node.text,\n JSON.stringify(safeMetadata ?? {}),\n node.hash ?? null,\n ];\n if (node.embedding) {\n docParams.push(JSON.stringify(node.embedding));\n }\n await this.exec(docSql, docParams);\n\n // Also write to _VECTORS table so vectorQuery() can find document nodes.\n // NODE_TYPE='document' distinguishes them from entity nodes.\n const vecSql = node.embedding\n ? `\n UPSERT ${this.vectorTableName} (id, node_type, label, name, properties, embedding)\n VALUES (?, 'document', 'DOCUMENT', ?, ?, TO_REAL_VECTOR(?))\n WITH PRIMARY KEY\n `\n : `\n UPSERT ${this.vectorTableName} (id, node_type, label, name, properties)\n VALUES (?, 'document', 'DOCUMENT', ?, ?)\n WITH PRIMARY KEY\n `;\n const vecParams: unknown[] = [node.id, node.id, JSON.stringify(safeMetadata ?? {})];\n if (node.embedding) {\n vecParams.push(JSON.stringify(node.embedding));\n }\n await this.exec(vecSql, vecParams);\n }\n }\n\n async getDocumentNodes(ids: string[]): Promise<DocumentNode[]> {\n await this.ensureInitialized();\n if (ids.length === 0) return [];\n\n const rows = (await this.exec(\n `SELECT id, text, metadata, hash FROM ${this.documentNodesTableName} WHERE id IN (${ids.map(() => \"?\").join(\",\")})`,\n ids\n )) as any[];\n\n return (rows ?? []).map((r) => ({\n id: r.ID ?? r.id,\n text: r.TEXT ?? r.text,\n metadata: JSON.parse(r.METADATA ?? r.metadata ?? \"{}\"),\n hash: r.HASH ?? r.hash,\n }));\n }\n}\n","import type { QueryBundle, NodeWithScore } from \"./types\";\nimport type { BasePGRetriever } from \"./retrievers/base\";\n\nexport interface PGRetrieverOptions {\n subRetrievers: BasePGRetriever[];\n showProgress?: boolean;\n}\n\nexport class PGRetriever {\n private readonly subRetrievers: BasePGRetriever[];\n private readonly showProgress: boolean;\n\n constructor(options: PGRetrieverOptions) {\n this.subRetrievers = options.subRetrievers;\n this.showProgress = options.showProgress ?? false;\n }\n\n private deduplicate(nodes: NodeWithScore[]): NodeWithScore[] {\n const seen = new Set<string>();\n const deduped: NodeWithScore[] = [];\n\n for (const node of nodes) {\n if (!seen.has(node.node.text)) {\n deduped.push(node);\n seen.add(node.node.text);\n }\n }\n\n return deduped;\n }\n\n async retrieve(queryBundle: QueryBundle): Promise<NodeWithScore[]> {\n const allResults: NodeWithScore[] = [];\n\n const promises = this.subRetrievers.map((r) => r.retrieve(queryBundle));\n const results = await Promise.all(promises);\n\n for (const result of results) {\n allResults.push(...result);\n }\n\n return this.deduplicate(allResults);\n }\n}\n","import type { PropertyGraphStore } from \"../property-graph-store\";\nimport type { Triplet, NodeWithScore, QueryBundle, LabelledNode } from \"../types\";\nimport { TRIPLET_SOURCE_KEY, tripletToString } from \"../types\";\n\nexport const DEFAULT_PREAMBLE = \"Here are some facts extracted from the provided text:\\n\\n\";\n\nexport interface BasePGRetrieverOptions {\n graphStore: PropertyGraphStore;\n includeText?: boolean;\n includeTextPreamble?: string;\n includeProperties?: boolean;\n}\n\nexport abstract class BasePGRetriever {\n protected readonly graphStore: PropertyGraphStore;\n protected readonly includeText: boolean;\n protected readonly includeTextPreamble: string;\n protected readonly includeProperties: boolean;\n\n constructor(options: BasePGRetrieverOptions) {\n this.graphStore = options.graphStore;\n this.includeText = options.includeText ?? true;\n this.includeTextPreamble = options.includeTextPreamble ?? DEFAULT_PREAMBLE;\n this.includeProperties = options.includeProperties ?? false;\n }\n\n protected getNodesWithScore(triplets: Triplet[], scores?: number[]): NodeWithScore[] {\n const results: NodeWithScore[] = [];\n\n for (let i = 0; i < triplets.length; i++) {\n const triplet = triplets[i];\n const sourceId = triplet[0].properties[TRIPLET_SOURCE_KEY] as string | undefined;\n\n const text = tripletToString(triplet, this.includeProperties);\n\n results.push({\n node: {\n id: `triplet_${i}`,\n text,\n metadata: {},\n refDocId: sourceId,\n },\n score: scores?.[i] ?? 1.0,\n });\n }\n\n return results;\n }\n\n protected async addSourceText(nodes: NodeWithScore[]): Promise<NodeWithScore[]> {\n if (!this.graphStore.getDocumentNodes) {\n return nodes;\n }\n\n const refDocIds = nodes\n .map((n) => n.node.refDocId)\n .filter((id): id is string => id !== undefined);\n\n if (refDocIds.length === 0) return nodes;\n\n const ogNodes = await this.graphStore.getDocumentNodes(refDocIds);\n const nodeMap = new Map(ogNodes.map((n) => [n.id, n]));\n\n const graphNodeMap = new Map<string, string[]>();\n for (const node of nodes) {\n const refDocId = node.node.refDocId ?? \"\";\n if (!graphNodeMap.has(refDocId)) {\n graphNodeMap.set(refDocId, []);\n }\n graphNodeMap.get(refDocId)!.push(node.node.text);\n }\n\n const resultNodes: NodeWithScore[] = [];\n for (const nodeWithScore of nodes) {\n const mappedNode = nodeMap.get(nodeWithScore.node.refDocId ?? \"\");\n\n if (mappedNode) {\n const graphContent = graphNodeMap.get(mappedNode.id) ?? [];\n if (graphContent.length > 0) {\n const graphContentStr = graphContent.join(\"\\n\");\n const newContent = this.includeTextPreamble + graphContentStr + \"\\n\\n\" + mappedNode.text;\n resultNodes.push({\n node: {\n id: mappedNode.id,\n text: newContent,\n metadata: mappedNode.metadata,\n refDocId: nodeWithScore.node.refDocId,\n },\n score: nodeWithScore.score,\n });\n } else {\n resultNodes.push({\n node: {\n id: mappedNode.id,\n text: mappedNode.text,\n metadata: mappedNode.metadata,\n refDocId: nodeWithScore.node.refDocId,\n },\n score: nodeWithScore.score,\n });\n }\n } else {\n resultNodes.push(nodeWithScore);\n }\n }\n\n return resultNodes;\n }\n\n async retrieve(queryBundle: QueryBundle): Promise<NodeWithScore[]> {\n let nodes = await this.retrieveFromGraph(queryBundle);\n if (this.includeText && nodes.length > 0) {\n nodes = await this.addSourceText(nodes);\n }\n return nodes;\n }\n\n abstract retrieveFromGraph(queryBundle: QueryBundle): Promise<NodeWithScore[]>;\n}\n","import type { PropertyGraphStore, VectorStoreQuery } from \"../property-graph-store\";\nimport type { QueryBundle, NodeWithScore, LabelledNode } from \"../types\";\nimport { KG_SOURCE_REL, TRIPLET_SOURCE_KEY, STRUCT_SAME_PAGE, STRUCT_ADJACENT, STRUCT_CONTAINS } from \"../types\";\nimport { BasePGRetriever, type BasePGRetrieverOptions } from \"./base\";\n\nexport interface EmbedModel {\n getTextEmbedding(text: string): Promise<number[]>;\n getTextEmbeddingBatch(texts: string[]): Promise<number[][]>;\n}\n\nexport interface VectorContextRetrieverOptions extends BasePGRetrieverOptions {\n embedModel: EmbedModel;\n similarityTopK?: number;\n pathDepth?: number;\n limit?: number;\n similarityScore?: number;\n /** Enable cross-check boosting: boost scores when vector-matched entities link to graph facts (default: true) */\n crossCheckBoost?: boolean;\n /** Multiplier for cross-check boost (default: 1.25 = 25% boost) */\n crossCheckBoostFactor?: number;\n /** Include structural adjacency relations (ON_SAME_PAGE, ADJACENT_TO) in graph expansion (default: true) */\n includeStructuralEdges?: boolean;\n /** Depth for structural edge traversal (default: 1) */\n structuralDepth?: number;\n}\n\nexport class VectorContextRetriever extends BasePGRetriever {\n private readonly embedModel: EmbedModel;\n private readonly similarityTopK: number;\n private readonly pathDepth: number;\n private readonly limit: number;\n private readonly similarityScore?: number;\n private readonly crossCheckBoost: boolean;\n private readonly crossCheckBoostFactor: number;\n private readonly includeStructuralEdges: boolean;\n private readonly structuralDepth: number;\n\n constructor(options: VectorContextRetrieverOptions) {\n super(options);\n this.embedModel = options.embedModel;\n this.similarityTopK = options.similarityTopK ?? 4;\n this.pathDepth = options.pathDepth ?? 1;\n this.limit = options.limit ?? 30;\n this.similarityScore = options.similarityScore;\n this.crossCheckBoost = options.crossCheckBoost ?? true;\n this.crossCheckBoostFactor = options.crossCheckBoostFactor ?? 1.25;\n this.includeStructuralEdges = options.includeStructuralEdges ?? true;\n this.structuralDepth = options.structuralDepth ?? 1;\n }\n\n async retrieveFromGraph(queryBundle: QueryBundle): Promise<NodeWithScore[]> {\n let embedding = queryBundle.embedding;\n\n if (!embedding) {\n embedding = await this.embedModel.getTextEmbedding(queryBundle.queryStr);\n }\n\n const vectorQuery: VectorStoreQuery = {\n queryEmbedding: embedding,\n similarityTopK: this.similarityTopK,\n };\n\n if (!this.graphStore.supportsVectorQueries || !this.graphStore.vectorQuery) {\n throw new Error(\"Graph store does not support vector queries\");\n }\n\n const [kgNodes, scores] = await this.graphStore.vectorQuery(vectorQuery);\n\n if (kgNodes.length === 0) {\n return [];\n }\n\n // Partition vector results into document nodes and entity/other nodes\n const entityNodes: LabelledNode[] = [];\n const entityScores: number[] = [];\n const documentResults: NodeWithScore[] = [];\n\n for (let i = 0; i < kgNodes.length; i++) {\n const node = kgNodes[i];\n if (node.label === \"DOCUMENT\") {\n // Document nodes are direct results — they don't need graph traversal.\n // Use node.id as refDocId so addSourceText() can fetch full text from _NODES.\n documentResults.push({\n node: {\n id: node.id,\n text: `Document: ${node.name}`,\n metadata: node.properties ?? {},\n refDocId: node.id,\n },\n score: scores[i],\n });\n } else {\n entityNodes.push(node);\n entityScores.push(scores[i]);\n }\n }\n\n // --- Entity flow: graph traversal to find triplets ---\n let tripletResults: NodeWithScore[] = [];\n\n if (entityNodes.length > 0) {\n const kgIds = entityNodes.map((n) => n.id);\n\n // Build provenance set from vector-matched nodes for cross-check boosting\n const provenanceSet = new Set<string>();\n if (this.crossCheckBoost) {\n for (const node of entityNodes) {\n provenanceSet.add(node.id.toLowerCase());\n provenanceSet.add(node.name.toLowerCase());\n\n const props = node.properties ?? {};\n if (props.documentId) {\n provenanceSet.add(String(props.documentId).toLowerCase());\n }\n if (props.sourceChunk) {\n provenanceSet.add(String(props.sourceChunk).toLowerCase());\n }\n }\n }\n\n let triplets = await this.graphStore.getRelMap({\n nodes: entityNodes,\n depth: this.pathDepth,\n limit: this.limit,\n ignoreRels: [KG_SOURCE_REL],\n });\n\n // Structural expansion: traverse ON_SAME_PAGE, ADJACENT_TO edges from source chunks\n if (this.includeStructuralEdges) {\n const chunkIds = new Set<string>();\n for (const node of entityNodes) {\n const sourceId = node.properties?.[TRIPLET_SOURCE_KEY];\n if (sourceId) {\n chunkIds.add(`CHUNK_${String(sourceId).replace(/\\s+/g, \"_\").toUpperCase()}`);\n }\n if (node.label === \"CHUNK\") {\n chunkIds.add(node.id);\n }\n }\n\n if (chunkIds.size > 0) {\n const chunkNodes = await this.graphStore.get({ ids: Array.from(chunkIds) });\n if (chunkNodes.length > 0) {\n const structuralTriplets = await this.graphStore.getRelMap({\n nodes: chunkNodes,\n depth: this.structuralDepth,\n limit: this.limit,\n ignoreRels: [KG_SOURCE_REL],\n });\n\n const structuralRels = [STRUCT_SAME_PAGE, STRUCT_ADJACENT, STRUCT_CONTAINS];\n const structuralOnly = structuralTriplets.filter(([_s, r, _o]) =>\n structuralRels.includes(r.label)\n );\n\n const existingKeys = new Set(triplets.map(([s, r, o]) => `${s.id}|${r.label}|${o.id}`));\n for (const triplet of structuralOnly) {\n const key = `${triplet[0].id}|${triplet[1].label}|${triplet[2].id}`;\n if (!existingKeys.has(key)) {\n triplets.push(triplet);\n existingKeys.add(key);\n }\n }\n }\n }\n }\n\n const newScores: number[] = [];\n for (const triplet of triplets) {\n const idx1 = kgIds.indexOf(triplet[0].id);\n const idx2 = kgIds.indexOf(triplet[2].id);\n const score1 = idx1 >= 0 ? entityScores[idx1] : 0;\n const score2 = idx2 >= 0 ? entityScores[idx2] : 0;\n let baseScore = Math.max(score1, score2);\n\n if (this.crossCheckBoost && baseScore > 0) {\n const shouldBoost = this.checkProvenance(triplet[0], provenanceSet) ||\n this.checkProvenance(triplet[2], provenanceSet);\n if (shouldBoost) {\n baseScore = Math.min(1.0, baseScore * this.crossCheckBoostFactor);\n }\n }\n\n newScores.push(baseScore);\n }\n\n let results = triplets.map((t, i) => ({ triplet: t, score: newScores[i] }));\n\n if (this.similarityScore !== undefined) {\n results = results.filter((r) => r.score >= this.similarityScore!);\n }\n\n results.sort((a, b) => b.score - a.score);\n\n tripletResults = this.getNodesWithScore(\n results.map((r) => r.triplet),\n results.map((r) => r.score)\n );\n }\n\n // --- Merge document results and triplet results, sorted by score ---\n const allResults = [...documentResults, ...tripletResults];\n\n if (this.similarityScore !== undefined) {\n return allResults\n .filter((r) => r.score >= this.similarityScore!)\n .sort((a, b) => b.score - a.score);\n }\n\n return allResults.sort((a, b) => b.score - a.score);\n }\n\n /**\n * Check if a node has provenance linking to the vector-matched nodes.\n * Returns true if the node's properties contain a documentId or sourceChunk\n * that matches something in the provenance set.\n */\n private checkProvenance(node: LabelledNode, provenanceSet: Set<string>): boolean {\n if (provenanceSet.size === 0) return false;\n\n const props = node.properties ?? {};\n \n // Check documentId property\n if (props.documentId && provenanceSet.has(String(props.documentId).toLowerCase())) {\n return true;\n }\n \n // Check sourceChunk property\n if (props.sourceChunk && provenanceSet.has(String(props.sourceChunk).toLowerCase())) {\n return true;\n }\n \n // Check if this node itself is in the provenance set (e.g., a CHUNK node)\n if (provenanceSet.has(node.id.toLowerCase()) || provenanceSet.has(node.name.toLowerCase())) {\n return true;\n }\n\n return false;\n }\n}\n","import type { TransformComponent, TextNode } from \"./types\";\nimport type { EntityNode, Relation } from \"../types\";\nimport { KG_NODES_KEY, KG_RELATIONS_KEY, createEntityNode, createRelation } from \"../types\";\n\nexport class ImplicitPathExtractor implements TransformComponent {\n async transform(nodes: TextNode[], options?: { showProgress?: boolean }): Promise<TextNode[]> {\n const results: TextNode[] = [];\n\n for (const node of nodes) {\n const existingNodes = (node.metadata[KG_NODES_KEY] as EntityNode[]) ?? [];\n const existingRelations = (node.metadata[KG_RELATIONS_KEY] as Relation[]) ?? [];\n\n const safeMetadata: Record<string, unknown> = { ...node.metadata };\n delete safeMetadata[KG_NODES_KEY];\n delete safeMetadata[KG_RELATIONS_KEY];\n\n const chunkNode = createEntityNode({\n label: \"CHUNK\",\n name: node.id,\n properties: {\n text: node.text.slice(0, 500),\n ...safeMetadata,\n },\n });\n\n if (node.metadata.documentId) {\n const docNode = createEntityNode({\n label: \"DOCUMENT\",\n name: String(node.metadata.documentId),\n properties: {},\n });\n\n const rel = createRelation({\n label: \"FROM_DOCUMENT\",\n sourceId: chunkNode.id,\n targetId: docNode.id,\n });\n\n existingNodes.push(docNode);\n existingRelations.push(rel);\n }\n\n existingNodes.push(chunkNode);\n\n results.push({\n ...node,\n metadata: {\n ...node.metadata,\n [KG_NODES_KEY]: existingNodes,\n [KG_RELATIONS_KEY]: existingRelations,\n },\n });\n }\n\n return results;\n }\n}\n","import type { PropertyGraphStore } from \"./property-graph-store\";\nimport type { TransformComponent, TextNode } from \"./extractors/types\";\nimport type { EntityNode, Relation, NodeWithScore, QueryBundle } from \"./types\";\nimport { KG_NODES_KEY, KG_RELATIONS_KEY, TRIPLET_SOURCE_KEY } from \"./types\";\nimport { PGRetriever } from \"./pg-retriever\";\nimport { VectorContextRetriever, type EmbedModel } from \"./retrievers/vector-context\";\nimport { ImplicitPathExtractor } from \"./extractors/implicit\";\nimport { createHash } from \"crypto\";\nimport { get_encoding } from \"tiktoken\";\n\n/** Default token limit with safety buffer for text-embedding-3-small (8 192 token context). */\nconst DEFAULT_MAX_EMBED_TOKENS = 8_000;\n\nexport interface PropertyGraphIndexOptions {\n propertyGraphStore: PropertyGraphStore;\n kgExtractors?: TransformComponent[];\n embedModel?: EmbedModel;\n embedKgNodes?: boolean;\n showProgress?: boolean;\n /** Maximum tokens to send to the embedding model per text.\n * Texts exceeding this limit are truncated using tiktoken (cl100k_base encoding).\n * Default: 8 000 (safe for 8 192-token models like text-embedding-3-small). */\n maxEmbedTokens?: number;\n}\n\nexport class PropertyGraphIndex {\n private readonly propertyGraphStore: PropertyGraphStore;\n private readonly kgExtractors: TransformComponent[];\n private readonly embedModel?: EmbedModel;\n private readonly embedKgNodes: boolean;\n private readonly showProgress: boolean;\n private readonly maxEmbedTokens: number;\n\n constructor(options: PropertyGraphIndexOptions) {\n this.propertyGraphStore = options.propertyGraphStore;\n this.kgExtractors = options.kgExtractors ?? [new ImplicitPathExtractor()];\n this.embedModel = options.embedModel;\n this.embedKgNodes = options.embedKgNodes ?? true;\n this.showProgress = options.showProgress ?? false;\n this.maxEmbedTokens = options.maxEmbedTokens ?? DEFAULT_MAX_EMBED_TOKENS;\n }\n\n get graphStore(): PropertyGraphStore {\n return this.propertyGraphStore;\n }\n\n static fromExisting(options: PropertyGraphIndexOptions): PropertyGraphIndex {\n return new PropertyGraphIndex(options);\n }\n\n private computeHash(text: string): string {\n return createHash(\"md5\").update(text).digest(\"hex\");\n }\n\n private truncateForEmbedding(text: string): string {\n const enc = get_encoding(\"cl100k_base\");\n try {\n const tokens = enc.encode(text);\n if (tokens.length <= this.maxEmbedTokens) return text;\n const truncated = tokens.slice(0, this.maxEmbedTokens);\n return new TextDecoder().decode(enc.decode(truncated));\n } finally {\n enc.free();\n }\n }\n\n async insert(nodes: TextNode[]): Promise<TextNode[]> {\n if (nodes.length === 0) return [];\n\n let processedNodes = nodes;\n for (const extractor of this.kgExtractors) {\n processedNodes = await extractor.transform(processedNodes, {\n showProgress: this.showProgress,\n });\n }\n\n const hasExtractors = this.kgExtractors.length > 0;\n\n const kgNodesToInsert: EntityNode[] = [];\n const kgRelsToInsert: Relation[] = [];\n let newKgNodes: EntityNode[] = [];\n\n if (hasExtractors) {\n for (const node of processedNodes) {\n if (!node.metadata[KG_NODES_KEY] && !node.metadata[KG_RELATIONS_KEY]) {\n throw new Error(`Node ${node.id} has no KG_NODES_KEY or KG_RELATIONS_KEY after extraction`);\n }\n }\n\n for (const node of processedNodes) {\n const kgNodes = (node.metadata[KG_NODES_KEY] as EntityNode[]) ?? [];\n const kgRels = (node.metadata[KG_RELATIONS_KEY] as Relation[]) ?? [];\n\n for (const kgNode of kgNodes) {\n kgNode.properties[TRIPLET_SOURCE_KEY] = node.id;\n }\n for (const kgRel of kgRels) {\n kgRel.properties[TRIPLET_SOURCE_KEY] = node.id;\n }\n\n kgNodesToInsert.push(...kgNodes);\n kgRelsToInsert.push(...kgRels);\n }\n\n const kgNodeIds = [...new Set(kgNodesToInsert.map((n) => n.id))];\n const existingKgNodes = await this.propertyGraphStore.get({ ids: kgNodeIds });\n const existingKgNodeIds = new Set(existingKgNodes.map((n) => n.id));\n newKgNodes = kgNodesToInsert.filter((n) => !existingKgNodeIds.has(n.id));\n }\n\n if (this.propertyGraphStore.getDocumentNodes) {\n const existingDocumentNodes = await this.propertyGraphStore.getDocumentNodes(\n processedNodes.map((n) => n.id)\n );\n const existingHashes = new Set(existingDocumentNodes.map((n) => n.hash));\n processedNodes = processedNodes.filter((n) => {\n const hash = this.computeHash(n.text);\n n.hash = hash;\n return !existingHashes.has(hash);\n });\n }\n\n if (this.embedModel && processedNodes.length > 0) {\n const nodeTexts = processedNodes.map((n) => this.truncateForEmbedding(n.text));\n const embeddings = await this.embedModel.getTextEmbeddingBatch(nodeTexts);\n for (let i = 0; i < processedNodes.length; i++) {\n processedNodes[i].embedding = embeddings[i];\n }\n }\n\n if (this.embedKgNodes && this.embedModel && newKgNodes.length > 0) {\n const kgNodeTexts = newKgNodes.map((n) => `${n.label}: ${n.name}`);\n const kgEmbeddings = await this.embedModel.getTextEmbeddingBatch(kgNodeTexts);\n for (let i = 0; i < newKgNodes.length; i++) {\n newKgNodes[i].embedding = kgEmbeddings[i];\n }\n }\n\n if (this.propertyGraphStore.upsertDocumentNodes && processedNodes.length > 0) {\n await this.propertyGraphStore.upsertDocumentNodes(\n processedNodes.map((n) => ({\n id: n.id,\n text: n.text,\n metadata: n.metadata,\n embedding: n.embedding,\n hash: n.hash,\n }))\n );\n }\n\n if (newKgNodes.length > 0) {\n await this.propertyGraphStore.upsertNodes(newKgNodes);\n }\n\n if (kgRelsToInsert.length > 0) {\n await this.propertyGraphStore.upsertRelations(kgRelsToInsert);\n }\n\n return processedNodes;\n }\n\n async delete(nodeIds: string[]): Promise<void> {\n await this.propertyGraphStore.delete({ ids: nodeIds });\n }\n\n asRetriever(options?: {\n subRetrievers?: Array<{ retrieve(query: QueryBundle): Promise<NodeWithScore[]> }>;\n includeText?: boolean;\n /** Number of top similar nodes to retrieve via vector search (default: 4) */\n similarityTopK?: number;\n /** Graph traversal depth from matched nodes (default: 1) */\n pathDepth?: number;\n /** Maximum number of triplets to return after expansion (default: 30) */\n limit?: number;\n /** Minimum similarity score threshold to include results (default: no threshold) */\n similarityScore?: number;\n /** Enable cross-check boosting: boost scores when vector-matched entities link to graph facts (default: true) */\n crossCheckBoost?: boolean;\n /** Multiplier for cross-check boost (default: 1.25 = 25% boost) */\n crossCheckBoostFactor?: number;\n /** Include structural adjacency relations (ON_SAME_PAGE, ADJACENT_TO) in graph expansion (default: true) */\n includeStructuralEdges?: boolean;\n /** Depth for structural edge traversal (default: 1) */\n structuralDepth?: number;\n }): PGRetriever {\n let subRetrievers = options?.subRetrievers as any[];\n\n if (!subRetrievers && this.embedModel && this.propertyGraphStore.supportsVectorQueries) {\n subRetrievers = [\n new VectorContextRetriever({\n graphStore: this.propertyGraphStore,\n embedModel: this.embedModel,\n includeText: options?.includeText ?? true,\n similarityTopK: options?.similarityTopK,\n pathDepth: options?.pathDepth,\n limit: options?.limit,\n similarityScore: options?.similarityScore,\n crossCheckBoost: options?.crossCheckBoost,\n crossCheckBoostFactor: options?.crossCheckBoostFactor,\n includeStructuralEdges: options?.includeStructuralEdges,\n structuralDepth: options?.structuralDepth,\n }),\n ];\n }\n\n if (!subRetrievers) {\n subRetrievers = [];\n }\n\n return new PGRetriever({ subRetrievers });\n }\n\n async query(queryStr: string, options?: {\n /** Number of top similar nodes to retrieve via vector search (default: 4) */\n similarityTopK?: number;\n /** Graph traversal depth from matched nodes (default: 1) */\n pathDepth?: number;\n /** Maximum number of triplets to return after expansion (default: 30) */\n limit?: number;\n /** Minimum similarity score threshold to include results (default: no threshold) */\n similarityScore?: number;\n /** Enable cross-check boosting: boost scores when vector-matched entities link to graph facts (default: true) */\n crossCheckBoost?: boolean;\n /** Multiplier for cross-check boost (default: 1.25 = 25% boost) */\n crossCheckBoostFactor?: number;\n /** Include structural adjacency relations (ON_SAME_PAGE, ADJACENT_TO) in graph expansion (default: true) */\n includeStructuralEdges?: boolean;\n /** Depth for structural edge traversal (default: 1) */\n structuralDepth?: number;\n }): Promise<NodeWithScore[]> {\n const retriever = this.asRetriever(options);\n return retriever.retrieve({ queryStr });\n }\n}\n","import { z } from \"zod\";\nimport type { TransformComponent, TextNode, SchemaDefinition } from \"./types\";\nimport type { EntityNode, Relation, Triplet } from \"../types\";\nimport { KG_NODES_KEY, KG_RELATIONS_KEY, createEntityNode, createRelation } from \"../types\";\n\n/** Minimal contract for a schema — compatible with Zod 3, Zod 4, or any parse-capable object. */\nexport interface Parseable<T> {\n parse(data: unknown): T;\n}\n\nexport interface LLMClient {\n structuredPredict<T>(schema: Parseable<T>, prompt: string): Promise<T>;\n}\n\nexport interface SchemaLLMPathExtractorOptions {\n llm: LLMClient;\n schema: SchemaDefinition;\n maxTripletsPerChunk?: number;\n strict?: boolean;\n extractPromptTemplate?: string;\n}\n\nconst DEFAULT_EXTRACT_PROMPT = `Given the following text, extract a knowledge graph according to the provided schema.\nExtract up to {maxTriplets} triplets. If fewer are present in the text, return fewer. Do not invent or pad triplets.\n\nSchema:\n- Entity types: {entityTypes}\n- Relation types: {relationTypes}\n- Valid relationships: {validationSchema}\n\nText:\n-------\n{text}\n-------\n\nExtract entities and relationships from the text above.\nReturn your answer as a JSON object with a \"triplets\" array. Each triplet should have:\n- \"subject\": { \"name\": string, \"type\": one of [{entityTypes}] }\n- \"relation\": { \"type\": one of [{relationTypes}] }\n- \"object\": { \"name\": string, \"type\": one of [{entityTypes}] }\n\nExample output format:\n{\n \"triplets\": [\n {\n \"subject\": { \"name\": \"John\", \"type\": \"PERSON\" },\n \"relation\": { \"type\": \"WORKS_AT\" },\n \"object\": { \"name\": \"Acme Corp\", \"type\": \"ORGANIZATION\" }\n }\n ]\n}`;\n\nexport class SchemaLLMPathExtractor implements TransformComponent {\n private readonly llm: LLMClient;\n private readonly schema: SchemaDefinition;\n private readonly maxTripletsPerChunk: number;\n private readonly strict: boolean;\n private readonly extractPromptTemplate: string;\n private readonly tripletSchema: z.ZodType<any>;\n private readonly rawTripletSchema: z.ZodType<any>;\n\n constructor(options: SchemaLLMPathExtractorOptions) {\n this.llm = options.llm;\n this.schema = options.schema;\n this.maxTripletsPerChunk = options.maxTripletsPerChunk ?? 10;\n this.strict = options.strict ?? true;\n this.extractPromptTemplate = options.extractPromptTemplate ?? DEFAULT_EXTRACT_PROMPT;\n\n const entityTypeEnum = z.enum(this.schema.entityTypes as [string, ...string[]]);\n const relationTypeEnum = z.enum(this.schema.relationTypes as [string, ...string[]]);\n\n const entitySchema = z.object({\n name: z.string(),\n type: entityTypeEnum,\n properties: z.record(z.unknown()).optional(),\n });\n\n const relationSchema = z.object({\n type: relationTypeEnum,\n properties: z.record(z.unknown()).optional(),\n });\n\n const tripletSchema = z.object({\n subject: entitySchema,\n relation: relationSchema,\n object: entitySchema,\n });\n\n this.tripletSchema = z.object({\n triplets: z.array(tripletSchema),\n });\n\n this.rawTripletSchema = z.object({\n triplets: z.array(z.any()),\n });\n }\n\n private normalizeType(type: string): string {\n return String(type).toUpperCase().replace(/\\s+/g, \"_\");\n }\n\n private buildPrompt(text: string): string {\n const validationSchemaStr = this.schema.validationSchema\n ?.map(([s, r, o]) => `(${s})-[${r}]->(${o})`)\n .join(\", \") ?? \"Any valid combination\";\n\n return this.extractPromptTemplate\n .replace(\"{maxTriplets}\", String(this.maxTripletsPerChunk))\n .replace(\"{entityTypes}\", this.schema.entityTypes.join(\", \"))\n .replace(\"{relationTypes}\", this.schema.relationTypes.join(\", \"))\n .replace(\"{validationSchema}\", validationSchemaStr)\n .replace(\"{text}\", text);\n }\n\n private isValidTriplet(subjectType: string, relationType: string, objectType: string): boolean {\n if (!this.strict || !this.schema.validationSchema) {\n return true;\n }\n\n const subj = this.normalizeType(subjectType);\n const rel = this.normalizeType(relationType);\n const obj = this.normalizeType(objectType);\n\n return this.schema.validationSchema.some(\n ([s, r, o]) =>\n this.normalizeType(s) === subj &&\n this.normalizeType(r) === rel &&\n this.normalizeType(o) === obj\n );\n }\n\n private pruneInvalidTriplets(\n extracted: { triplets: Array<{ subject: any; relation: any; object: any }> }\n ): Triplet[] {\n const validTriplets: Triplet[] = [];\n\n const allowedEntityTypes = new Set(this.schema.entityTypes.map((t) => this.normalizeType(t)));\n const allowedRelationTypes = new Set(this.schema.relationTypes.map((t) => this.normalizeType(t)));\n\n for (const triplet of extracted.triplets) {\n const subject = (triplet as any)?.subject;\n const relation = (triplet as any)?.relation;\n const object = (triplet as any)?.object;\n\n if (!subject || !relation || !object) continue;\n if (typeof subject.type !== \"string\" || typeof subject.name !== \"string\") continue;\n if (typeof relation.type !== \"string\") continue;\n if (typeof object.type !== \"string\" || typeof object.name !== \"string\") continue;\n\n const subjectType = this.normalizeType(subject.type);\n const relationType = this.normalizeType(relation.type);\n const objectType = this.normalizeType(object.type);\n\n if (this.strict) {\n if (!allowedEntityTypes.has(subjectType)) continue;\n if (!allowedRelationTypes.has(relationType)) continue;\n if (!allowedEntityTypes.has(objectType)) continue;\n }\n\n if (!this.isValidTriplet(subjectType, relationType, objectType)) {\n continue;\n }\n\n const subjectName = String(triplet.subject.name).trim();\n const objectName = String(triplet.object.name).trim();\n\n if (subjectName.toLowerCase() === objectName.toLowerCase()) {\n continue;\n }\n\n const subj = createEntityNode({\n label: subjectType,\n name: subjectName,\n properties: triplet.subject.properties ?? {},\n });\n\n const obj = createEntityNode({\n label: objectType,\n name: objectName,\n properties: triplet.object.properties ?? {},\n });\n\n const rel = createRelation({\n label: relationType,\n sourceId: subj.id,\n targetId: obj.id,\n properties: triplet.relation.properties ?? {},\n });\n\n validTriplets.push([subj, rel, obj]);\n }\n\n return validTriplets;\n }\n\n private async extractFromNode(node: TextNode): Promise<TextNode> {\n const prompt = this.buildPrompt(node.text);\n\n let triplets: Triplet[] = [];\n\n try {\n const result = await this.llm.structuredPredict(this.rawTripletSchema, prompt);\n triplets = this.pruneInvalidTriplets(result);\n\n if (this.maxTripletsPerChunk > 0 && triplets.length > this.maxTripletsPerChunk) {\n triplets = triplets.slice(0, this.maxTripletsPerChunk);\n }\n } catch (err) {\n // Log extraction errors for debugging\n console.warn(`[SchemaLLMPathExtractor] Failed to extract from node ${node.id}:`, err);\n triplets = [];\n }\n\n const existingNodes = (node.metadata[KG_NODES_KEY] as EntityNode[]) ?? [];\n const existingRelations = (node.metadata[KG_RELATIONS_KEY] as Relation[]) ?? [];\n\n // Avoid copying kg_nodes/kg_relations into node properties (can create circular refs)\n const safeMetadata: Record<string, unknown> = { ...node.metadata };\n delete safeMetadata[KG_NODES_KEY];\n delete safeMetadata[KG_RELATIONS_KEY];\n\n for (const [subj, rel, obj] of triplets) {\n subj.properties = { ...subj.properties, ...safeMetadata };\n obj.properties = { ...obj.properties, ...safeMetadata };\n rel.properties = { ...rel.properties, ...safeMetadata };\n\n existingNodes.push(subj);\n existingNodes.push(obj);\n existingRelations.push(rel);\n }\n\n return {\n ...node,\n metadata: {\n ...node.metadata,\n [KG_NODES_KEY]: existingNodes,\n [KG_RELATIONS_KEY]: existingRelations,\n },\n };\n }\n\n async transform(nodes: TextNode[], options?: { showProgress?: boolean }): Promise<TextNode[]> {\n const results: TextNode[] = [];\n\n for (const node of nodes) {\n const processed = await this.extractFromNode(node);\n results.push(processed);\n }\n\n return results;\n }\n}\n","import type { TransformComponent, TextNode } from \"./types\";\nimport type { Relation } from \"../types\";\nimport { KG_RELATIONS_KEY, STRUCT_SAME_PAGE, STRUCT_ADJACENT } from \"../types\";\n\nexport interface AdjacencyLinkerOptions {\n /**\n * Link chunks that share the same pageNumber in metadata.\n * Default: true\n */\n linkSamePage?: boolean;\n\n /**\n * Link chunks that are adjacent by chunkIndex in metadata.\n * Default: true\n */\n linkAdjacent?: boolean;\n\n /**\n * Maximum chunk index distance for ADJACENT_TO links.\n * Default: 1 (immediate neighbors only)\n */\n adjacentDistance?: number;\n\n /**\n * Only create cross-type links (e.g., text↔image), not text↔text.\n * Default: false (link all)\n */\n crossTypeOnly?: boolean;\n}\n\nexport class AdjacencyLinker implements TransformComponent {\n private linkSamePage: boolean;\n private linkAdjacent: boolean;\n private adjacentDistance: number;\n private crossTypeOnly: boolean;\n\n constructor(options: AdjacencyLinkerOptions = {}) {\n this.linkSamePage = options.linkSamePage ?? true;\n this.linkAdjacent = options.linkAdjacent ?? true;\n this.adjacentDistance = options.adjacentDistance ?? 1;\n this.crossTypeOnly = options.crossTypeOnly ?? false;\n }\n\n /**\n * Transform is called AFTER other extractors (SchemaLLMPathExtractor, ImplicitPathExtractor).\n * It adds structural relations between chunks based on metadata.\n */\n async transform(nodes: TextNode[], options?: { showProgress?: boolean }): Promise<TextNode[]> {\n if (nodes.length < 2) return nodes;\n\n // Group nodes by documentId\n const byDocument = new Map<string, TextNode[]>();\n for (const node of nodes) {\n const docId = String(node.metadata.documentId ?? \"unknown\");\n if (!byDocument.has(docId)) byDocument.set(docId, []);\n byDocument.get(docId)!.push(node);\n }\n\n // For each document, create structural links\n // Map from node.id to relations that should be added to that node\n const nodeRelationsMap = new Map<string, Relation[]>();\n\n for (const [docId, docNodes] of byDocument) {\n // Group by page\n const byPage = new Map<number, TextNode[]>();\n for (const node of docNodes) {\n const page = Number(node.metadata.pageNumber ?? 0);\n if (!byPage.has(page)) byPage.set(page, []);\n byPage.get(page)!.push(node);\n }\n\n // Same-page links\n if (this.linkSamePage) {\n for (const [page, pageNodes] of byPage) {\n if (pageNodes.length < 2) continue;\n for (let i = 0; i < pageNodes.length; i++) {\n for (let j = i + 1; j < pageNodes.length; j++) {\n const a = pageNodes[i];\n const b = pageNodes[j];\n if (this.shouldLink(a, b)) {\n this.addRelation(nodeRelationsMap, a.id, b.id, STRUCT_SAME_PAGE, { pageNumber: page, documentId: docId });\n }\n }\n }\n }\n }\n\n // Adjacent chunk links (by chunkIndex)\n if (this.linkAdjacent) {\n // Sort by chunkIndex\n const sorted = [...docNodes].sort((a, b) => {\n const idxA = Number(a.metadata.chunkIndex ?? 0);\n const idxB = Number(b.metadata.chunkIndex ?? 0);\n return idxA - idxB;\n });\n\n for (let i = 0; i < sorted.length; i++) {\n for (let d = 1; d <= this.adjacentDistance && i + d < sorted.length; d++) {\n const a = sorted[i];\n const b = sorted[i + d];\n if (this.shouldLink(a, b)) {\n this.addRelation(nodeRelationsMap, a.id, b.id, STRUCT_ADJACENT, { distance: d, documentId: docId });\n }\n }\n }\n }\n }\n\n // Merge relations into node metadata\n return nodes.map((node) => {\n const existingRelations = (node.metadata[KG_RELATIONS_KEY] as Relation[]) ?? [];\n const newRelations = nodeRelationsMap.get(node.id) ?? [];\n\n return {\n ...node,\n metadata: {\n ...node.metadata,\n [KG_RELATIONS_KEY]: [...existingRelations, ...newRelations],\n },\n };\n });\n }\n\n private shouldLink(a: TextNode, b: TextNode): boolean {\n if (!this.crossTypeOnly) return true;\n const typeA = String(a.metadata.contentType ?? \"text\");\n const typeB = String(b.metadata.contentType ?? \"text\");\n return typeA !== typeB;\n }\n\n private addRelation(\n map: Map<string, Relation[]>,\n sourceNodeId: string,\n targetNodeId: string,\n label: string,\n properties: Record<string, unknown>\n ): void {\n // Create CHUNK entity IDs (matching ImplicitPathExtractor format)\n const sourceId = `CHUNK_${sourceNodeId.replace(/\\s+/g, \"_\").toUpperCase()}`;\n const targetId = `CHUNK_${targetNodeId.replace(/\\s+/g, \"_\").toUpperCase()}`;\n\n const rel: Relation = {\n id: `${sourceId}_${label}_${targetId}`,\n label,\n sourceId,\n targetId,\n properties,\n };\n\n // Add to source node\n if (!map.has(sourceNodeId)) map.set(sourceNodeId, []);\n map.get(sourceNodeId)!.push(rel);\n\n // Bidirectional: also add reverse to target node\n const reverseRel: Relation = {\n id: `${targetId}_${label}_${sourceId}`,\n label,\n sourceId: targetId,\n targetId: sourceId,\n properties,\n };\n\n if (!map.has(targetNodeId)) map.set(targetNodeId, []);\n map.get(targetNodeId)!.push(reverseRel);\n }\n}\n"],"mappings":";AAAO,SAAS,cACd,MACA,cACgC;AAChC,QAAM,MAAM,KAAK,YAAY,GAAG;AAChC,MAAI,MAAM,MAAM,MAAM,KAAK,SAAS,GAAG;AACrC,UAAM,YAAY,OAAO,KAAK,MAAM,MAAM,CAAC,CAAC;AAC5C,QAAI,CAAC,OAAO,MAAM,SAAS,KAAK,YAAY,GAAG;AAC7C,aAAO,EAAE,MAAM,KAAK,MAAM,GAAG,GAAG,GAAG,MAAM,UAAU;AAAA,IACrD;AAAA,EACF;AAEA,SAAO,EAAE,MAAM,MAAM,aAAa;AACpC;;;ACVA,eAAsB,qBACpB,QACyB;AACzB,MAAI;AACJ,MAAI;AACF,UAAM,aAAa,MAAM,OAAO,kBAAkB;AAClD,WAAQ,WAAmB,WAAW;AAAA,EACxC,QAAQ;AACN,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,eAAe,OAAO,QAAQ;AACpC,QAAM,EAAE,MAAM,KAAK,IAAI,cAAc,OAAO,MAAM,YAAY;AAE9D,QAAM,OAAuB,KAAK,iBAAiB;AAEnD,QAAM,IAAI,QAAc,CAAC,SAAS,WAAW;AAC3C,SAAK;AAAA,MACH;AAAA,QACE,YAAY,GAAG,IAAI,IAAI,IAAI;AAAA,QAC3B,KAAK,OAAO;AAAA,QACZ,KAAK,OAAO;AAAA,QACZ,SAAS,OAAO,WAAW;AAAA,QAC3B,wBAAwB,OAAO,0BAA0B;AAAA,MAC3D;AAAA,MACA,CAAC,QAAmB,MAAM,OAAO,GAAG,IAAI,QAAQ;AAAA,IAClD;AAAA,EACF,CAAC;AAED,SAAO;AACT;AAEA,eAAsB,SACpB,MACA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CAAC;AACpD,QAAI,IAAI,YAAY,EAAG,KAAK,UAAU;AAAA,EACxC;AACF;","names":["z","z"]}
|
|
1
|
+
{"version":3,"sources":["../src/hana/parse-host-port.ts","../src/hana/connection.ts","../src/hana/sparql-store.ts","../src/hana/graph-discovery.ts","../src/graph/types.ts","../src/graph/hana-property-graph-store.ts","../src/graph/pg-retriever.ts","../src/graph/retrievers/base.ts","../src/graph/retrievers/vector-context.ts","../src/graph/extractors/implicit.ts","../src/graph/property-graph-index.ts","../src/graph/extractors/schema-llm.ts","../src/graph/extractors/adjacency-linker.ts"],"sourcesContent":["export function parseHostPort(\n host: string,\n fallbackPort: number\n): { host: string; port: number } {\n const idx = host.lastIndexOf(\":\");\n if (idx > -1 && idx < host.length - 1) {\n const maybePort = Number(host.slice(idx + 1));\n if (!Number.isNaN(maybePort) && maybePort > 0) {\n return { host: host.slice(0, idx), port: maybePort };\n }\n }\n\n return { host, port: fallbackPort };\n}\n","import { parseHostPort } from \"./parse-host-port\";\nimport type { HanaConnection, HanaConnectionConfig } from \"./types\";\n\nexport async function createHanaConnection(\n config: HanaConnectionConfig\n): Promise<HanaConnection> {\n let hana: any;\n try {\n const hanaModule = await import(\"@sap/hana-client\");\n hana = (hanaModule as any).default || hanaModule;\n } catch {\n throw new Error(\n \"@sap/hana-client is not available. Ensure it is installed and pnpm build scripts are approved (pnpm approve-builds).\"\n );\n }\n\n const fallbackPort = config.port ?? 443;\n const { host, port } = parseHostPort(config.host, fallbackPort);\n\n const conn: HanaConnection = hana.createConnection();\n\n await new Promise<void>((resolve, reject) => {\n conn.connect(\n {\n serverNode: `${host}:${port}`,\n uid: config.user,\n pwd: config.password,\n encrypt: config.encrypt ?? true,\n sslValidateCertificate: config.sslValidateCertificate ?? true\n },\n (err?: unknown) => (err ? reject(err) : resolve())\n );\n });\n\n return conn;\n}\n\nexport async function hanaExec<T = unknown>(\n conn: HanaConnection,\n sql: string\n): Promise<T> {\n return await new Promise<T>((resolve, reject) => {\n conn.exec(sql, (err: unknown, result: unknown) => {\n if (err) return reject(err);\n resolve(result as T);\n });\n });\n}\n","import type { HanaConnection } from \"./types\";\n\nexport type SparqlExecuteResult = unknown;\n\nexport class HanaSparqlStore {\n private readonly conn: HanaConnection;\n\n constructor(conn: HanaConnection) {\n this.conn = conn;\n }\n\n async execute(options: {\n sparql: string;\n headers?: string;\n defaultGraphUri?: string;\n }): Promise<SparqlExecuteResult> {\n const headerLines: string[] = [];\n\n if (options.defaultGraphUri) {\n headerLines.push(`rqx-default-graph-uri: ${options.defaultGraphUri}`);\n }\n\n if (options.headers) {\n headerLines.push(options.headers.trim());\n }\n\n const hdrs = headerLines.length ? `${headerLines.join(\"\\r\\n\")}\\r\\n` : \"\";\n\n const sql = \"CALL SPARQL_EXECUTE(?, ?, ?, ?)\";\n\n return await new Promise((resolve, reject) => {\n // @sap/hana-client supports conn.exec with parameter arrays.\n // We intentionally keep the result as unknown; callers can parse the XML/JSON depending on HANA return mode.\n (this.conn as any).exec(sql, [options.sparql, hdrs, \"\", null], (err: unknown, result: unknown) => {\n if (err) return reject(err);\n resolve(result);\n });\n });\n }\n\n async loadTurtle(options: {\n turtle: string;\n graphName: string;\n filename?: string;\n }): Promise<SparqlExecuteResult> {\n const requestHdrs = [\n \"rqx-load-protocol: true\",\n options.filename ? `rqx-load-filename: ${options.filename}` : undefined,\n `rqx-load-graphname: ${options.graphName}`\n ]\n .filter(Boolean)\n .join(\"\\r\\n\");\n\n return await this.execute({ sparql: options.turtle, headers: requestHdrs });\n }\n}\n","import type { HanaConnection } from \"./types\";\nimport { hanaExec } from \"./connection\";\n\nexport type HanaKgGraphTableSuffix = \"VECTORS\" | \"NODES\" | \"IMAGES\";\n\nexport type GraphTables = {\n vectorsTable: string;\n nodesTable: string;\n imagesTable: string;\n};\n\nexport type HanaKgGraphInfo = {\n graphName: string;\n hasVectors: boolean;\n hasNodes: boolean;\n hasImages: boolean;\n vectorsCount?: number;\n nodesCount?: number;\n imagesCount?: number;\n};\n\nexport function getGraphTables(graphName: string): GraphTables {\n return {\n vectorsTable: `${graphName}_VECTORS`,\n nodesTable: `${graphName}_NODES`,\n imagesTable: `${graphName}_IMAGES`,\n };\n}\n\nfunction escapeSqlStringLiteral(value: string): string {\n return value.replace(/'/g, \"''\");\n}\n\nfunction normalizeRequirement(req: HanaKgGraphTableSuffix): HanaKgGraphTableSuffix {\n return req.toUpperCase() as HanaKgGraphTableSuffix;\n}\n\nexport async function listGraphs(\n conn: HanaConnection,\n opts?: {\n schema?: string;\n require?: HanaKgGraphTableSuffix[];\n includeCounts?: boolean;\n limit?: number;\n }\n): Promise<HanaKgGraphInfo[]> {\n const schemaFilter = opts?.schema ? ` = '${escapeSqlStringLiteral(opts.schema)}'` : \" = CURRENT_SCHEMA\";\n\n // Discover by our naming convention in a single pass.\n // Note: `_` is a wildcard in LIKE, so we must escape it.\n const rows = (await hanaExec<any[]>(\n conn,\n `SELECT TABLE_NAME\n FROM SYS.TABLES\n WHERE SCHEMA_NAME${schemaFilter}\n AND (\n TABLE_NAME LIKE '%\\\\_VECTORS' ESCAPE '\\\\'\n OR TABLE_NAME LIKE '%\\\\_NODES' ESCAPE '\\\\'\n OR TABLE_NAME LIKE '%\\\\_IMAGES' ESCAPE '\\\\'\n )`\n )) as Array<{ TABLE_NAME?: string; table_name?: string }>;\n\n const tableNames = new Set(\n (rows ?? []).map((r) => String(r.TABLE_NAME ?? r.table_name ?? \"\").toUpperCase()).filter(Boolean)\n );\n\n const stems = new Set<string>();\n for (const t of tableNames) {\n if (t.endsWith(\"_VECTORS\")) {\n stems.add(t.slice(0, -\"_VECTORS\".length));\n }\n }\n\n const infos: HanaKgGraphInfo[] = [];\n for (const stem of stems) {\n const { vectorsTable, nodesTable, imagesTable } = getGraphTables(stem);\n infos.push({\n graphName: stem,\n hasVectors: tableNames.has(vectorsTable),\n hasNodes: tableNames.has(nodesTable),\n hasImages: tableNames.has(imagesTable),\n });\n }\n\n if (opts?.includeCounts) {\n // Only count tables that exist; use quoted identifiers to be robust.\n // NOTE: Table names come from SYS.TABLES results, so this is not user input.\n const schemaName = opts?.schema ? String(opts.schema).toUpperCase() : undefined;\n\n const countTable = async (tableName: string): Promise<number> => {\n const fq = schemaName\n ? `\"${schemaName.replace(/\"/g, '\"\"')}\".\"${tableName.replace(/\"/g, '\"\"')}\"`\n : `\"${tableName.replace(/\"/g, '\"\"')}\"`;\n const res = (await hanaExec<any[]>(conn, `SELECT COUNT(*) AS CNT FROM ${fq}`)) as any[];\n const row = res?.[0];\n const cnt = row?.CNT ?? row?.cnt ?? Object.values(row ?? {})[0];\n return Number(cnt ?? 0);\n };\n\n for (const info of infos) {\n const { vectorsTable, nodesTable, imagesTable } = getGraphTables(info.graphName);\n\n if (info.hasVectors) {\n info.vectorsCount = await countTable(vectorsTable);\n }\n if (info.hasNodes) {\n info.nodesCount = await countTable(nodesTable);\n }\n if (info.hasImages) {\n info.imagesCount = await countTable(imagesTable);\n }\n }\n }\n\n const requireList = (opts?.require ?? []).map(normalizeRequirement);\n const filtered = requireList.length\n ? infos.filter((i) =>\n requireList.every((req) => {\n if (req === \"VECTORS\") return i.hasVectors;\n if (req === \"NODES\") return i.hasNodes;\n if (req === \"IMAGES\") return i.hasImages;\n return false;\n })\n )\n : infos;\n\n filtered.sort((a, b) => a.graphName.localeCompare(b.graphName));\n\n if (opts?.limit !== undefined) {\n return filtered.slice(0, Math.max(0, opts.limit));\n }\n\n return filtered;\n}\n","import { z } from \"zod\";\n\nexport const TRIPLET_SOURCE_KEY = \"triplet_source_id\";\nexport const KG_NODES_KEY = \"kg_nodes\";\nexport const KG_RELATIONS_KEY = \"kg_relations\";\nexport const VECTOR_SOURCE_KEY = \"vector_source_id\";\nexport const KG_SOURCE_REL = \"HAS_SOURCE\";\n\n// Structural adjacency relations (not semantic)\nexport const STRUCT_SAME_PAGE = \"ON_SAME_PAGE\";\nexport const STRUCT_ADJACENT = \"ADJACENT_TO\";\nexport const STRUCT_CONTAINS = \"CONTAINS\";\n\nexport const EntityNodeSchema = z.object({\n id: z.string(),\n label: z.string(),\n name: z.string(),\n properties: z.record(z.unknown()).default({}),\n embedding: z.array(z.number()).optional(),\n});\n\nexport type EntityNode = z.infer<typeof EntityNodeSchema>;\n\nexport const RelationSchema = z.object({\n id: z.string().optional(),\n label: z.string(),\n sourceId: z.string(),\n targetId: z.string(),\n properties: z.record(z.unknown()).default({}),\n});\n\nexport type Relation = z.infer<typeof RelationSchema>;\n\nexport type Triplet = [EntityNode, Relation, EntityNode];\n\nexport type LabelledNode = EntityNode;\n\nexport interface NodeWithScore {\n node: {\n id: string;\n text: string;\n metadata: Record<string, unknown>;\n refDocId?: string;\n };\n score: number;\n}\n\nexport interface QueryBundle {\n queryStr: string;\n embedding?: number[];\n embeddingStrs?: string[];\n}\n\nexport function createEntityNode(opts: {\n label: string;\n name: string;\n properties?: Record<string, unknown>;\n embedding?: number[];\n}): EntityNode {\n const id = `${opts.label.toUpperCase()}_${opts.name.replace(/\\s+/g, \"_\").toUpperCase()}`;\n return {\n id,\n label: opts.label,\n name: opts.name,\n properties: opts.properties ?? {},\n embedding: opts.embedding,\n };\n}\n\nexport function createRelation(opts: {\n label: string;\n sourceId: string;\n targetId: string;\n properties?: Record<string, unknown>;\n}): Relation {\n return {\n id: `${opts.sourceId}_${opts.label}_${opts.targetId}`,\n label: opts.label,\n sourceId: opts.sourceId,\n targetId: opts.targetId,\n properties: opts.properties ?? {},\n };\n}\n\nexport function tripletToString(triplet: Triplet, includeProperties = false): string {\n const [subj, rel, obj] = triplet;\n if (includeProperties) {\n return `${subj.name} (${subj.label}) -[${rel.label}]-> ${obj.name} (${obj.label})`;\n }\n return `${subj.id} -> ${rel.label} -> ${obj.id}`;\n}\n","import type { HanaConnection } from \"../hana/types\";\nimport type { PropertyGraphStore, VectorStoreQuery } from \"./property-graph-store\";\nimport type { EntityNode, Relation, Triplet, LabelledNode } from \"./types\";\nimport { TRIPLET_SOURCE_KEY, KG_SOURCE_REL } from \"./types\";\n\ntype DocumentNode = {\n id: string;\n text: string;\n metadata: Record<string, unknown>;\n embedding?: number[];\n hash?: string;\n};\n\nexport interface HanaPropertyGraphStoreOptions {\n graphName: string;\n vectorTableName?: string;\n documentNodesTableName?: string;\n /** Optional, unused for dimensionless REAL_VECTOR columns (kept for backward compat logging). */\n vectorDimension?: number;\n /** SQL execBatch chunk size for vector/document table writes. Defaults to HANA_KGVECTOR_SQL_BATCH_SIZE or 500. */\n sqlBatchSize?: number;\n /** If true, will DROP and recreate tables on init (intended for tests/dev only). */\n resetTables?: boolean;\n}\n\nexport class HanaPropertyGraphStore implements PropertyGraphStore {\n private readonly conn: HanaConnection;\n private readonly graphName: string;\n private readonly vectorTableName: string;\n private readonly documentNodesTableName: string;\n private readonly sqlBatchSize: number;\n private readonly resetTables: boolean;\n private initialized = false;\n\n readonly supportsVectorQueries = true;\n readonly supportsStructuredQueries = true;\n\n constructor(conn: HanaConnection, options: HanaPropertyGraphStoreOptions) {\n this.conn = conn;\n this.graphName = options.graphName;\n this.vectorTableName = options.vectorTableName ?? `${options.graphName.replace(/[^a-zA-Z0-9]/g, \"_\")}_VECTORS`;\n this.documentNodesTableName = options.documentNodesTableName ?? `${options.graphName.replace(/[^a-zA-Z0-9]/g, \"_\")}_NODES`;\n this.sqlBatchSize = this.resolveSqlBatchSize(options.sqlBatchSize);\n this.resetTables = options.resetTables ?? false;\n }\n\n private resolveSqlBatchSize(configured?: number): number {\n const raw = configured ?? Number(process.env.HANA_KGVECTOR_SQL_BATCH_SIZE);\n if (!Number.isFinite(raw) || raw <= 0) return 500;\n return Math.floor(raw);\n }\n\n private async ensureInitialized(): Promise<void> {\n if (this.initialized) return;\n\n // Optional destructive reset intended for tests/dev. This is OFF by default.\n if (this.resetTables) {\n await this.exec(`DROP TABLE ${this.vectorTableName}`).catch(() => {});\n await this.exec(`DROP TABLE ${this.documentNodesTableName}`).catch(() => {});\n\n // Also clear the RDF named graph to avoid accumulating triples across test runs.\n // (Tables are recreated, but the KG graph would otherwise persist.)\n await this.sparqlExecute(`CLEAR GRAPH <${this.graphName}>`).catch(() => {});\n }\n\n // HANA does not support \"IF NOT EXISTS\" for CREATE TABLE. We try to create and ignore the\n // \"name exists\" error, but surface any other errors.\n const createVectorTable = `\n CREATE COLUMN TABLE ${this.vectorTableName} (\n id NVARCHAR(512) PRIMARY KEY,\n node_type NVARCHAR(64),\n label NVARCHAR(128),\n name NVARCHAR(512),\n properties NCLOB,\n source_id NVARCHAR(512),\n target_id NVARCHAR(512),\n embedding REAL_VECTOR\n )\n `;\n await this.exec(createVectorTable).catch((err: any) => {\n const message = String(err?.message ?? \"\");\n // Handle \"duplicate table name\" or \"already exists\"\n if (!/exists|duplicate table name/i.test(message)) {\n throw err;\n }\n });\n\n // Migrate existing tables that lack the source_id / target_id columns.\n await this.exec(`ALTER TABLE ${this.vectorTableName} ADD (source_id NVARCHAR(512), target_id NVARCHAR(512))`).catch((err: any) => {\n const message = String(err?.message ?? \"\");\n // Ignore if columns already exist\n if (!/duplicate column|already exists/i.test(message)) {\n throw err;\n }\n });\n\n const createDocumentTable = `\n CREATE COLUMN TABLE ${this.documentNodesTableName} (\n id NVARCHAR(512) PRIMARY KEY,\n text NCLOB,\n metadata NCLOB,\n hash NVARCHAR(64),\n embedding REAL_VECTOR\n )\n `;\n await this.exec(createDocumentTable).catch((err: any) => {\n const message = String(err?.message ?? \"\");\n if (!/exists|duplicate table name/i.test(message)) {\n throw err;\n }\n });\n\n this.initialized = true;\n }\n\n private async exec(sql: string, params?: unknown[]): Promise<unknown[]> {\n return new Promise((resolve, reject) => {\n if (params && params.length > 0) {\n (this.conn as any).exec(sql, params, (err: unknown, result: unknown) => {\n if (err) reject(err);\n else resolve(result as unknown[]);\n });\n } else {\n this.conn.exec(sql, (err: unknown, result: unknown) => {\n if (err) reject(err);\n else resolve(result as unknown[]);\n });\n }\n });\n }\n\n private async execBatch(sql: string, paramRows: unknown[][]): Promise<void> {\n if (paramRows.length === 0) return;\n\n if (typeof (this.conn as any).prepare !== \"function\") {\n for (const params of paramRows) {\n await this.exec(sql, params);\n }\n return;\n }\n\n for (let i = 0; i < paramRows.length; i += this.sqlBatchSize) {\n const chunk = paramRows.slice(i, i + this.sqlBatchSize);\n const stmt = await new Promise<any>((resolve, reject) => {\n (this.conn as any).prepare(sql, (err: unknown, prepared: unknown) => {\n if (err) reject(err);\n else resolve(prepared);\n });\n });\n\n try {\n if (typeof stmt.execBatch !== \"function\") {\n for (const params of chunk) {\n await this.exec(sql, params);\n }\n continue;\n }\n\n await new Promise<void>((resolve, reject) => {\n stmt.execBatch(chunk, (err: unknown) => {\n if (err) reject(err);\n else resolve();\n });\n });\n } finally {\n try {\n stmt.drop?.();\n } catch {\n // non-fatal cleanup\n }\n }\n }\n }\n\n private uniqueBy<T>(items: T[], getId: (item: T) => string): T[] {\n const byId = new Map<string, T>();\n\n for (const item of items) {\n byId.set(getId(item), item);\n }\n\n return Array.from(byId.values());\n }\n\n private sanitizeRecord(record: Record<string, unknown> | undefined): Record<string, unknown> {\n const safeRecord: Record<string, unknown> = { ...(record ?? {}) };\n delete (safeRecord as any).kg_nodes;\n delete (safeRecord as any).kg_relations;\n return safeRecord;\n }\n\n private async sparqlExecute(sparql: string, headers = \"\"): Promise<unknown> {\n // Some HANA environments require OUT parameters (e.g. RESPONSE) to be bound.\n // The @sap/hana-client driver provides a proc statement helper which correctly\n // handles OUT params *without* requiring you to pass them in the params array.\n try {\n const streamMod = await import(\"@sap/hana-client/extension/Stream\");\n const Stream = (streamMod as any).default ?? streamMod;\n\n return await new Promise<unknown>((resolve, reject) => {\n Stream.createProcStatement(this.conn as any, \"CALL SPARQL_EXECUTE(?, ?, ?, ?)\", (err: any, stmt: any) => {\n if (err) return reject(err);\n stmt.exec([sparql, headers], (err2: any, scalarParams: any) => {\n // scalarParams contains OUT params by name (e.g. RESPONSE)\n if (err2) return reject(err2);\n resolve(scalarParams);\n });\n });\n });\n } catch {\n // Fallback (may fail on systems requiring bound OUT params)\n return await new Promise<unknown>((resolve, reject) => {\n (this.conn as any).exec(\n \"CALL SPARQL_EXECUTE(?, ?, ?, ?)\",\n // Important: only pass IN params; OUT params are placeholders in SQL.\n [sparql, headers],\n (err: unknown, result: unknown) => {\n if (err) reject(err);\n else resolve(result);\n }\n );\n });\n }\n }\n\n private entityToUri(node: EntityNode): string {\n return `<urn:hkv:${this.graphName}:${node.label}:${encodeURIComponent(node.id)}>`;\n }\n\n private relationToTriples(rel: Relation, subj: EntityNode, obj: EntityNode): string {\n const subjUri = this.entityToUri(subj);\n const objUri = this.entityToUri(obj);\n const predUri = `<urn:hkv:rel:${rel.label}>`;\n return `${subjUri} ${predUri} ${objUri} .`;\n }\n\n private entityToTriples(node: EntityNode): string {\n const uri = this.entityToUri(node);\n const lines: string[] = [];\n lines.push(`${uri} a <urn:hkv:type:${node.label}> .`);\n lines.push(`${uri} <urn:hkv:prop:name> \"${this.escapeLiteral(node.name)}\" .`);\n\n for (const [key, value] of Object.entries(node.properties)) {\n if (value !== undefined && value !== null) {\n const strVal = typeof value === \"string\" ? value : String(value);\n // Skip overly large properties in RDF — they are already stored in the vectors table\n if (strVal.length > 5000) continue;\n const escaped = this.escapeLiteral(strVal);\n lines.push(`${uri} <urn:hkv:prop:${key}> \"${escaped}\" .`);\n }\n }\n\n return lines.join(\"\\n\");\n }\n\n private escapeLiteral(s: string): string {\n return s\n .replace(/\\\\/g, \"\\\\\\\\\")\n .replace(/\"/g, '\\\\\"')\n .replace(/\\n/g, \"\\\\n\")\n .replace(/\\r/g, \"\\\\r\")\n .replace(/\\t/g, \"\\\\t\");\n }\n\n async upsertNodes(nodes: EntityNode[]): Promise<void> {\n await this.ensureInitialized();\n if (nodes.length === 0) return;\n\n const uniqueNodes = this.uniqueBy(nodes, (node) => node.id);\n\n const triples = uniqueNodes.map((n) => this.entityToTriples(n)).join(\"\\n\");\n const sparql = `INSERT DATA { GRAPH <${this.graphName}> { ${triples} } }`;\n await this.sparqlExecute(sparql);\n\n const rowsWithEmbedding: unknown[][] = [];\n const rowsWithoutEmbedding: unknown[][] = [];\n\n for (const node of uniqueNodes) {\n const safeProps = this.sanitizeRecord(node.properties);\n const row = [node.id, node.label, node.name, JSON.stringify(safeProps)];\n if (node.embedding) {\n rowsWithEmbedding.push([...row, JSON.stringify(node.embedding)]);\n } else {\n rowsWithoutEmbedding.push(row);\n }\n }\n\n await this.execBatch(\n `\n UPSERT ${this.vectorTableName} (id, node_type, label, name, properties)\n VALUES (?, 'entity', ?, ?, ?)\n WITH PRIMARY KEY\n `,\n rowsWithoutEmbedding\n );\n\n await this.execBatch(\n `\n UPSERT ${this.vectorTableName} (id, node_type, label, name, properties, embedding)\n VALUES (?, 'entity', ?, ?, ?, TO_REAL_VECTOR(?))\n WITH PRIMARY KEY\n `,\n rowsWithEmbedding\n );\n }\n\n async upsertRelations(relations: Relation[]): Promise<void> {\n await this.ensureInitialized();\n if (relations.length === 0) return;\n\n const uniqueRelations = this.uniqueBy(\n relations,\n (rel) => rel.id ?? `${rel.sourceId}_${rel.label}_${rel.targetId}`\n );\n\n const nodeIds = new Set<string>();\n for (const rel of uniqueRelations) {\n nodeIds.add(rel.sourceId);\n nodeIds.add(rel.targetId);\n }\n\n const existingNodes = await this.get({ ids: Array.from(nodeIds) });\n const nodeMap = new Map(existingNodes.map((n) => [n.id, n]));\n\n // Write to RDF graph (backward compat — kept for installations that use SPARQL)\n const lines: string[] = [];\n for (const rel of uniqueRelations) {\n const subj = nodeMap.get(rel.sourceId);\n const obj = nodeMap.get(rel.targetId);\n if (subj && obj) {\n lines.push(this.relationToTriples(rel, subj, obj));\n }\n }\n\n if (lines.length > 0) {\n const sparql = `INSERT DATA { GRAPH <${this.graphName}> { ${lines.join(\"\\n\")} } }`;\n await this.sparqlExecute(sparql).catch((err: any) => {\n // SPARQL may fail if KG Engine is not enabled — log but don't block\n console.warn(`[HanaPropertyGraphStore] SPARQL INSERT for relations failed (non-fatal):`, err?.message ?? err);\n });\n }\n\n // Write to _VECTORS table for reliable SQL-based querying via getRelMap()\n const relationRows: unknown[][] = [];\n for (const rel of uniqueRelations) {\n const relId = rel.id ?? `${rel.sourceId}_${rel.label}_${rel.targetId}`;\n const safeProps: Record<string, unknown> = {\n sourceId: rel.sourceId,\n targetId: rel.targetId,\n ...(rel.properties ?? {}),\n };\n delete (safeProps as any).kg_nodes;\n delete (safeProps as any).kg_relations;\n\n relationRows.push([\n relId,\n rel.label,\n `${rel.sourceId} -> ${rel.targetId}`,\n JSON.stringify(safeProps),\n rel.sourceId,\n rel.targetId,\n ]);\n }\n\n await this.execBatch(\n `\n UPSERT ${this.vectorTableName} (id, node_type, label, name, properties, source_id, target_id)\n VALUES (?, 'relation', ?, ?, ?, ?, ?)\n WITH PRIMARY KEY\n `,\n relationRows\n );\n }\n\n async get(opts: { ids: string[] }): Promise<LabelledNode[]> {\n await this.ensureInitialized();\n if (opts.ids.length === 0) return [];\n\n const rows = (await this.exec(\n `SELECT id, label, name, properties FROM ${this.vectorTableName} WHERE id IN (${opts.ids.map(() => \"?\").join(\",\")})`,\n opts.ids\n )) as any[];\n\n return (rows ?? []).map((r) => ({\n id: r.ID ?? r.id,\n label: r.LABEL ?? r.label,\n name: r.NAME ?? r.name,\n properties: JSON.parse(r.PROPERTIES ?? r.properties ?? \"{}\"),\n }));\n }\n\n async getRelMap(opts: {\n nodes: LabelledNode[];\n depth?: number;\n limit?: number;\n ignoreRels?: string[];\n }): Promise<Triplet[]> {\n await this.ensureInitialized();\n if (opts.nodes.length === 0) return [];\n\n const nodeIds = opts.nodes.map((n) => n.id);\n const depth = opts.depth ?? 1;\n const limit = opts.limit ?? 100;\n const ignoreRels = opts.ignoreRels ?? [KG_SOURCE_REL];\n const ignoreRelSet = new Set(ignoreRels);\n\n const triplets: Triplet[] = [];\n const seenKeys = new Set<string>();\n const nodeMap = new Map(opts.nodes.map((n) => [n.id, n]));\n\n // --- SQL path: query _VECTORS WHERE node_type='relation' ---\n const placeholders = nodeIds.map(() => \"?\").join(\",\");\n const sqlRelQuery = `\n SELECT id, label, name, properties, source_id, target_id\n FROM ${this.vectorTableName}\n WHERE node_type = 'relation'\n AND (source_id IN (${placeholders}) OR target_id IN (${placeholders}))\n LIMIT ?\n `;\n const sqlParams = [...nodeIds, ...nodeIds, limit];\n\n try {\n const sqlRows = (await this.exec(sqlRelQuery, sqlParams)) as any[];\n for (const row of sqlRows ?? []) {\n const relLabel = row.LABEL ?? row.label;\n const sourceId = row.SOURCE_ID ?? row.source_id;\n const targetId = row.TARGET_ID ?? row.target_id;\n\n if (ignoreRelSet.has(relLabel)) continue;\n\n const key = `${sourceId}|${relLabel}|${targetId}`;\n if (seenKeys.has(key)) continue;\n seenKeys.add(key);\n\n let subj = nodeMap.get(sourceId);\n let obj = nodeMap.get(targetId);\n\n if (!subj) {\n subj = { id: sourceId, label: \"UNKNOWN\", name: sourceId, properties: {} };\n }\n if (!obj) {\n obj = { id: targetId, label: \"UNKNOWN\", name: targetId, properties: {} };\n }\n\n const rel: Relation = {\n id: row.ID ?? row.id,\n label: relLabel,\n sourceId,\n targetId,\n properties: JSON.parse(row.PROPERTIES ?? row.properties ?? \"{}\"),\n };\n\n triplets.push([subj, rel, obj]);\n }\n } catch (err: any) {\n console.warn(`[HanaPropertyGraphStore] SQL relation query failed (falling back to SPARQL only):`, err?.message ?? err);\n }\n\n // --- SPARQL path: query RDF graph (backward compat) ---\n try {\n const filterClause = nodeIds\n .map((id) => `CONTAINS(STR(?s), \"${encodeURIComponent(id)}\") || CONTAINS(STR(?o), \"${encodeURIComponent(id)}\")`)\n .join(\" || \");\n\n const ignoreFilter = ignoreRels.length > 0\n ? `FILTER(${ignoreRels.map((r) => `!CONTAINS(STR(?p), \"${r}\")`).join(\" && \")})`\n : \"\";\n\n const sparql = `\n SELECT ?s ?p ?o\n FROM <${this.graphName}>\n WHERE {\n ?s ?p ?o .\n FILTER(${filterClause})\n ${ignoreFilter}\n }\n LIMIT ${limit}\n `;\n\n const result = await this.exec(\n `SELECT * FROM SPARQL_TABLE('${sparql.replace(/'/g, \"''\")}')`\n ) as any[];\n\n for (const row of result ?? []) {\n const sUri = row.S ?? row.s;\n const pUri = row.P ?? row.p;\n const oUri = row.O ?? row.o;\n\n const sId = this.extractIdFromUri(sUri);\n const oId = this.extractIdFromUri(oUri);\n const relLabel = this.extractRelLabelFromUri(pUri);\n\n const key = `${sId}|${relLabel}|${oId}`;\n if (seenKeys.has(key)) continue;\n seenKeys.add(key);\n\n let subj = nodeMap.get(sId);\n let obj = nodeMap.get(oId);\n\n if (!subj) {\n subj = { id: sId, label: \"UNKNOWN\", name: sId, properties: {} };\n }\n if (!obj) {\n obj = { id: oId, label: \"UNKNOWN\", name: oId, properties: {} };\n }\n\n const rel: Relation = {\n label: relLabel,\n sourceId: sId,\n targetId: oId,\n properties: {},\n };\n\n triplets.push([subj, rel, obj]);\n }\n } catch (err: any) {\n // SPARQL may fail if KG Engine is not enabled — log but don't block\n console.warn(`[HanaPropertyGraphStore] SPARQL relation query failed (non-fatal):`, err?.message ?? err);\n }\n\n return triplets;\n }\n\n private extractIdFromUri(uri: string): string {\n // URI format: <urn:hkv:graphName:label:id> or just the content without angle brackets\n // The ID is the last segment after the label (second-to-last segment)\n const cleanUri = uri.replace(/^<|>$/g, \"\");\n const parts = cleanUri.split(\":\");\n // ID is the last part, decode it\n if (parts.length >= 2) {\n return decodeURIComponent(parts[parts.length - 1]);\n }\n return uri;\n }\n\n private extractRelLabelFromUri(uri: string): string {\n const match = uri.match(/urn:hkv:rel:(.+)>?$/);\n return match ? match[1].replace(/>$/, \"\") : uri;\n }\n\n async delete(opts: { ids: string[] }): Promise<void> {\n await this.ensureInitialized();\n if (opts.ids.length === 0) return;\n\n for (const id of opts.ids) {\n await this.exec(`DELETE FROM ${this.vectorTableName} WHERE id = ?`, [id]);\n }\n }\n\n async vectorQuery(query: VectorStoreQuery): Promise<[LabelledNode[], number[]]> {\n await this.ensureInitialized();\n\n const sql = `\n SELECT id, label, name, properties,\n COSINE_SIMILARITY(embedding, TO_REAL_VECTOR(?)) AS score\n FROM ${this.vectorTableName}\n WHERE embedding IS NOT NULL\n ORDER BY score DESC\n LIMIT ?\n `;\n\n const rows = (await this.exec(sql, [\n JSON.stringify(query.queryEmbedding),\n query.similarityTopK,\n ])) as any[];\n\n const nodes: LabelledNode[] = [];\n const scores: number[] = [];\n\n for (const row of rows ?? []) {\n nodes.push({\n id: row.ID ?? row.id,\n label: row.LABEL ?? row.label,\n name: row.NAME ?? row.name,\n properties: JSON.parse(row.PROPERTIES ?? row.properties ?? \"{}\"),\n });\n scores.push(row.SCORE ?? row.score ?? 0);\n }\n\n return [nodes, scores];\n }\n\n async upsertDocumentNodes(nodes: DocumentNode[]): Promise<void> {\n await this.ensureInitialized();\n if (nodes.length === 0) return;\n\n const uniqueNodes = this.uniqueBy(nodes, (node) => node.id);\n const docRowsWithEmbedding: unknown[][] = [];\n const docRowsWithoutEmbedding: unknown[][] = [];\n const vectorRowsWithEmbedding: unknown[][] = [];\n const vectorRowsWithoutEmbedding: unknown[][] = [];\n\n for (const node of uniqueNodes) {\n const safeMetadata = this.sanitizeRecord(node.metadata);\n const metadataJson = JSON.stringify(safeMetadata ?? {});\n const docRow = [node.id, node.text, metadataJson, node.hash ?? null];\n const vectorRow = [node.id, node.id, metadataJson];\n\n if (node.embedding) {\n const embeddingJson = JSON.stringify(node.embedding);\n docRowsWithEmbedding.push([...docRow, embeddingJson]);\n vectorRowsWithEmbedding.push([...vectorRow, embeddingJson]);\n } else {\n docRowsWithoutEmbedding.push(docRow);\n vectorRowsWithoutEmbedding.push(vectorRow);\n }\n }\n\n await this.execBatch(\n `\n UPSERT ${this.documentNodesTableName} (id, text, metadata, hash, embedding)\n VALUES (?, ?, ?, ?, TO_REAL_VECTOR(?))\n WITH PRIMARY KEY\n `,\n docRowsWithEmbedding\n );\n\n await this.execBatch(\n `\n UPSERT ${this.documentNodesTableName} (id, text, metadata, hash, embedding)\n VALUES (?, ?, ?, ?, NULL)\n WITH PRIMARY KEY\n `,\n docRowsWithoutEmbedding\n );\n\n await this.execBatch(\n `\n UPSERT ${this.vectorTableName} (id, node_type, label, name, properties, embedding)\n VALUES (?, 'document', 'DOCUMENT', ?, ?, TO_REAL_VECTOR(?))\n WITH PRIMARY KEY\n `,\n vectorRowsWithEmbedding\n );\n\n await this.execBatch(\n `\n UPSERT ${this.vectorTableName} (id, node_type, label, name, properties)\n VALUES (?, 'document', 'DOCUMENT', ?, ?)\n WITH PRIMARY KEY\n `,\n vectorRowsWithoutEmbedding\n );\n }\n\n async getDocumentNodes(ids: string[]): Promise<DocumentNode[]> {\n await this.ensureInitialized();\n if (ids.length === 0) return [];\n\n const rows = (await this.exec(\n `SELECT id, text, metadata, hash FROM ${this.documentNodesTableName} WHERE id IN (${ids.map(() => \"?\").join(\",\")})`,\n ids\n )) as any[];\n\n return (rows ?? []).map((r) => ({\n id: r.ID ?? r.id,\n text: r.TEXT ?? r.text,\n metadata: JSON.parse(r.METADATA ?? r.metadata ?? \"{}\"),\n hash: r.HASH ?? r.hash,\n }));\n }\n}\n","import type { QueryBundle, NodeWithScore } from \"./types\";\nimport type { BasePGRetriever } from \"./retrievers/base\";\n\nexport interface PGRetrieverOptions {\n subRetrievers: BasePGRetriever[];\n showProgress?: boolean;\n}\n\nexport class PGRetriever {\n private readonly subRetrievers: BasePGRetriever[];\n private readonly showProgress: boolean;\n\n constructor(options: PGRetrieverOptions) {\n this.subRetrievers = options.subRetrievers;\n this.showProgress = options.showProgress ?? false;\n }\n\n private deduplicate(nodes: NodeWithScore[]): NodeWithScore[] {\n const seen = new Set<string>();\n const deduped: NodeWithScore[] = [];\n\n for (const node of nodes) {\n if (!seen.has(node.node.text)) {\n deduped.push(node);\n seen.add(node.node.text);\n }\n }\n\n return deduped;\n }\n\n async retrieve(queryBundle: QueryBundle): Promise<NodeWithScore[]> {\n const allResults: NodeWithScore[] = [];\n\n const promises = this.subRetrievers.map((r) => r.retrieve(queryBundle));\n const results = await Promise.all(promises);\n\n for (const result of results) {\n allResults.push(...result);\n }\n\n return this.deduplicate(allResults);\n }\n}\n","import type { PropertyGraphStore } from \"../property-graph-store\";\nimport type { Triplet, NodeWithScore, QueryBundle, LabelledNode } from \"../types\";\nimport { TRIPLET_SOURCE_KEY, tripletToString } from \"../types\";\n\nexport const DEFAULT_PREAMBLE = \"Here are some facts extracted from the provided text:\\n\\n\";\n\nexport interface BasePGRetrieverOptions {\n graphStore: PropertyGraphStore;\n includeText?: boolean;\n includeTextPreamble?: string;\n includeProperties?: boolean;\n}\n\nexport abstract class BasePGRetriever {\n protected readonly graphStore: PropertyGraphStore;\n protected readonly includeText: boolean;\n protected readonly includeTextPreamble: string;\n protected readonly includeProperties: boolean;\n\n constructor(options: BasePGRetrieverOptions) {\n this.graphStore = options.graphStore;\n this.includeText = options.includeText ?? true;\n this.includeTextPreamble = options.includeTextPreamble ?? DEFAULT_PREAMBLE;\n this.includeProperties = options.includeProperties ?? false;\n }\n\n protected getNodesWithScore(triplets: Triplet[], scores?: number[]): NodeWithScore[] {\n const results: NodeWithScore[] = [];\n\n for (let i = 0; i < triplets.length; i++) {\n const triplet = triplets[i];\n const sourceId = triplet[0].properties[TRIPLET_SOURCE_KEY] as string | undefined;\n\n const text = tripletToString(triplet, this.includeProperties);\n\n results.push({\n node: {\n id: `triplet_${i}`,\n text,\n metadata: {},\n refDocId: sourceId,\n },\n score: scores?.[i] ?? 1.0,\n });\n }\n\n return results;\n }\n\n protected async addSourceText(nodes: NodeWithScore[]): Promise<NodeWithScore[]> {\n if (!this.graphStore.getDocumentNodes) {\n return nodes;\n }\n\n const refDocIds = nodes\n .map((n) => n.node.refDocId)\n .filter((id): id is string => id !== undefined);\n\n if (refDocIds.length === 0) return nodes;\n\n const ogNodes = await this.graphStore.getDocumentNodes(refDocIds);\n const nodeMap = new Map(ogNodes.map((n) => [n.id, n]));\n\n const graphNodeMap = new Map<string, string[]>();\n for (const node of nodes) {\n const refDocId = node.node.refDocId ?? \"\";\n if (!graphNodeMap.has(refDocId)) {\n graphNodeMap.set(refDocId, []);\n }\n graphNodeMap.get(refDocId)!.push(node.node.text);\n }\n\n const resultNodes: NodeWithScore[] = [];\n for (const nodeWithScore of nodes) {\n const mappedNode = nodeMap.get(nodeWithScore.node.refDocId ?? \"\");\n\n if (mappedNode) {\n const graphContent = graphNodeMap.get(mappedNode.id) ?? [];\n if (graphContent.length > 0) {\n const graphContentStr = graphContent.join(\"\\n\");\n const newContent = this.includeTextPreamble + graphContentStr + \"\\n\\n\" + mappedNode.text;\n resultNodes.push({\n node: {\n id: mappedNode.id,\n text: newContent,\n metadata: mappedNode.metadata,\n refDocId: nodeWithScore.node.refDocId,\n },\n score: nodeWithScore.score,\n });\n } else {\n resultNodes.push({\n node: {\n id: mappedNode.id,\n text: mappedNode.text,\n metadata: mappedNode.metadata,\n refDocId: nodeWithScore.node.refDocId,\n },\n score: nodeWithScore.score,\n });\n }\n } else {\n resultNodes.push(nodeWithScore);\n }\n }\n\n return resultNodes;\n }\n\n async retrieve(queryBundle: QueryBundle): Promise<NodeWithScore[]> {\n let nodes = await this.retrieveFromGraph(queryBundle);\n if (this.includeText && nodes.length > 0) {\n nodes = await this.addSourceText(nodes);\n }\n return nodes;\n }\n\n abstract retrieveFromGraph(queryBundle: QueryBundle): Promise<NodeWithScore[]>;\n}\n","import type { PropertyGraphStore, VectorStoreQuery } from \"../property-graph-store\";\nimport type { QueryBundle, NodeWithScore, LabelledNode } from \"../types\";\nimport { KG_SOURCE_REL, TRIPLET_SOURCE_KEY, STRUCT_SAME_PAGE, STRUCT_ADJACENT, STRUCT_CONTAINS } from \"../types\";\nimport { BasePGRetriever, type BasePGRetrieverOptions } from \"./base\";\n\nexport interface EmbedModel {\n getTextEmbedding(text: string): Promise<number[]>;\n getTextEmbeddingBatch(texts: string[]): Promise<number[][]>;\n}\n\nexport interface VectorContextRetrieverOptions extends BasePGRetrieverOptions {\n embedModel: EmbedModel;\n similarityTopK?: number;\n pathDepth?: number;\n limit?: number;\n similarityScore?: number;\n /** Enable cross-check boosting: boost scores when vector-matched entities link to graph facts (default: true) */\n crossCheckBoost?: boolean;\n /** Multiplier for cross-check boost (default: 1.25 = 25% boost) */\n crossCheckBoostFactor?: number;\n /** Include structural adjacency relations (ON_SAME_PAGE, ADJACENT_TO) in graph expansion (default: true) */\n includeStructuralEdges?: boolean;\n /** Depth for structural edge traversal (default: 1) */\n structuralDepth?: number;\n}\n\nexport class VectorContextRetriever extends BasePGRetriever {\n private readonly embedModel: EmbedModel;\n private readonly similarityTopK: number;\n private readonly pathDepth: number;\n private readonly limit: number;\n private readonly similarityScore?: number;\n private readonly crossCheckBoost: boolean;\n private readonly crossCheckBoostFactor: number;\n private readonly includeStructuralEdges: boolean;\n private readonly structuralDepth: number;\n\n constructor(options: VectorContextRetrieverOptions) {\n super(options);\n this.embedModel = options.embedModel;\n this.similarityTopK = options.similarityTopK ?? 4;\n this.pathDepth = options.pathDepth ?? 1;\n this.limit = options.limit ?? 30;\n this.similarityScore = options.similarityScore;\n this.crossCheckBoost = options.crossCheckBoost ?? true;\n this.crossCheckBoostFactor = options.crossCheckBoostFactor ?? 1.25;\n this.includeStructuralEdges = options.includeStructuralEdges ?? true;\n this.structuralDepth = options.structuralDepth ?? 1;\n }\n\n async retrieveFromGraph(queryBundle: QueryBundle): Promise<NodeWithScore[]> {\n let embedding = queryBundle.embedding;\n\n if (!embedding) {\n embedding = await this.embedModel.getTextEmbedding(queryBundle.queryStr);\n }\n\n const vectorQuery: VectorStoreQuery = {\n queryEmbedding: embedding,\n similarityTopK: this.similarityTopK,\n };\n\n if (!this.graphStore.supportsVectorQueries || !this.graphStore.vectorQuery) {\n throw new Error(\"Graph store does not support vector queries\");\n }\n\n const [kgNodes, scores] = await this.graphStore.vectorQuery(vectorQuery);\n\n if (kgNodes.length === 0) {\n return [];\n }\n\n // Partition vector results into document nodes and entity/other nodes\n const entityNodes: LabelledNode[] = [];\n const entityScores: number[] = [];\n const documentResults: NodeWithScore[] = [];\n\n for (let i = 0; i < kgNodes.length; i++) {\n const node = kgNodes[i];\n if (node.label === \"DOCUMENT\") {\n // Document nodes are direct results — they don't need graph traversal.\n // Use node.id as refDocId so addSourceText() can fetch full text from _NODES.\n documentResults.push({\n node: {\n id: node.id,\n text: `Document: ${node.name}`,\n metadata: node.properties ?? {},\n refDocId: node.id,\n },\n score: scores[i],\n });\n } else {\n entityNodes.push(node);\n entityScores.push(scores[i]);\n }\n }\n\n // --- Entity flow: graph traversal to find triplets ---\n let tripletResults: NodeWithScore[] = [];\n\n if (entityNodes.length > 0) {\n const kgIds = entityNodes.map((n) => n.id);\n\n // Build provenance set from vector-matched nodes for cross-check boosting\n const provenanceSet = new Set<string>();\n if (this.crossCheckBoost) {\n for (const node of entityNodes) {\n provenanceSet.add(node.id.toLowerCase());\n provenanceSet.add(node.name.toLowerCase());\n\n const props = node.properties ?? {};\n if (props.documentId) {\n provenanceSet.add(String(props.documentId).toLowerCase());\n }\n if (props.sourceChunk) {\n provenanceSet.add(String(props.sourceChunk).toLowerCase());\n }\n }\n }\n\n let triplets = await this.graphStore.getRelMap({\n nodes: entityNodes,\n depth: this.pathDepth,\n limit: this.limit,\n ignoreRels: [KG_SOURCE_REL],\n });\n\n // Structural expansion: traverse ON_SAME_PAGE, ADJACENT_TO edges from source chunks\n if (this.includeStructuralEdges) {\n const chunkIds = new Set<string>();\n for (const node of entityNodes) {\n const sourceId = node.properties?.[TRIPLET_SOURCE_KEY];\n if (sourceId) {\n chunkIds.add(`CHUNK_${String(sourceId).replace(/\\s+/g, \"_\").toUpperCase()}`);\n }\n if (node.label === \"CHUNK\") {\n chunkIds.add(node.id);\n }\n }\n\n if (chunkIds.size > 0) {\n const chunkNodes = await this.graphStore.get({ ids: Array.from(chunkIds) });\n if (chunkNodes.length > 0) {\n const structuralTriplets = await this.graphStore.getRelMap({\n nodes: chunkNodes,\n depth: this.structuralDepth,\n limit: this.limit,\n ignoreRels: [KG_SOURCE_REL],\n });\n\n const structuralRels = [STRUCT_SAME_PAGE, STRUCT_ADJACENT, STRUCT_CONTAINS];\n const structuralOnly = structuralTriplets.filter(([_s, r, _o]) =>\n structuralRels.includes(r.label)\n );\n\n const existingKeys = new Set(triplets.map(([s, r, o]) => `${s.id}|${r.label}|${o.id}`));\n for (const triplet of structuralOnly) {\n const key = `${triplet[0].id}|${triplet[1].label}|${triplet[2].id}`;\n if (!existingKeys.has(key)) {\n triplets.push(triplet);\n existingKeys.add(key);\n }\n }\n }\n }\n }\n\n const newScores: number[] = [];\n for (const triplet of triplets) {\n const idx1 = kgIds.indexOf(triplet[0].id);\n const idx2 = kgIds.indexOf(triplet[2].id);\n const score1 = idx1 >= 0 ? entityScores[idx1] : 0;\n const score2 = idx2 >= 0 ? entityScores[idx2] : 0;\n let baseScore = Math.max(score1, score2);\n\n if (this.crossCheckBoost && baseScore > 0) {\n const shouldBoost = this.checkProvenance(triplet[0], provenanceSet) ||\n this.checkProvenance(triplet[2], provenanceSet);\n if (shouldBoost) {\n baseScore = Math.min(1.0, baseScore * this.crossCheckBoostFactor);\n }\n }\n\n newScores.push(baseScore);\n }\n\n let results = triplets.map((t, i) => ({ triplet: t, score: newScores[i] }));\n\n if (this.similarityScore !== undefined) {\n results = results.filter((r) => r.score >= this.similarityScore!);\n }\n\n results.sort((a, b) => b.score - a.score);\n\n tripletResults = this.getNodesWithScore(\n results.map((r) => r.triplet),\n results.map((r) => r.score)\n );\n }\n\n // --- Merge document results and triplet results, sorted by score ---\n const allResults = [...documentResults, ...tripletResults];\n\n if (this.similarityScore !== undefined) {\n return allResults\n .filter((r) => r.score >= this.similarityScore!)\n .sort((a, b) => b.score - a.score);\n }\n\n return allResults.sort((a, b) => b.score - a.score);\n }\n\n /**\n * Check if a node has provenance linking to the vector-matched nodes.\n * Returns true if the node's properties contain a documentId or sourceChunk\n * that matches something in the provenance set.\n */\n private checkProvenance(node: LabelledNode, provenanceSet: Set<string>): boolean {\n if (provenanceSet.size === 0) return false;\n\n const props = node.properties ?? {};\n \n // Check documentId property\n if (props.documentId && provenanceSet.has(String(props.documentId).toLowerCase())) {\n return true;\n }\n \n // Check sourceChunk property\n if (props.sourceChunk && provenanceSet.has(String(props.sourceChunk).toLowerCase())) {\n return true;\n }\n \n // Check if this node itself is in the provenance set (e.g., a CHUNK node)\n if (provenanceSet.has(node.id.toLowerCase()) || provenanceSet.has(node.name.toLowerCase())) {\n return true;\n }\n\n return false;\n }\n}\n","import type { TransformComponent, TextNode } from \"./types\";\nimport type { EntityNode, Relation } from \"../types\";\nimport { KG_NODES_KEY, KG_RELATIONS_KEY, createEntityNode, createRelation } from \"../types\";\n\nexport class ImplicitPathExtractor implements TransformComponent {\n async transform(nodes: TextNode[], options?: { showProgress?: boolean }): Promise<TextNode[]> {\n const results: TextNode[] = [];\n\n for (const node of nodes) {\n const existingNodes = (node.metadata[KG_NODES_KEY] as EntityNode[]) ?? [];\n const existingRelations = (node.metadata[KG_RELATIONS_KEY] as Relation[]) ?? [];\n\n const safeMetadata: Record<string, unknown> = { ...node.metadata };\n delete safeMetadata[KG_NODES_KEY];\n delete safeMetadata[KG_RELATIONS_KEY];\n\n const chunkNode = createEntityNode({\n label: \"CHUNK\",\n name: node.id,\n properties: {\n text: node.text.slice(0, 500),\n ...safeMetadata,\n },\n });\n\n if (node.metadata.documentId) {\n const docNode = createEntityNode({\n label: \"DOCUMENT\",\n name: String(node.metadata.documentId),\n properties: {},\n });\n\n const rel = createRelation({\n label: \"FROM_DOCUMENT\",\n sourceId: chunkNode.id,\n targetId: docNode.id,\n });\n\n existingNodes.push(docNode);\n existingRelations.push(rel);\n }\n\n existingNodes.push(chunkNode);\n\n results.push({\n ...node,\n metadata: {\n ...node.metadata,\n [KG_NODES_KEY]: existingNodes,\n [KG_RELATIONS_KEY]: existingRelations,\n },\n });\n }\n\n return results;\n }\n}\n","import type { PropertyGraphStore } from \"./property-graph-store\";\nimport type { TransformComponent, TextNode } from \"./extractors/types\";\nimport type { EntityNode, Relation, NodeWithScore, QueryBundle } from \"./types\";\nimport { KG_NODES_KEY, KG_RELATIONS_KEY, TRIPLET_SOURCE_KEY } from \"./types\";\nimport { PGRetriever } from \"./pg-retriever\";\nimport { VectorContextRetriever, type EmbedModel } from \"./retrievers/vector-context\";\nimport { ImplicitPathExtractor } from \"./extractors/implicit\";\nimport { createHash } from \"crypto\";\nimport { get_encoding } from \"tiktoken\";\n\n/** Default token limit with safety buffer for text-embedding-3-small (8 192 token context). */\nconst DEFAULT_MAX_EMBED_TOKENS = 8_000;\n\nexport interface PropertyGraphIndexOptions {\n propertyGraphStore: PropertyGraphStore;\n kgExtractors?: TransformComponent[];\n embedModel?: EmbedModel;\n embedKgNodes?: boolean;\n showProgress?: boolean;\n /** Maximum tokens to send to the embedding model per text.\n * Texts exceeding this limit are truncated using tiktoken (cl100k_base encoding).\n * Default: 8 000 (safe for 8 192-token models like text-embedding-3-small). */\n maxEmbedTokens?: number;\n}\n\nexport class PropertyGraphIndex {\n private readonly propertyGraphStore: PropertyGraphStore;\n private readonly kgExtractors: TransformComponent[];\n private readonly embedModel?: EmbedModel;\n private readonly embedKgNodes: boolean;\n private readonly showProgress: boolean;\n private readonly maxEmbedTokens: number;\n\n constructor(options: PropertyGraphIndexOptions) {\n this.propertyGraphStore = options.propertyGraphStore;\n this.kgExtractors = options.kgExtractors ?? [new ImplicitPathExtractor()];\n this.embedModel = options.embedModel;\n this.embedKgNodes = options.embedKgNodes ?? true;\n this.showProgress = options.showProgress ?? false;\n this.maxEmbedTokens = options.maxEmbedTokens ?? DEFAULT_MAX_EMBED_TOKENS;\n }\n\n get graphStore(): PropertyGraphStore {\n return this.propertyGraphStore;\n }\n\n static fromExisting(options: PropertyGraphIndexOptions): PropertyGraphIndex {\n return new PropertyGraphIndex(options);\n }\n\n private computeHash(text: string): string {\n return createHash(\"md5\").update(text).digest(\"hex\");\n }\n\n private truncateForEmbedding(text: string): string {\n const enc = get_encoding(\"cl100k_base\");\n try {\n const tokens = enc.encode(text);\n if (tokens.length <= this.maxEmbedTokens) return text;\n const truncated = tokens.slice(0, this.maxEmbedTokens);\n return new TextDecoder().decode(enc.decode(truncated));\n } finally {\n enc.free();\n }\n }\n\n async insert(nodes: TextNode[]): Promise<TextNode[]> {\n if (nodes.length === 0) return [];\n\n let processedNodes = nodes;\n for (const extractor of this.kgExtractors) {\n processedNodes = await extractor.transform(processedNodes, {\n showProgress: this.showProgress,\n });\n }\n\n const hasExtractors = this.kgExtractors.length > 0;\n\n const kgNodesToInsert: EntityNode[] = [];\n const kgRelsToInsert: Relation[] = [];\n let newKgNodes: EntityNode[] = [];\n\n if (hasExtractors) {\n for (const node of processedNodes) {\n if (!node.metadata[KG_NODES_KEY] && !node.metadata[KG_RELATIONS_KEY]) {\n throw new Error(`Node ${node.id} has no KG_NODES_KEY or KG_RELATIONS_KEY after extraction`);\n }\n }\n\n for (const node of processedNodes) {\n const kgNodes = (node.metadata[KG_NODES_KEY] as EntityNode[]) ?? [];\n const kgRels = (node.metadata[KG_RELATIONS_KEY] as Relation[]) ?? [];\n\n for (const kgNode of kgNodes) {\n kgNode.properties[TRIPLET_SOURCE_KEY] = node.id;\n }\n for (const kgRel of kgRels) {\n kgRel.properties[TRIPLET_SOURCE_KEY] = node.id;\n }\n\n kgNodesToInsert.push(...kgNodes);\n kgRelsToInsert.push(...kgRels);\n }\n\n const kgNodeIds = [...new Set(kgNodesToInsert.map((n) => n.id))];\n const existingKgNodes = await this.propertyGraphStore.get({ ids: kgNodeIds });\n const existingKgNodeIds = new Set(existingKgNodes.map((n) => n.id));\n newKgNodes = kgNodesToInsert.filter((n) => !existingKgNodeIds.has(n.id));\n }\n\n if (this.propertyGraphStore.getDocumentNodes) {\n const existingDocumentNodes = await this.propertyGraphStore.getDocumentNodes(\n processedNodes.map((n) => n.id)\n );\n const existingHashes = new Set(existingDocumentNodes.map((n) => n.hash));\n processedNodes = processedNodes.filter((n) => {\n const hash = this.computeHash(n.text);\n n.hash = hash;\n return !existingHashes.has(hash);\n });\n }\n\n if (this.embedModel && processedNodes.length > 0) {\n const nodeTexts = processedNodes.map((n) => this.truncateForEmbedding(n.text));\n const embeddings = await this.embedModel.getTextEmbeddingBatch(nodeTexts);\n for (let i = 0; i < processedNodes.length; i++) {\n processedNodes[i].embedding = embeddings[i];\n }\n }\n\n if (this.embedKgNodes && this.embedModel && newKgNodes.length > 0) {\n const kgNodeTexts = newKgNodes.map((n) => `${n.label}: ${n.name}`);\n const kgEmbeddings = await this.embedModel.getTextEmbeddingBatch(kgNodeTexts);\n for (let i = 0; i < newKgNodes.length; i++) {\n newKgNodes[i].embedding = kgEmbeddings[i];\n }\n }\n\n if (this.propertyGraphStore.upsertDocumentNodes && processedNodes.length > 0) {\n await this.propertyGraphStore.upsertDocumentNodes(\n processedNodes.map((n) => ({\n id: n.id,\n text: n.text,\n metadata: n.metadata,\n embedding: n.embedding,\n hash: n.hash,\n }))\n );\n }\n\n if (newKgNodes.length > 0) {\n await this.propertyGraphStore.upsertNodes(newKgNodes);\n }\n\n if (kgRelsToInsert.length > 0) {\n await this.propertyGraphStore.upsertRelations(kgRelsToInsert);\n }\n\n return processedNodes;\n }\n\n async delete(nodeIds: string[]): Promise<void> {\n await this.propertyGraphStore.delete({ ids: nodeIds });\n }\n\n asRetriever(options?: {\n subRetrievers?: Array<{ retrieve(query: QueryBundle): Promise<NodeWithScore[]> }>;\n includeText?: boolean;\n /** Number of top similar nodes to retrieve via vector search (default: 4) */\n similarityTopK?: number;\n /** Graph traversal depth from matched nodes (default: 1) */\n pathDepth?: number;\n /** Maximum number of triplets to return after expansion (default: 30) */\n limit?: number;\n /** Minimum similarity score threshold to include results (default: no threshold) */\n similarityScore?: number;\n /** Enable cross-check boosting: boost scores when vector-matched entities link to graph facts (default: true) */\n crossCheckBoost?: boolean;\n /** Multiplier for cross-check boost (default: 1.25 = 25% boost) */\n crossCheckBoostFactor?: number;\n /** Include structural adjacency relations (ON_SAME_PAGE, ADJACENT_TO) in graph expansion (default: true) */\n includeStructuralEdges?: boolean;\n /** Depth for structural edge traversal (default: 1) */\n structuralDepth?: number;\n }): PGRetriever {\n let subRetrievers = options?.subRetrievers as any[];\n\n if (!subRetrievers && this.embedModel && this.propertyGraphStore.supportsVectorQueries) {\n subRetrievers = [\n new VectorContextRetriever({\n graphStore: this.propertyGraphStore,\n embedModel: this.embedModel,\n includeText: options?.includeText ?? true,\n similarityTopK: options?.similarityTopK,\n pathDepth: options?.pathDepth,\n limit: options?.limit,\n similarityScore: options?.similarityScore,\n crossCheckBoost: options?.crossCheckBoost,\n crossCheckBoostFactor: options?.crossCheckBoostFactor,\n includeStructuralEdges: options?.includeStructuralEdges,\n structuralDepth: options?.structuralDepth,\n }),\n ];\n }\n\n if (!subRetrievers) {\n subRetrievers = [];\n }\n\n return new PGRetriever({ subRetrievers });\n }\n\n async query(queryStr: string, options?: {\n /** Number of top similar nodes to retrieve via vector search (default: 4) */\n similarityTopK?: number;\n /** Graph traversal depth from matched nodes (default: 1) */\n pathDepth?: number;\n /** Maximum number of triplets to return after expansion (default: 30) */\n limit?: number;\n /** Minimum similarity score threshold to include results (default: no threshold) */\n similarityScore?: number;\n /** Enable cross-check boosting: boost scores when vector-matched entities link to graph facts (default: true) */\n crossCheckBoost?: boolean;\n /** Multiplier for cross-check boost (default: 1.25 = 25% boost) */\n crossCheckBoostFactor?: number;\n /** Include structural adjacency relations (ON_SAME_PAGE, ADJACENT_TO) in graph expansion (default: true) */\n includeStructuralEdges?: boolean;\n /** Depth for structural edge traversal (default: 1) */\n structuralDepth?: number;\n }): Promise<NodeWithScore[]> {\n const retriever = this.asRetriever(options);\n return retriever.retrieve({ queryStr });\n }\n}\n","import { z } from \"zod\";\nimport type { TransformComponent, TextNode, SchemaDefinition } from \"./types\";\nimport type { EntityNode, Relation, Triplet } from \"../types\";\nimport { KG_NODES_KEY, KG_RELATIONS_KEY, createEntityNode, createRelation } from \"../types\";\n\n/** Minimal contract for a schema — compatible with Zod 3, Zod 4, or any parse-capable object. */\nexport interface Parseable<T> {\n parse(data: unknown): T;\n}\n\nexport interface LLMClient {\n structuredPredict<T>(schema: Parseable<T>, prompt: string): Promise<T>;\n}\n\nexport interface SchemaLLMPathExtractorOptions {\n llm: LLMClient;\n schema: SchemaDefinition;\n maxTripletsPerChunk?: number;\n strict?: boolean;\n extractPromptTemplate?: string;\n}\n\nconst DEFAULT_EXTRACT_PROMPT = `Given the following text, extract a knowledge graph according to the provided schema.\nExtract up to {maxTriplets} triplets. If fewer are present in the text, return fewer. Do not invent or pad triplets.\n\nSchema:\n- Entity types: {entityTypes}\n- Relation types: {relationTypes}\n- Valid relationships: {validationSchema}\n\nText:\n-------\n{text}\n-------\n\nExtract entities and relationships from the text above.\nReturn your answer as a JSON object with a \"triplets\" array. Each triplet should have:\n- \"subject\": { \"name\": string, \"type\": one of [{entityTypes}] }\n- \"relation\": { \"type\": one of [{relationTypes}] }\n- \"object\": { \"name\": string, \"type\": one of [{entityTypes}] }\n\nExample output format:\n{\n \"triplets\": [\n {\n \"subject\": { \"name\": \"John\", \"type\": \"PERSON\" },\n \"relation\": { \"type\": \"WORKS_AT\" },\n \"object\": { \"name\": \"Acme Corp\", \"type\": \"ORGANIZATION\" }\n }\n ]\n}`;\n\nexport class SchemaLLMPathExtractor implements TransformComponent {\n private readonly llm: LLMClient;\n private readonly schema: SchemaDefinition;\n private readonly maxTripletsPerChunk: number;\n private readonly strict: boolean;\n private readonly extractPromptTemplate: string;\n private readonly tripletSchema: z.ZodType<any>;\n private readonly rawTripletSchema: z.ZodType<any>;\n\n constructor(options: SchemaLLMPathExtractorOptions) {\n this.llm = options.llm;\n this.schema = options.schema;\n this.maxTripletsPerChunk = options.maxTripletsPerChunk ?? 10;\n this.strict = options.strict ?? true;\n this.extractPromptTemplate = options.extractPromptTemplate ?? DEFAULT_EXTRACT_PROMPT;\n\n const entityTypeEnum = z.enum(this.schema.entityTypes as [string, ...string[]]);\n const relationTypeEnum = z.enum(this.schema.relationTypes as [string, ...string[]]);\n\n const entitySchema = z.object({\n name: z.string(),\n type: entityTypeEnum,\n properties: z.record(z.unknown()).optional(),\n });\n\n const relationSchema = z.object({\n type: relationTypeEnum,\n properties: z.record(z.unknown()).optional(),\n });\n\n const tripletSchema = z.object({\n subject: entitySchema,\n relation: relationSchema,\n object: entitySchema,\n });\n\n this.tripletSchema = z.object({\n triplets: z.array(tripletSchema),\n });\n\n this.rawTripletSchema = z.object({\n triplets: z.array(z.any()),\n });\n }\n\n private normalizeType(type: string): string {\n return String(type).toUpperCase().replace(/\\s+/g, \"_\");\n }\n\n private buildPrompt(text: string): string {\n const validationSchemaStr = this.schema.validationSchema\n ?.map(([s, r, o]) => `(${s})-[${r}]->(${o})`)\n .join(\", \") ?? \"Any valid combination\";\n\n return this.extractPromptTemplate\n .replace(\"{maxTriplets}\", String(this.maxTripletsPerChunk))\n .replace(\"{entityTypes}\", this.schema.entityTypes.join(\", \"))\n .replace(\"{relationTypes}\", this.schema.relationTypes.join(\", \"))\n .replace(\"{validationSchema}\", validationSchemaStr)\n .replace(\"{text}\", text);\n }\n\n private isValidTriplet(subjectType: string, relationType: string, objectType: string): boolean {\n if (!this.strict || !this.schema.validationSchema) {\n return true;\n }\n\n const subj = this.normalizeType(subjectType);\n const rel = this.normalizeType(relationType);\n const obj = this.normalizeType(objectType);\n\n return this.schema.validationSchema.some(\n ([s, r, o]) =>\n this.normalizeType(s) === subj &&\n this.normalizeType(r) === rel &&\n this.normalizeType(o) === obj\n );\n }\n\n private pruneInvalidTriplets(\n extracted: { triplets: Array<{ subject: any; relation: any; object: any }> }\n ): Triplet[] {\n const validTriplets: Triplet[] = [];\n\n const allowedEntityTypes = new Set(this.schema.entityTypes.map((t) => this.normalizeType(t)));\n const allowedRelationTypes = new Set(this.schema.relationTypes.map((t) => this.normalizeType(t)));\n\n for (const triplet of extracted.triplets) {\n const subject = (triplet as any)?.subject;\n const relation = (triplet as any)?.relation;\n const object = (triplet as any)?.object;\n\n if (!subject || !relation || !object) continue;\n if (typeof subject.type !== \"string\" || typeof subject.name !== \"string\") continue;\n if (typeof relation.type !== \"string\") continue;\n if (typeof object.type !== \"string\" || typeof object.name !== \"string\") continue;\n\n const subjectType = this.normalizeType(subject.type);\n const relationType = this.normalizeType(relation.type);\n const objectType = this.normalizeType(object.type);\n\n if (this.strict) {\n if (!allowedEntityTypes.has(subjectType)) continue;\n if (!allowedRelationTypes.has(relationType)) continue;\n if (!allowedEntityTypes.has(objectType)) continue;\n }\n\n if (!this.isValidTriplet(subjectType, relationType, objectType)) {\n continue;\n }\n\n const subjectName = String(triplet.subject.name).trim();\n const objectName = String(triplet.object.name).trim();\n\n if (subjectName.toLowerCase() === objectName.toLowerCase()) {\n continue;\n }\n\n const subj = createEntityNode({\n label: subjectType,\n name: subjectName,\n properties: triplet.subject.properties ?? {},\n });\n\n const obj = createEntityNode({\n label: objectType,\n name: objectName,\n properties: triplet.object.properties ?? {},\n });\n\n const rel = createRelation({\n label: relationType,\n sourceId: subj.id,\n targetId: obj.id,\n properties: triplet.relation.properties ?? {},\n });\n\n validTriplets.push([subj, rel, obj]);\n }\n\n return validTriplets;\n }\n\n private async extractFromNode(node: TextNode): Promise<TextNode> {\n const prompt = this.buildPrompt(node.text);\n\n let triplets: Triplet[] = [];\n\n try {\n const result = await this.llm.structuredPredict(this.rawTripletSchema, prompt);\n triplets = this.pruneInvalidTriplets(result);\n\n if (this.maxTripletsPerChunk > 0 && triplets.length > this.maxTripletsPerChunk) {\n triplets = triplets.slice(0, this.maxTripletsPerChunk);\n }\n } catch (err) {\n // Log extraction errors for debugging\n console.warn(`[SchemaLLMPathExtractor] Failed to extract from node ${node.id}:`, err);\n triplets = [];\n }\n\n const existingNodes = (node.metadata[KG_NODES_KEY] as EntityNode[]) ?? [];\n const existingRelations = (node.metadata[KG_RELATIONS_KEY] as Relation[]) ?? [];\n\n // Avoid copying kg_nodes/kg_relations into node properties (can create circular refs)\n const safeMetadata: Record<string, unknown> = { ...node.metadata };\n delete safeMetadata[KG_NODES_KEY];\n delete safeMetadata[KG_RELATIONS_KEY];\n\n for (const [subj, rel, obj] of triplets) {\n subj.properties = { ...subj.properties, ...safeMetadata };\n obj.properties = { ...obj.properties, ...safeMetadata };\n rel.properties = { ...rel.properties, ...safeMetadata };\n\n existingNodes.push(subj);\n existingNodes.push(obj);\n existingRelations.push(rel);\n }\n\n return {\n ...node,\n metadata: {\n ...node.metadata,\n [KG_NODES_KEY]: existingNodes,\n [KG_RELATIONS_KEY]: existingRelations,\n },\n };\n }\n\n async transform(nodes: TextNode[], options?: { showProgress?: boolean }): Promise<TextNode[]> {\n const results: TextNode[] = [];\n\n for (const node of nodes) {\n const processed = await this.extractFromNode(node);\n results.push(processed);\n }\n\n return results;\n }\n}\n","import type { TransformComponent, TextNode } from \"./types\";\nimport type { Relation } from \"../types\";\nimport { KG_RELATIONS_KEY, STRUCT_SAME_PAGE, STRUCT_ADJACENT } from \"../types\";\n\nexport interface AdjacencyLinkerOptions {\n /**\n * Link chunks that share the same pageNumber in metadata.\n * Default: true\n */\n linkSamePage?: boolean;\n\n /**\n * Link chunks that are adjacent by chunkIndex in metadata.\n * Default: true\n */\n linkAdjacent?: boolean;\n\n /**\n * Maximum chunk index distance for ADJACENT_TO links.\n * Default: 1 (immediate neighbors only)\n */\n adjacentDistance?: number;\n\n /**\n * Only create cross-type links (e.g., text↔image), not text↔text.\n * Default: false (link all)\n */\n crossTypeOnly?: boolean;\n}\n\nexport class AdjacencyLinker implements TransformComponent {\n private linkSamePage: boolean;\n private linkAdjacent: boolean;\n private adjacentDistance: number;\n private crossTypeOnly: boolean;\n\n constructor(options: AdjacencyLinkerOptions = {}) {\n this.linkSamePage = options.linkSamePage ?? true;\n this.linkAdjacent = options.linkAdjacent ?? true;\n this.adjacentDistance = options.adjacentDistance ?? 1;\n this.crossTypeOnly = options.crossTypeOnly ?? false;\n }\n\n /**\n * Transform is called AFTER other extractors (SchemaLLMPathExtractor, ImplicitPathExtractor).\n * It adds structural relations between chunks based on metadata.\n */\n async transform(nodes: TextNode[], options?: { showProgress?: boolean }): Promise<TextNode[]> {\n if (nodes.length < 2) return nodes;\n\n // Group nodes by documentId\n const byDocument = new Map<string, TextNode[]>();\n for (const node of nodes) {\n const docId = String(node.metadata.documentId ?? \"unknown\");\n if (!byDocument.has(docId)) byDocument.set(docId, []);\n byDocument.get(docId)!.push(node);\n }\n\n // For each document, create structural links\n // Map from node.id to relations that should be added to that node\n const nodeRelationsMap = new Map<string, Relation[]>();\n\n for (const [docId, docNodes] of byDocument) {\n // Group by page\n const byPage = new Map<number, TextNode[]>();\n for (const node of docNodes) {\n const page = Number(node.metadata.pageNumber ?? 0);\n if (!byPage.has(page)) byPage.set(page, []);\n byPage.get(page)!.push(node);\n }\n\n // Same-page links\n if (this.linkSamePage) {\n for (const [page, pageNodes] of byPage) {\n if (pageNodes.length < 2) continue;\n for (let i = 0; i < pageNodes.length; i++) {\n for (let j = i + 1; j < pageNodes.length; j++) {\n const a = pageNodes[i];\n const b = pageNodes[j];\n if (this.shouldLink(a, b)) {\n this.addRelation(nodeRelationsMap, a.id, b.id, STRUCT_SAME_PAGE, { pageNumber: page, documentId: docId });\n }\n }\n }\n }\n }\n\n // Adjacent chunk links (by chunkIndex)\n if (this.linkAdjacent) {\n // Sort by chunkIndex\n const sorted = [...docNodes].sort((a, b) => {\n const idxA = Number(a.metadata.chunkIndex ?? 0);\n const idxB = Number(b.metadata.chunkIndex ?? 0);\n return idxA - idxB;\n });\n\n for (let i = 0; i < sorted.length; i++) {\n for (let d = 1; d <= this.adjacentDistance && i + d < sorted.length; d++) {\n const a = sorted[i];\n const b = sorted[i + d];\n if (this.shouldLink(a, b)) {\n this.addRelation(nodeRelationsMap, a.id, b.id, STRUCT_ADJACENT, { distance: d, documentId: docId });\n }\n }\n }\n }\n }\n\n // Merge relations into node metadata\n return nodes.map((node) => {\n const existingRelations = (node.metadata[KG_RELATIONS_KEY] as Relation[]) ?? [];\n const newRelations = nodeRelationsMap.get(node.id) ?? [];\n\n return {\n ...node,\n metadata: {\n ...node.metadata,\n [KG_RELATIONS_KEY]: [...existingRelations, ...newRelations],\n },\n };\n });\n }\n\n private shouldLink(a: TextNode, b: TextNode): boolean {\n if (!this.crossTypeOnly) return true;\n const typeA = String(a.metadata.contentType ?? \"text\");\n const typeB = String(b.metadata.contentType ?? \"text\");\n return typeA !== typeB;\n }\n\n private addRelation(\n map: Map<string, Relation[]>,\n sourceNodeId: string,\n targetNodeId: string,\n label: string,\n properties: Record<string, unknown>\n ): void {\n // Create CHUNK entity IDs (matching ImplicitPathExtractor format)\n const sourceId = `CHUNK_${sourceNodeId.replace(/\\s+/g, \"_\").toUpperCase()}`;\n const targetId = `CHUNK_${targetNodeId.replace(/\\s+/g, \"_\").toUpperCase()}`;\n\n const rel: Relation = {\n id: `${sourceId}_${label}_${targetId}`,\n label,\n sourceId,\n targetId,\n properties,\n };\n\n // Add to source node\n if (!map.has(sourceNodeId)) map.set(sourceNodeId, []);\n map.get(sourceNodeId)!.push(rel);\n\n // Bidirectional: also add reverse to target node\n const reverseRel: Relation = {\n id: `${targetId}_${label}_${sourceId}`,\n label,\n sourceId: targetId,\n targetId: sourceId,\n properties,\n };\n\n if (!map.has(targetNodeId)) map.set(targetNodeId, []);\n map.get(targetNodeId)!.push(reverseRel);\n }\n}\n"],"mappings":";AAAO,SAAS,cACd,MACA,cACgC;AAChC,QAAM,MAAM,KAAK,YAAY,GAAG;AAChC,MAAI,MAAM,MAAM,MAAM,KAAK,SAAS,GAAG;AACrC,UAAM,YAAY,OAAO,KAAK,MAAM,MAAM,CAAC,CAAC;AAC5C,QAAI,CAAC,OAAO,MAAM,SAAS,KAAK,YAAY,GAAG;AAC7C,aAAO,EAAE,MAAM,KAAK,MAAM,GAAG,GAAG,GAAG,MAAM,UAAU;AAAA,IACrD;AAAA,EACF;AAEA,SAAO,EAAE,MAAM,MAAM,aAAa;AACpC;;;ACVA,eAAsB,qBACpB,QACyB;AACzB,MAAI;AACJ,MAAI;AACF,UAAM,aAAa,MAAM,OAAO,kBAAkB;AAClD,WAAQ,WAAmB,WAAW;AAAA,EACxC,QAAQ;AACN,UAAM,IAAI;AAAA,MACR;AAAA,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Q;AAAA,MACpC;AAAA,MACA,UAAU;AAAA,MACV,UAAU;AAAA,MACV;AAAA,IACF;AAEA,QAAI,CAAC,IAAI,IAAI,YAAY,EAAG,KAAI,IAAI,cAAc,CAAC,CAAC;AACpD,QAAI,IAAI,YAAY,EAAG,KAAK,UAAU;AAAA,EACxC;AACF;","names":["z","z"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hana-kgvector",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.12",
|
|
4
4
|
"description": "A TypeScript framework for building hybrid GraphRAG applications using SAP HANA Cloud as the unified backend for knowledge graphs (RDF) and vector embeddings",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -31,13 +31,6 @@
|
|
|
31
31
|
"url": "https://github.com/skye0402/hana-kgvector/issues"
|
|
32
32
|
},
|
|
33
33
|
"homepage": "https://github.com/skye0402/hana-kgvector#readme",
|
|
34
|
-
"scripts": {
|
|
35
|
-
"build": "tsup",
|
|
36
|
-
"dev": "tsx src/index.ts",
|
|
37
|
-
"phase0:litellm": "tsx scripts/validate-litellm.ts",
|
|
38
|
-
"phase0:hana": "tsx scripts/validate-hana.ts",
|
|
39
|
-
"smoke:pg": "tsx scripts/smoke-property-graph.ts"
|
|
40
|
-
},
|
|
41
34
|
"dependencies": {
|
|
42
35
|
"openai": "^4.104.0",
|
|
43
36
|
"tiktoken": "^1.0.22",
|
|
@@ -52,5 +45,12 @@
|
|
|
52
45
|
"tsup": "^8.5.1",
|
|
53
46
|
"tsx": "^4.21.0",
|
|
54
47
|
"typescript": "^5.9.3"
|
|
48
|
+
},
|
|
49
|
+
"scripts": {
|
|
50
|
+
"build": "tsup",
|
|
51
|
+
"dev": "tsx src/index.ts",
|
|
52
|
+
"phase0:litellm": "tsx scripts/validate-litellm.ts",
|
|
53
|
+
"phase0:hana": "tsx scripts/validate-hana.ts",
|
|
54
|
+
"smoke:pg": "tsx scripts/smoke-property-graph.ts"
|
|
55
55
|
}
|
|
56
|
-
}
|
|
56
|
+
}
|