@nicia-ai/typegraph 0.20.0 → 0.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{ast-Bh2NDeaK.d.cts → ast-CSLbPIOC.d.ts} +56 -3
- package/dist/{ast-COMyNeMn.d.ts → ast-DogwbBqA.d.cts} +56 -3
- package/dist/backend/postgres/index.cjs +123 -45
- package/dist/backend/postgres/index.cjs.map +1 -1
- package/dist/backend/postgres/index.d.cts +15 -7
- package/dist/backend/postgres/index.d.ts +15 -7
- package/dist/backend/postgres/index.js +101 -23
- package/dist/backend/postgres/index.js.map +1 -1
- package/dist/backend/sqlite/index.cjs +15 -15
- package/dist/backend/sqlite/index.d.cts +22 -7
- package/dist/backend/sqlite/index.d.ts +22 -7
- package/dist/backend/sqlite/index.js +5 -5
- package/dist/backend/sqlite/libsql.cjs +8 -8
- package/dist/backend/sqlite/libsql.d.cts +4 -5
- package/dist/backend/sqlite/libsql.d.ts +4 -5
- package/dist/backend/sqlite/libsql.js +5 -5
- package/dist/backend/sqlite/local.cjs +27 -10
- package/dist/backend/sqlite/local.cjs.map +1 -1
- package/dist/backend/sqlite/local.d.cts +4 -5
- package/dist/backend/sqlite/local.d.ts +4 -5
- package/dist/backend/sqlite/local.js +22 -6
- package/dist/backend/sqlite/local.js.map +1 -1
- package/dist/{chunk-MME3H4ZF.cjs → chunk-3JK66E3I.cjs} +387 -9
- package/dist/chunk-3JK66E3I.cjs.map +1 -0
- package/dist/{chunk-6GWJH6AR.js → chunk-3PPEHLGK.js} +4 -4
- package/dist/{chunk-6GWJH6AR.js.map → chunk-3PPEHLGK.js.map} +1 -1
- package/dist/{chunk-QFZQGEQ3.js → chunk-5ZMMHUWR.js} +199 -38
- package/dist/chunk-5ZMMHUWR.js.map +1 -0
- package/dist/{chunk-GNIYZKBI.js → chunk-753F33CV.js} +378 -8
- package/dist/chunk-753F33CV.js.map +1 -0
- package/dist/{chunk-K7SQ3SWP.js → chunk-EYELZHKY.js} +120 -12
- package/dist/chunk-EYELZHKY.js.map +1 -0
- package/dist/{chunk-HXJXTOXR.cjs → chunk-GUYI6VAS.cjs} +101 -21
- package/dist/chunk-GUYI6VAS.cjs.map +1 -0
- package/dist/{chunk-X33WV2UF.cjs → chunk-HRNQ3DVJ.cjs} +24 -21
- package/dist/chunk-HRNQ3DVJ.cjs.map +1 -0
- package/dist/{chunk-W6M7XWKX.js → chunk-JYUQA77I.js} +21 -18
- package/dist/chunk-JYUQA77I.js.map +1 -0
- package/dist/{chunk-LLHFS53Q.js → chunk-NSLTDXVH.js} +91 -11
- package/dist/chunk-NSLTDXVH.js.map +1 -0
- package/dist/{chunk-LELLOHJK.cjs → chunk-PEE4EWXZ.cjs} +35 -35
- package/dist/{chunk-LELLOHJK.cjs.map → chunk-PEE4EWXZ.cjs.map} +1 -1
- package/dist/{chunk-G5CYWKRF.js → chunk-RS5OLGEW.js} +2 -2
- package/dist/{chunk-G5CYWKRF.js.map → chunk-RS5OLGEW.js.map} +1 -1
- package/dist/{chunk-IYWWXOVK.cjs → chunk-SCXOGKLD.cjs} +252 -91
- package/dist/chunk-SCXOGKLD.cjs.map +1 -0
- package/dist/{chunk-P5CNM325.cjs → chunk-UVZHTBZ5.cjs} +123 -11
- package/dist/chunk-UVZHTBZ5.cjs.map +1 -0
- package/dist/{chunk-5GZMPJOP.cjs → chunk-WRWVWKQL.cjs} +2 -2
- package/dist/{chunk-5GZMPJOP.cjs.map → chunk-WRWVWKQL.cjs.map} +1 -1
- package/dist/{ddl-BBo2EcFc.d.cts → ddl-BqkTShcR.d.ts} +28 -6
- package/dist/{ddl-D4jlcOH_.d.ts → ddl-Dk1NDN3M.d.cts} +28 -6
- package/dist/index.cjs +1809 -513
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +53 -11
- package/dist/index.d.ts +53 -11
- package/dist/index.js +1668 -398
- package/dist/index.js.map +1 -1
- package/dist/indexes/index.cjs +17 -17
- package/dist/indexes/index.d.cts +5 -5
- package/dist/indexes/index.d.ts +5 -5
- package/dist/indexes/index.js +3 -3
- package/dist/interchange/index.cjs +6 -6
- package/dist/interchange/index.d.cts +4 -5
- package/dist/interchange/index.d.ts +4 -5
- package/dist/interchange/index.js +1 -1
- package/dist/{manager-Chhrq1vl.d.ts → manager-0jVZtiE8.d.ts} +1 -2
- package/dist/{manager-Bj1UEnhE.d.cts → manager-BPK-2PUI.d.cts} +1 -2
- package/dist/profiler/index.cjs +15 -8
- package/dist/profiler/index.cjs.map +1 -1
- package/dist/profiler/index.d.cts +7 -8
- package/dist/profiler/index.d.ts +7 -8
- package/dist/profiler/index.js +8 -1
- package/dist/profiler/index.js.map +1 -1
- package/dist/schema/index.cjs +21 -21
- package/dist/schema/index.d.cts +4 -5
- package/dist/schema/index.d.ts +4 -5
- package/dist/schema/index.js +3 -3
- package/dist/{sqlite-DE-6NWtC.d.cts → sqlite-D1rrwcir.d.cts} +14 -1
- package/dist/{sqlite-Blq-AhmK.d.ts → sqlite-W3rmJMlc.d.ts} +14 -1
- package/dist/{store-BMrRi_mY.d.ts → store-2QW2SIRk.d.cts} +404 -5
- package/dist/{store-DRRvALu8.d.cts → store-C0q13mtJ.d.ts} +404 -5
- package/dist/{types-B3mmOMJV.d.cts → types-CQF88McG.d.cts} +475 -2
- package/dist/{types-ThB4cFLp.d.ts → types-CQF88McG.d.ts} +475 -2
- package/dist/{types-COPePE8_.d.ts → types-CglvhPKz.d.ts} +1 -1
- package/dist/{types-CVtGFpB9.d.cts → types-D23slCOA.d.cts} +1 -1
- package/dist/{types-Ceb01czq.d.ts → types-IMQCuser.d.ts} +2 -2
- package/dist/{types-CZd2PEOc.d.cts → types-vgjar7Ch.d.cts} +2 -2
- package/package.json +9 -9
- package/dist/chunk-GNIYZKBI.js.map +0 -1
- package/dist/chunk-HXJXTOXR.cjs.map +0 -1
- package/dist/chunk-IYWWXOVK.cjs.map +0 -1
- package/dist/chunk-K7SQ3SWP.js.map +0 -1
- package/dist/chunk-LLHFS53Q.js.map +0 -1
- package/dist/chunk-MME3H4ZF.cjs.map +0 -1
- package/dist/chunk-P5CNM325.cjs.map +0 -1
- package/dist/chunk-QFZQGEQ3.js.map +0 -1
- package/dist/chunk-W6M7XWKX.js.map +0 -1
- package/dist/chunk-X33WV2UF.cjs.map +0 -1
- package/dist/types-DMzKq0d5.d.cts +0 -181
- package/dist/types-DMzKq0d5.d.ts +0 -181
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DatabaseOperationError, UniquenessError } from './chunk-WFMTAEEN.js';
|
|
2
|
-
import { buildPostgresNodeIndexBuilders, buildPostgresEdgeIndexBuilders, buildSqliteNodeIndexBuilders, buildSqliteEdgeIndexBuilders } from './chunk-
|
|
3
|
-
import { MAX_PG_IDENTIFIER_LENGTH } from './chunk-
|
|
2
|
+
import { buildPostgresNodeIndexBuilders, buildPostgresEdgeIndexBuilders, buildSqliteNodeIndexBuilders, buildSqliteEdgeIndexBuilders } from './chunk-3PPEHLGK.js';
|
|
3
|
+
import { tsvectorStrategy, fts5Strategy, MAX_PG_IDENTIFIER_LENGTH, quotedTableName, quotedColumn, edgeColumnList, sqlNull, nodeColumnList } from './chunk-753F33CV.js';
|
|
4
4
|
import { customType, pgTable, timestamp, integer, jsonb, text, primaryKey, index, boolean, getTableConfig as getTableConfig$1 } from 'drizzle-orm/pg-core';
|
|
5
5
|
import { sqliteTable, text as text$1, integer as integer$1, primaryKey as primaryKey$1, index as index$1, blob, getTableConfig } from 'drizzle-orm/sqlite-core';
|
|
6
6
|
import { sql, getTableName } from 'drizzle-orm';
|
|
@@ -67,7 +67,8 @@ var DEFAULT_TABLE_NAMES = {
|
|
|
67
67
|
edges: "typegraph_edges",
|
|
68
68
|
uniques: "typegraph_node_uniques",
|
|
69
69
|
schemaVersions: "typegraph_schema_versions",
|
|
70
|
-
embeddings: "typegraph_node_embeddings"
|
|
70
|
+
embeddings: "typegraph_node_embeddings",
|
|
71
|
+
fulltext: "typegraph_node_fulltext"
|
|
71
72
|
};
|
|
72
73
|
function createPostgresTables(names = {}, options = {}) {
|
|
73
74
|
const n = { ...DEFAULT_TABLE_NAMES, ...names };
|
|
@@ -224,7 +225,23 @@ function createPostgresTables(names = {}, options = {}) {
|
|
|
224
225
|
)
|
|
225
226
|
]
|
|
226
227
|
);
|
|
227
|
-
return {
|
|
228
|
+
return {
|
|
229
|
+
nodes: nodes3,
|
|
230
|
+
edges: edges3,
|
|
231
|
+
uniques: uniques3,
|
|
232
|
+
schemaVersions: schemaVersions3,
|
|
233
|
+
embeddings: embeddings3,
|
|
234
|
+
/**
|
|
235
|
+
* The fulltext storage table is owned by the active `FulltextStrategy`,
|
|
236
|
+
* not Drizzle. Shapes vary across strategies — the default `tsvectorStrategy`
|
|
237
|
+
* uses a `regconfig` language column, a GENERATED STORED `tsv` column,
|
|
238
|
+
* and a GIN index; alternate strategies (ParadeDB, pg_trgm, pgroonga)
|
|
239
|
+
* pick their own column types and index methods. DDL is emitted as
|
|
240
|
+
* raw SQL via `strategy.generateDdl()`; reads and writes are composed
|
|
241
|
+
* from the strategy's fragment helpers.
|
|
242
|
+
*/
|
|
243
|
+
fulltextTableName: n.fulltext
|
|
244
|
+
};
|
|
228
245
|
}
|
|
229
246
|
var tables = createPostgresTables();
|
|
230
247
|
var { nodes, edges, uniques, schemaVersions, embeddings } = tables;
|
|
@@ -233,7 +250,8 @@ var DEFAULT_TABLE_NAMES2 = {
|
|
|
233
250
|
edges: "typegraph_edges",
|
|
234
251
|
uniques: "typegraph_node_uniques",
|
|
235
252
|
schemaVersions: "typegraph_schema_versions",
|
|
236
|
-
embeddings: "typegraph_node_embeddings"
|
|
253
|
+
embeddings: "typegraph_node_embeddings",
|
|
254
|
+
fulltext: "typegraph_node_fulltext"
|
|
237
255
|
};
|
|
238
256
|
function createSqliteTables(names = {}, options = {}) {
|
|
239
257
|
const n = { ...DEFAULT_TABLE_NAMES2, ...names };
|
|
@@ -394,7 +412,19 @@ function createSqliteTables(names = {}, options = {}) {
|
|
|
394
412
|
)
|
|
395
413
|
]
|
|
396
414
|
);
|
|
397
|
-
return {
|
|
415
|
+
return {
|
|
416
|
+
nodes: nodes3,
|
|
417
|
+
edges: edges3,
|
|
418
|
+
uniques: uniques3,
|
|
419
|
+
schemaVersions: schemaVersions3,
|
|
420
|
+
embeddings: embeddings3,
|
|
421
|
+
/**
|
|
422
|
+
* The fulltext storage is a FTS5 virtual table which Drizzle cannot
|
|
423
|
+
* represent. DDL is emitted as raw SQL and operations query it via
|
|
424
|
+
* `sql.raw()`.
|
|
425
|
+
*/
|
|
426
|
+
fulltextTableName: n.fulltext
|
|
427
|
+
};
|
|
398
428
|
}
|
|
399
429
|
var tables2 = createSqliteTables();
|
|
400
430
|
var { nodes: nodes2, edges: edges2, uniques: uniques2, schemaVersions: schemaVersions2, embeddings: embeddings2 } = tables2;
|
|
@@ -473,8 +503,17 @@ function flattenSqlChunk(chunk) {
|
|
|
473
503
|
return chunk;
|
|
474
504
|
}
|
|
475
505
|
if (typeof chunk === "object" && chunk !== null) {
|
|
476
|
-
if ("
|
|
477
|
-
return chunk.
|
|
506
|
+
if ("name" in chunk && typeof chunk.name === "string") {
|
|
507
|
+
return `"${chunk.name}"`;
|
|
508
|
+
}
|
|
509
|
+
if ("value" in chunk) {
|
|
510
|
+
const value = chunk.value;
|
|
511
|
+
if (typeof value === "string") {
|
|
512
|
+
return value;
|
|
513
|
+
}
|
|
514
|
+
if (Array.isArray(value)) {
|
|
515
|
+
return value.map((part) => flattenSqlChunk(part)).join("");
|
|
516
|
+
}
|
|
478
517
|
}
|
|
479
518
|
if ("queryChunks" in chunk && Array.isArray(chunk.queryChunks)) {
|
|
480
519
|
return chunk.queryChunks.map((part) => flattenSqlChunk(part)).join("");
|
|
@@ -516,18 +555,25 @@ function generateSqliteCreateIndexSQL(table) {
|
|
|
516
555
|
}
|
|
517
556
|
return statements;
|
|
518
557
|
}
|
|
519
|
-
function
|
|
558
|
+
function isSqliteTable(value) {
|
|
559
|
+
return typeof value === "object" && value !== null && // Drizzle tables are always objects; strings are our escape hatch.
|
|
560
|
+
typeof value !== "string";
|
|
561
|
+
}
|
|
562
|
+
function generateSqliteDDL(tables3 = tables2, fulltextStrategy = fts5Strategy) {
|
|
520
563
|
const statements = [];
|
|
521
564
|
for (const table of Object.values(tables3)) {
|
|
565
|
+
if (!isSqliteTable(table)) continue;
|
|
522
566
|
statements.push(generateSqliteCreateTableSQL(table));
|
|
523
567
|
}
|
|
524
568
|
for (const table of Object.values(tables3)) {
|
|
569
|
+
if (!isSqliteTable(table)) continue;
|
|
525
570
|
statements.push(...generateSqliteCreateIndexSQL(table));
|
|
526
571
|
}
|
|
572
|
+
statements.push(...fulltextStrategy.generateDdl(tables3.fulltextTableName));
|
|
527
573
|
return statements;
|
|
528
574
|
}
|
|
529
|
-
function generateSqliteMigrationSQL(tables3 = tables2) {
|
|
530
|
-
return generateSqliteDDL(tables3).join("\n\n");
|
|
575
|
+
function generateSqliteMigrationSQL(tables3 = tables2, fulltextStrategy = fts5Strategy) {
|
|
576
|
+
return generateSqliteDDL(tables3, fulltextStrategy).join("\n\n");
|
|
531
577
|
}
|
|
532
578
|
function getPgColumnType(column) {
|
|
533
579
|
switch (column.columnType) {
|
|
@@ -608,19 +654,25 @@ function generatePgCreateIndexSQL(table) {
|
|
|
608
654
|
}
|
|
609
655
|
return statements;
|
|
610
656
|
}
|
|
611
|
-
function
|
|
657
|
+
function isPgTable(value) {
|
|
658
|
+
return typeof value === "object" && value !== null && typeof value !== "string";
|
|
659
|
+
}
|
|
660
|
+
function generatePostgresDDL(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
|
|
612
661
|
const statements = [];
|
|
613
662
|
for (const table of Object.values(tables3)) {
|
|
663
|
+
if (!isPgTable(table)) continue;
|
|
614
664
|
statements.push(generatePgCreateTableSQL(table));
|
|
615
665
|
}
|
|
616
666
|
for (const table of Object.values(tables3)) {
|
|
667
|
+
if (!isPgTable(table)) continue;
|
|
617
668
|
statements.push(...generatePgCreateIndexSQL(table));
|
|
618
669
|
}
|
|
670
|
+
statements.push(...fulltextStrategy.generateDdl(tables3.fulltextTableName));
|
|
619
671
|
return statements;
|
|
620
672
|
}
|
|
621
|
-
function generatePostgresMigrationSQL(tables3 = tables) {
|
|
673
|
+
function generatePostgresMigrationSQL(tables3 = tables, fulltextStrategy = tsvectorStrategy) {
|
|
622
674
|
const extensionSql = "-- Enable pgvector extension for vector similarity search\nCREATE EXTENSION IF NOT EXISTS vector;";
|
|
623
|
-
const ddlSql = generatePostgresDDL(tables3).join("\n\n");
|
|
675
|
+
const ddlSql = generatePostgresDDL(tables3, fulltextStrategy).join("\n\n");
|
|
624
676
|
return `${extensionSql}
|
|
625
677
|
|
|
626
678
|
${ddlSql}`;
|
|
@@ -847,6 +899,14 @@ function createCommonOperationBackend(options) {
|
|
|
847
899
|
params.id
|
|
848
900
|
);
|
|
849
901
|
await execution.execRun(deleteEmbeddingsQuery);
|
|
902
|
+
const deleteFulltextStatements = operationStrategy.buildDeleteFulltextByNode(
|
|
903
|
+
params.graphId,
|
|
904
|
+
params.kind,
|
|
905
|
+
params.id
|
|
906
|
+
);
|
|
907
|
+
for (const stmt of deleteFulltextStatements) {
|
|
908
|
+
await execution.execRun(stmt);
|
|
909
|
+
}
|
|
850
910
|
const deleteEdgesQuery = operationStrategy.buildHardDeleteEdgesByNode(
|
|
851
911
|
params.graphId,
|
|
852
912
|
params.kind,
|
|
@@ -1021,7 +1081,9 @@ function createCommonOperationBackend(options) {
|
|
|
1021
1081
|
};
|
|
1022
1082
|
}
|
|
1023
1083
|
function buildClearGraph(tables3, graphId) {
|
|
1084
|
+
const fulltext = quotedTableName(tables3.fulltextTableName);
|
|
1024
1085
|
return [
|
|
1086
|
+
sql`DELETE FROM ${fulltext} WHERE "graph_id" = ${graphId}`,
|
|
1025
1087
|
sql`DELETE FROM ${tables3.embeddings} WHERE ${tables3.embeddings.graphId} = ${graphId}`,
|
|
1026
1088
|
sql`DELETE FROM ${tables3.uniques} WHERE ${tables3.uniques.graphId} = ${graphId}`,
|
|
1027
1089
|
sql`DELETE FROM ${tables3.edges} WHERE ${tables3.edges.graphId} = ${graphId}`,
|
|
@@ -1056,12 +1118,16 @@ function buildFindNodesByKind(tables3, params) {
|
|
|
1056
1118
|
sql`${nodes3.kind} = ${params.kind}`,
|
|
1057
1119
|
...buildTemporalConditions(nodes3, params)
|
|
1058
1120
|
];
|
|
1121
|
+
if (params.orderBy === "id" && params.after !== void 0) {
|
|
1122
|
+
conditions.push(sql`${nodes3.id} > ${params.after}`);
|
|
1123
|
+
}
|
|
1059
1124
|
const whereClause = sql.join(conditions, sql` AND `);
|
|
1125
|
+
const orderByClause = params.orderBy === "id" ? sql`${nodes3.id} ASC` : sql`${nodes3.createdAt} DESC, ${nodes3.id} DESC`;
|
|
1060
1126
|
if (params.limit !== void 0 && params.offset !== void 0) {
|
|
1061
1127
|
return sql`
|
|
1062
1128
|
SELECT * FROM ${nodes3}
|
|
1063
1129
|
WHERE ${whereClause}
|
|
1064
|
-
ORDER BY ${
|
|
1130
|
+
ORDER BY ${orderByClause}
|
|
1065
1131
|
LIMIT ${params.limit} OFFSET ${params.offset}
|
|
1066
1132
|
`;
|
|
1067
1133
|
}
|
|
@@ -1069,14 +1135,14 @@ function buildFindNodesByKind(tables3, params) {
|
|
|
1069
1135
|
return sql`
|
|
1070
1136
|
SELECT * FROM ${nodes3}
|
|
1071
1137
|
WHERE ${whereClause}
|
|
1072
|
-
ORDER BY ${
|
|
1138
|
+
ORDER BY ${orderByClause}
|
|
1073
1139
|
LIMIT ${params.limit}
|
|
1074
1140
|
`;
|
|
1075
1141
|
}
|
|
1076
1142
|
return sql`
|
|
1077
1143
|
SELECT * FROM ${nodes3}
|
|
1078
1144
|
WHERE ${whereClause}
|
|
1079
|
-
ORDER BY ${
|
|
1145
|
+
ORDER BY ${orderByClause}
|
|
1080
1146
|
`;
|
|
1081
1147
|
}
|
|
1082
1148
|
function buildCountNodesByKind(tables3, params) {
|
|
@@ -1159,20 +1225,6 @@ function buildCountEdgesByKind(tables3, params) {
|
|
|
1159
1225
|
WHERE ${whereClause}
|
|
1160
1226
|
`;
|
|
1161
1227
|
}
|
|
1162
|
-
function sqlNull(value) {
|
|
1163
|
-
return value ?? sql.raw("NULL");
|
|
1164
|
-
}
|
|
1165
|
-
function quotedColumn(column) {
|
|
1166
|
-
return sql.raw(`"${column.name.replaceAll('"', '""')}"`);
|
|
1167
|
-
}
|
|
1168
|
-
function nodeColumnList(nodes3) {
|
|
1169
|
-
return sql.raw(`"${nodes3.graphId.name}", "${nodes3.kind.name}", "${nodes3.id.name}", "${nodes3.props.name}", "${nodes3.version.name}", "${nodes3.validFrom.name}", "${nodes3.validTo.name}", "${nodes3.createdAt.name}", "${nodes3.updatedAt.name}"`);
|
|
1170
|
-
}
|
|
1171
|
-
function edgeColumnList(edges3) {
|
|
1172
|
-
return sql.raw(`"${edges3.graphId.name}", "${edges3.id.name}", "${edges3.kind.name}", "${edges3.fromKind.name}", "${edges3.fromId.name}", "${edges3.toKind.name}", "${edges3.toId.name}", "${edges3.props.name}", "${edges3.validFrom.name}", "${edges3.validTo.name}", "${edges3.createdAt.name}", "${edges3.updatedAt.name}"`);
|
|
1173
|
-
}
|
|
1174
|
-
|
|
1175
|
-
// src/backend/drizzle/operations/edges.ts
|
|
1176
1228
|
function buildInsertEdge(tables3, params, timestamp2) {
|
|
1177
1229
|
const { edges: edges3 } = tables3;
|
|
1178
1230
|
const propsJson = JSON.stringify(params.props);
|
|
@@ -1364,6 +1416,60 @@ function buildFindEdgesConnectedTo(tables3, params) {
|
|
|
1364
1416
|
)
|
|
1365
1417
|
`;
|
|
1366
1418
|
}
|
|
1419
|
+
function resolveMode(mode) {
|
|
1420
|
+
return mode ?? "websearch";
|
|
1421
|
+
}
|
|
1422
|
+
function buildFulltextSearch(tableName, params, strategy) {
|
|
1423
|
+
assertValidSearchParams(params);
|
|
1424
|
+
const mode = resolveMode(params.mode);
|
|
1425
|
+
const table = quotedTableName(tableName);
|
|
1426
|
+
const matchCondition = strategy.matchCondition(
|
|
1427
|
+
tableName,
|
|
1428
|
+
params.query,
|
|
1429
|
+
mode,
|
|
1430
|
+
params.language
|
|
1431
|
+
);
|
|
1432
|
+
const rankExpression = strategy.rankExpression(
|
|
1433
|
+
tableName,
|
|
1434
|
+
params.query,
|
|
1435
|
+
mode,
|
|
1436
|
+
params.language
|
|
1437
|
+
);
|
|
1438
|
+
const conditions = [
|
|
1439
|
+
matchCondition,
|
|
1440
|
+
sql`"graph_id" = ${params.graphId}`,
|
|
1441
|
+
sql`"node_kind" = ${params.nodeKind}`
|
|
1442
|
+
];
|
|
1443
|
+
if (params.minScore !== void 0) {
|
|
1444
|
+
conditions.push(sql`${rankExpression} >= ${params.minScore}`);
|
|
1445
|
+
}
|
|
1446
|
+
const snippetExpr = params.includeSnippets === true && strategy.supportsSnippets ? strategy.snippetExpression(
|
|
1447
|
+
tableName,
|
|
1448
|
+
params.query,
|
|
1449
|
+
mode,
|
|
1450
|
+
params.language
|
|
1451
|
+
) : sql`NULL`;
|
|
1452
|
+
return sql`
|
|
1453
|
+
SELECT
|
|
1454
|
+
"node_id" AS node_id,
|
|
1455
|
+
${rankExpression} AS score,
|
|
1456
|
+
${snippetExpr} AS snippet
|
|
1457
|
+
FROM ${table}
|
|
1458
|
+
WHERE ${sql.join(conditions, sql` AND `)}
|
|
1459
|
+
ORDER BY ${rankExpression} DESC, "node_id" ASC
|
|
1460
|
+
LIMIT ${params.limit}
|
|
1461
|
+
`;
|
|
1462
|
+
}
|
|
1463
|
+
function assertValidSearchParams(params) {
|
|
1464
|
+
if (!Number.isInteger(params.limit) || params.limit <= 0) {
|
|
1465
|
+
throw new Error(`limit must be a positive integer, got: ${params.limit}`);
|
|
1466
|
+
}
|
|
1467
|
+
if (params.minScore !== void 0 && !Number.isFinite(params.minScore)) {
|
|
1468
|
+
throw new TypeError(
|
|
1469
|
+
`minScore must be a finite number, got: ${params.minScore}`
|
|
1470
|
+
);
|
|
1471
|
+
}
|
|
1472
|
+
}
|
|
1367
1473
|
function buildInsertNode(tables3, params, timestamp2) {
|
|
1368
1474
|
const { nodes: nodes3 } = tables3;
|
|
1369
1475
|
const propsJson = JSON.stringify(params.props);
|
|
@@ -1738,6 +1844,30 @@ function buildUpsertEmbeddingPostgres(tables3, params, timestamp2) {
|
|
|
1738
1844
|
${column(embeddings3.updatedAt)} = ${timestamp2}
|
|
1739
1845
|
`;
|
|
1740
1846
|
}
|
|
1847
|
+
function buildUpsertEmbeddingSqlite(tables3, params, timestamp2) {
|
|
1848
|
+
const { embeddings: embeddings3 } = tables3;
|
|
1849
|
+
const embeddingJson = JSON.stringify(params.embedding);
|
|
1850
|
+
assertFiniteNumberArray(params.embedding, "embedding");
|
|
1851
|
+
const columns = sql.raw(
|
|
1852
|
+
`"${embeddings3.graphId.name}", "${embeddings3.nodeKind.name}", "${embeddings3.nodeId.name}", "${embeddings3.fieldPath.name}", "${embeddings3.embedding.name}", "${embeddings3.dimensions.name}", "${embeddings3.createdAt.name}", "${embeddings3.updatedAt.name}"`
|
|
1853
|
+
);
|
|
1854
|
+
const conflictColumns = sql.raw(
|
|
1855
|
+
`"${embeddings3.graphId.name}", "${embeddings3.nodeKind.name}", "${embeddings3.nodeId.name}", "${embeddings3.fieldPath.name}"`
|
|
1856
|
+
);
|
|
1857
|
+
const column = (target) => sql.raw(`"${target.name}"`);
|
|
1858
|
+
return sql`
|
|
1859
|
+
INSERT INTO ${embeddings3} (${columns})
|
|
1860
|
+
VALUES (
|
|
1861
|
+
${params.graphId}, ${params.nodeKind}, ${params.nodeId}, ${params.fieldPath},
|
|
1862
|
+
vec_f32(${embeddingJson}), ${params.dimensions}, ${timestamp2}, ${timestamp2}
|
|
1863
|
+
)
|
|
1864
|
+
ON CONFLICT (${conflictColumns})
|
|
1865
|
+
DO UPDATE SET
|
|
1866
|
+
${column(embeddings3.embedding)} = vec_f32(${embeddingJson}),
|
|
1867
|
+
${column(embeddings3.dimensions)} = ${params.dimensions},
|
|
1868
|
+
${column(embeddings3.updatedAt)} = ${timestamp2}
|
|
1869
|
+
`;
|
|
1870
|
+
}
|
|
1741
1871
|
function buildDeleteEmbedding(tables3, params) {
|
|
1742
1872
|
const { embeddings: embeddings3 } = tables3;
|
|
1743
1873
|
return sql`
|
|
@@ -1901,13 +2031,27 @@ var COMMON_TABLE_OPERATION_BUILDERS = {
|
|
|
1901
2031
|
buildCheckUniqueBatch,
|
|
1902
2032
|
buildGetSchemaVersion
|
|
1903
2033
|
};
|
|
1904
|
-
function createCommonOperationStrategy(tables3, dialect) {
|
|
2034
|
+
function createCommonOperationStrategy(tables3, dialect, fulltextStrategy) {
|
|
1905
2035
|
const tableOperations = bindTableOperationBuilders(
|
|
1906
2036
|
tables3,
|
|
1907
2037
|
COMMON_TABLE_OPERATION_BUILDERS
|
|
1908
2038
|
);
|
|
2039
|
+
const fulltextTable = tables3.fulltextTableName;
|
|
2040
|
+
const fulltextBuilders = {
|
|
2041
|
+
buildUpsertFulltext: (params, timestamp2) => fulltextStrategy.buildUpsert(fulltextTable, params, timestamp2),
|
|
2042
|
+
buildDeleteFulltext: (params) => fulltextStrategy.buildDelete(fulltextTable, params),
|
|
2043
|
+
buildDeleteFulltextByNode: (graphId, nodeKind, nodeId) => fulltextStrategy.buildDelete(fulltextTable, {
|
|
2044
|
+
graphId,
|
|
2045
|
+
nodeKind,
|
|
2046
|
+
nodeId
|
|
2047
|
+
}),
|
|
2048
|
+
buildUpsertFulltextBatch: (params, timestamp2) => fulltextStrategy.buildBatchUpsert(fulltextTable, params, timestamp2),
|
|
2049
|
+
buildDeleteFulltextBatch: (params) => fulltextStrategy.buildBatchDelete(fulltextTable, params),
|
|
2050
|
+
buildFulltextSearch: (params) => buildFulltextSearch(fulltextTable, params, fulltextStrategy)
|
|
2051
|
+
};
|
|
1909
2052
|
return {
|
|
1910
2053
|
...tableOperations,
|
|
2054
|
+
...fulltextBuilders,
|
|
1911
2055
|
buildInsertUnique(params) {
|
|
1912
2056
|
return buildInsertUnique(tables3, dialect, params);
|
|
1913
2057
|
},
|
|
@@ -1925,11 +2069,28 @@ function createCommonOperationStrategy(tables3, dialect) {
|
|
|
1925
2069
|
}
|
|
1926
2070
|
};
|
|
1927
2071
|
}
|
|
1928
|
-
function createSqliteOperationStrategy(tables3) {
|
|
1929
|
-
|
|
2072
|
+
function createSqliteOperationStrategy(tables3, fulltextStrategy) {
|
|
2073
|
+
const common = createCommonOperationStrategy(
|
|
2074
|
+
tables3,
|
|
2075
|
+
"sqlite",
|
|
2076
|
+
fulltextStrategy
|
|
2077
|
+
);
|
|
2078
|
+
return {
|
|
2079
|
+
...common,
|
|
2080
|
+
buildUpsertEmbedding(params, timestamp2) {
|
|
2081
|
+
return buildUpsertEmbeddingSqlite(tables3, params, timestamp2);
|
|
2082
|
+
},
|
|
2083
|
+
buildDeleteEmbedding(params) {
|
|
2084
|
+
return buildDeleteEmbedding(tables3, params);
|
|
2085
|
+
}
|
|
2086
|
+
};
|
|
1930
2087
|
}
|
|
1931
|
-
function createPostgresOperationStrategy(tables3) {
|
|
1932
|
-
const common = createCommonOperationStrategy(
|
|
2088
|
+
function createPostgresOperationStrategy(tables3, fulltextStrategy) {
|
|
2089
|
+
const common = createCommonOperationStrategy(
|
|
2090
|
+
tables3,
|
|
2091
|
+
"postgres",
|
|
2092
|
+
fulltextStrategy
|
|
2093
|
+
);
|
|
1933
2094
|
return {
|
|
1934
2095
|
...common,
|
|
1935
2096
|
buildUpsertEmbedding(params, timestamp2) {
|
|
@@ -2133,5 +2294,5 @@ function compileQueryWithDialect(db, query, backendName) {
|
|
|
2133
2294
|
}
|
|
2134
2295
|
|
|
2135
2296
|
export { POSTGRES_CAPABILITIES, POSTGRES_ROW_MAPPER_CONFIG, SQLITE_CAPABILITIES, SQLITE_ROW_MAPPER_CONFIG, compileQueryWithDialect, createCommonOperationBackend, createEdgeRowMapper, createNodeRowMapper, createPostgresOperationStrategy, createPostgresTables, createPostgresVectorIndex, createSchemaVersionRowMapper, createSqliteOperationStrategy, createSqliteTables, createSqliteVectorIndex, createUniqueRowMapper, dropPostgresVectorIndex, dropSqliteVectorIndex, edges, edges2, embeddings, embeddings2, formatPostgresTimestamp, generatePostgresDDL, generatePostgresMigrationSQL, generateSqliteDDL, generateSqliteMigrationSQL, generateVectorIndexName, nodes, nodes2, nowIso, schemaVersions, schemaVersions2, tables, tables2, uniques, uniques2, wrapWithManagedClose };
|
|
2136
|
-
//# sourceMappingURL=chunk-
|
|
2137
|
-
//# sourceMappingURL=chunk-
|
|
2297
|
+
//# sourceMappingURL=chunk-5ZMMHUWR.js.map
|
|
2298
|
+
//# sourceMappingURL=chunk-5ZMMHUWR.js.map
|