@palbase/backend 25.0.2 → 25.0.4
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/bin/palbase-backend.cjs +26 -10
- package/dist/bin/palbase-backend.cjs.map +1 -1
- package/dist/bin/palbase-backend.js +3 -3
- package/dist/{chunk-34I4GB7D.js → chunk-AILPKEK5.js} +12 -12
- package/dist/chunk-AILPKEK5.js.map +1 -0
- package/dist/{chunk-P2Q27SGP.js → chunk-CJSKYY76.js} +182 -2
- package/dist/chunk-CJSKYY76.js.map +1 -0
- package/dist/{chunk-XJ2RSHEU.js → chunk-CRQKCRGF.js} +16 -2
- package/dist/chunk-CRQKCRGF.js.map +1 -0
- package/dist/{chunk-7JSEN7UR.js → chunk-G4R6BTLV.js} +3 -182
- package/dist/chunk-G4R6BTLV.js.map +1 -0
- package/dist/db/index.cjs +1 -1
- package/dist/db/index.cjs.map +1 -1
- package/dist/db/index.js +2 -2
- package/dist/engine/index.cjs +26 -10
- package/dist/engine/index.cjs.map +1 -1
- package/dist/engine/index.js +3 -3
- package/dist/index.cjs +15 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +6 -6
- package/docs/README.md +20 -20
- package/docs/llms-full.txt +20 -20
- package/package.json +1 -1
- package/dist/chunk-34I4GB7D.js.map +0 -1
- package/dist/chunk-7JSEN7UR.js.map +0 -1
- package/dist/chunk-P2Q27SGP.js.map +0 -1
- package/dist/chunk-XJ2RSHEU.js.map +0 -1
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
BootRefused,
|
|
4
4
|
createApp,
|
|
5
5
|
loadConfig
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import "../chunk-
|
|
6
|
+
} from "../chunk-AILPKEK5.js";
|
|
7
|
+
import "../chunk-CRQKCRGF.js";
|
|
8
8
|
import "../chunk-XABBC7JP.js";
|
|
9
|
-
import "../chunk-
|
|
9
|
+
import "../chunk-CJSKYY76.js";
|
|
10
10
|
import {
|
|
11
11
|
getRegisteredControllers
|
|
12
12
|
} from "../chunk-35PNTIRN.js";
|
|
@@ -2,11 +2,14 @@ import {
|
|
|
2
2
|
__requestALS,
|
|
3
3
|
__runStartHooks,
|
|
4
4
|
__runWithRuntime
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-CRQKCRGF.js";
|
|
6
6
|
import {
|
|
7
7
|
assertUsableFilter,
|
|
8
8
|
assertUsableWriteValues
|
|
9
9
|
} from "./chunk-XABBC7JP.js";
|
|
10
|
+
import {
|
|
11
|
+
qualifiedTableKey
|
|
12
|
+
} from "./chunk-CJSKYY76.js";
|
|
10
13
|
import {
|
|
11
14
|
UniqueViolation,
|
|
12
15
|
assertZeroArgConstructor,
|
|
@@ -1094,7 +1097,7 @@ function createOps(tx) {
|
|
|
1094
1097
|
let exactOrderC = "";
|
|
1095
1098
|
if (userWhereC !== "") {
|
|
1096
1099
|
const probeRows = await liveC.unsafe(
|
|
1097
|
-
`SELECT count(*)::int AS n FROM (SELECT 1 FROM ${
|
|
1100
|
+
`SELECT count(*)::int AS n FROM (SELECT 1 FROM ${quoteTable(ck.table)} c${parentJoinC}c.embedding IS NOT NULL LIMIT ${SELECTIVITY_EXACT_THRESHOLD + 1}) s`,
|
|
1098
1101
|
bindC.slice()
|
|
1099
1102
|
);
|
|
1100
1103
|
const n = probeRows?.[0]?.n;
|
|
@@ -1103,7 +1106,7 @@ function createOps(tx) {
|
|
|
1103
1106
|
}
|
|
1104
1107
|
}
|
|
1105
1108
|
const vp = addC(toVectorLiteral(qvC));
|
|
1106
|
-
semC = `SELECT c.${pidQ} AS pid, c.chunk_seq, ROW_NUMBER() OVER (ORDER BY (c.embedding OPERATOR(${quoteIdent(sch)}.${op}) ${vp}::${quoteIdent(sch)}.vector)${exactOrderC}) AS r FROM ${
|
|
1109
|
+
semC = `SELECT c.${pidQ} AS pid, c.chunk_seq, ROW_NUMBER() OVER (ORDER BY (c.embedding OPERATOR(${quoteIdent(sch)}.${op}) ${vp}::${quoteIdent(sch)}.vector)${exactOrderC}) AS r FROM ${quoteTable(ck.table)} c${parentJoinC}c.embedding IS NOT NULL ORDER BY r LIMIT ${cpool}`;
|
|
1107
1110
|
}
|
|
1108
1111
|
let qpC = "";
|
|
1109
1112
|
let qpCIdx = -1;
|
|
@@ -1111,7 +1114,7 @@ function createOps(tx) {
|
|
|
1111
1114
|
const qTextC = cfg.synonyms !== void 0 ? expandSynonyms(params.query, cfg.synonyms) : params.query;
|
|
1112
1115
|
qpC = addC(qTextC);
|
|
1113
1116
|
qpCIdx = bindC.length - 1;
|
|
1114
|
-
kwC = `SELECT c.${pidQ} AS pid, c.chunk_seq, ROW_NUMBER() OVER (ORDER BY ts_rank_cd(c.palbase_fts, websearch_to_tsquery('simple', ${qpC})) DESC) AS r FROM ${
|
|
1117
|
+
kwC = `SELECT c.${pidQ} AS pid, c.chunk_seq, ROW_NUMBER() OVER (ORDER BY ts_rank_cd(c.palbase_fts, websearch_to_tsquery('simple', ${qpC})) DESC) AS r FROM ${quoteTable(ck.table)} c${parentJoinC}c.palbase_fts @@ websearch_to_tsquery('simple', ${qpC}) ORDER BY r LIMIT ${cpool}`;
|
|
1115
1118
|
}
|
|
1116
1119
|
const msC = params.minScore === void 0 ? "" : addC(params.minScore);
|
|
1117
1120
|
const colListC = cfg.cols.map((c) => `t.${quoteIdent(c)}`).join(", ");
|
|
@@ -1126,13 +1129,13 @@ function createOps(tx) {
|
|
|
1126
1129
|
} else {
|
|
1127
1130
|
fusedSrc = `WITH kw AS (${kwIn}), fused AS (SELECT kw.pid, kw.chunk_seq, (1.0/(${K2} + kw.r))::float8 AS cscore FROM kw)`;
|
|
1128
1131
|
}
|
|
1129
|
-
const inner = `${fusedSrc}, ranked AS (SELECT f.pid, f.chunk_seq, f.cscore, ROW_NUMBER() OVER (PARTITION BY f.pid ORDER BY f.cscore DESC, f.chunk_seq) AS rn FROM fused f), grouped AS (SELECT r.pid, MAX(r.cscore) AS _score, json_agg(json_build_object('content', c.content, 'score', r.cscore, 'chunkSeq', r.chunk_seq, 'charStart', c.char_start) ORDER BY r.cscore DESC, r.chunk_seq) FILTER (WHERE r.rn <= ${bpr}) AS blocks FROM ranked r JOIN ${
|
|
1132
|
+
const inner = `${fusedSrc}, ranked AS (SELECT f.pid, f.chunk_seq, f.cscore, ROW_NUMBER() OVER (PARTITION BY f.pid ORDER BY f.cscore DESC, f.chunk_seq) AS rn FROM fused f), grouped AS (SELECT r.pid, MAX(r.cscore) AS _score, json_agg(json_build_object('content', c.content, 'score', r.cscore, 'chunkSeq', r.chunk_seq, 'charStart', c.char_start) ORDER BY r.cscore DESC, r.chunk_seq) FILTER (WHERE r.rn <= ${bpr}) AS blocks FROM ranked r JOIN ${quoteTable(ck.table)} c ON c.${pidQ} = r.pid AND c.chunk_seq = r.chunk_seq GROUP BY r.pid) SELECT ${colListC}, ${scoreC}::float8 AS _score, g.blocks AS blocks${kwnCol} FROM grouped g JOIN ${quoteTable(table)} t ON t.${quoteIdent(cfg.pk)} = g.pid`;
|
|
1130
1133
|
return msC === "" ? `SELECT * FROM (${inner}) q ORDER BY q._score DESC, q.${quoteIdent(cfg.pk)} LIMIT ${limit}` : `SELECT * FROM (${inner}) q WHERE q._score >= ${msC} ORDER BY q._score DESC, q.${quoteIdent(cfg.pk)} LIMIT ${limit}`;
|
|
1131
1134
|
};
|
|
1132
1135
|
let rowsC = await liveC.unsafe(assembleC(kwC, kwC !== ""), bindC);
|
|
1133
1136
|
if (wantTextC && kwC !== "" && (rowsC.length === 0 || rowsC[0]._kwn === 0)) {
|
|
1134
1137
|
const tsch = await trgmSchemaOf(liveC);
|
|
1135
|
-
const trgmKwC = `SELECT c.${pidQ} AS pid, c.chunk_seq, ROW_NUMBER() OVER (ORDER BY ${quoteIdent(tsch)}.word_similarity(${qpC}, coalesce(c.content,'')) DESC) AS r FROM ${
|
|
1138
|
+
const trgmKwC = `SELECT c.${pidQ} AS pid, c.chunk_seq, ROW_NUMBER() OVER (ORDER BY ${quoteIdent(tsch)}.word_similarity(${qpC}, coalesce(c.content,'')) DESC) AS r FROM ${quoteTable(ck.table)} c${parentJoinC}${quoteIdent(tsch)}.word_similarity(${qpC}, coalesce(c.content,'')) > 0.3 ORDER BY r LIMIT ${cpool}`;
|
|
1136
1139
|
const retryBindC = bindC.slice();
|
|
1137
1140
|
if (qpCIdx >= 0) retryBindC[qpCIdx] = params.query;
|
|
1138
1141
|
rowsC = await liveC.unsafe(assembleC(trgmKwC, false), retryBindC);
|
|
@@ -1280,7 +1283,7 @@ function createOps(tx) {
|
|
|
1280
1283
|
if (cfg.chunk !== void 0) {
|
|
1281
1284
|
const sch = await vectorSchemaWithGuc(live);
|
|
1282
1285
|
const rows = await live.unsafe(
|
|
1283
|
-
`SELECT ${quoteIdent(sch)}.avg(c.embedding) AS v FROM ${
|
|
1286
|
+
`SELECT ${quoteIdent(sch)}.avg(c.embedding) AS v FROM ${quoteTable(cfg.chunk.table)} c WHERE c.${quoteIdent(`parent_${cfg.pk}`)} = $1 AND c.embedding IS NOT NULL`,
|
|
1284
1287
|
[id]
|
|
1285
1288
|
);
|
|
1286
1289
|
v = rows?.[0]?.v;
|
|
@@ -1347,7 +1350,7 @@ function createOps(tx) {
|
|
|
1347
1350
|
};
|
|
1348
1351
|
const avgSel = (ids) => {
|
|
1349
1352
|
const inList = ids.map((x) => add(x)).join(", ");
|
|
1350
|
-
return cfg.chunk !== void 0 ? `SELECT ${quoteIdent(sch)}.avg(c.embedding) AS v FROM ${
|
|
1353
|
+
return cfg.chunk !== void 0 ? `SELECT ${quoteIdent(sch)}.avg(c.embedding) AS v FROM ${quoteTable(cfg.chunk.table)} c WHERE c.${quoteIdent(`parent_${cfg.pk}`)} IN (${inList}) AND c.embedding IS NOT NULL` : `SELECT ${quoteIdent(sch)}.avg(t.${quoteIdent(leg.column)}) AS v FROM ${quoteTable(table)} t WHERE t.${quoteIdent(cfg.pk)} IN (${inList}) AND t.${quoteIdent(leg.column)} IS NOT NULL`;
|
|
1351
1354
|
};
|
|
1352
1355
|
const targetSql = negative.length === 0 ? `WITH pos AS (${avgSel(positive)}) SELECT pos.v AS v, (pos.v IS NULL) AS pos_missing FROM pos` : `WITH pos AS (${avgSel(positive)}), neg AS (${avgSel(negative)}) SELECT (pos.v OPERATOR(${quoteIdent(sch)}.+) (pos.v OPERATOR(${quoteIdent(sch)}.-) neg.v)) AS v, (pos.v IS NULL) AS pos_missing, (neg.v IS NULL) AS neg_missing FROM pos, neg`;
|
|
1353
1356
|
const rows = await live.unsafe(targetSql, bind);
|
|
@@ -1491,9 +1494,6 @@ function setSchema(schemas) {
|
|
|
1491
1494
|
}
|
|
1492
1495
|
currentSchema = { tables };
|
|
1493
1496
|
}
|
|
1494
|
-
function qualifiedTableKey(schema, table) {
|
|
1495
|
-
return schema === "" || schema === "public" ? table : `${schema}.${table}`;
|
|
1496
|
-
}
|
|
1497
1497
|
function withTables(ops, schema = currentSchema) {
|
|
1498
1498
|
const bind = (key) => ({
|
|
1499
1499
|
insert: (data) => ops.insert(key, data),
|
|
@@ -2465,4 +2465,4 @@ export {
|
|
|
2465
2465
|
installEgressFence,
|
|
2466
2466
|
createApp
|
|
2467
2467
|
};
|
|
2468
|
-
//# sourceMappingURL=chunk-
|
|
2468
|
+
//# sourceMappingURL=chunk-AILPKEK5.js.map
|