@jefuriiij/synthra 0.2.0 → 0.2.1
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/CHANGELOG.md +16 -0
- package/dist/cli/index.js +31 -3
- package/dist/cli/index.js.map +1 -1
- package/dist/dashboard/index.js +1 -1
- package/dist/dashboard/index.js.map +1 -1
- package/dist/server/index.js +30 -2
- package/dist/server/index.js.map +1 -1
- package/package.json +1 -1
package/dist/server/index.js
CHANGED
|
@@ -2140,6 +2140,7 @@ import { appendFile as appendFile3, mkdir as mkdir7 } from "fs/promises";
|
|
|
2140
2140
|
import { dirname as dirname8 } from "path";
|
|
2141
2141
|
|
|
2142
2142
|
// src/graph/rank.ts
|
|
2143
|
+
var KW_BASE_WEIGHT = 2;
|
|
2143
2144
|
var USAGE_BOOST_CAP_DEFAULT = 4;
|
|
2144
2145
|
function usageBoostCap() {
|
|
2145
2146
|
const env = Number(process.env.SYN_LEARN_BOOST_CAP);
|
|
@@ -2229,14 +2230,41 @@ function scoreFiles(inputs) {
|
|
|
2229
2230
|
const importsFrom = indexImportEdges(inputs.graph);
|
|
2230
2231
|
const seeds = new Set(inputs.sessionKnownPaths ?? []);
|
|
2231
2232
|
for (const p of inputs.recentlyEditedPaths ?? []) seeds.add(p);
|
|
2233
|
+
const corpusSize = inputs.candidates.length;
|
|
2234
|
+
const queryDf = /* @__PURE__ */ new Map();
|
|
2235
|
+
for (const f of inputs.candidates) {
|
|
2236
|
+
for (const kw of f.keywords) {
|
|
2237
|
+
if (qTokens.has(kw)) queryDf.set(kw, (queryDf.get(kw) ?? 0) + 1);
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
const idf = (token) => {
|
|
2241
|
+
const n = queryDf.get(token) ?? 0;
|
|
2242
|
+
if (n <= 0) return 0;
|
|
2243
|
+
return Math.log(1 + (corpusSize - n + 0.5) / (n + 0.5));
|
|
2244
|
+
};
|
|
2245
|
+
let idfSum = 0;
|
|
2246
|
+
let idfCount = 0;
|
|
2247
|
+
for (const t of qTokens) {
|
|
2248
|
+
const v = idf(t);
|
|
2249
|
+
if (v > 0) {
|
|
2250
|
+
idfSum += v;
|
|
2251
|
+
idfCount += 1;
|
|
2252
|
+
}
|
|
2253
|
+
}
|
|
2254
|
+
const refIdf = idfCount > 0 ? idfSum / idfCount : 1;
|
|
2232
2255
|
const scored = [];
|
|
2233
2256
|
for (const file of inputs.candidates) {
|
|
2234
2257
|
const reasons = [];
|
|
2235
2258
|
let score2 = 0;
|
|
2236
2259
|
let kwHits = 0;
|
|
2237
|
-
|
|
2260
|
+
let kwScore = 0;
|
|
2261
|
+
for (const kw of file.keywords) {
|
|
2262
|
+
if (!qTokens.has(kw)) continue;
|
|
2263
|
+
kwHits += 1;
|
|
2264
|
+
kwScore += KW_BASE_WEIGHT * (idf(kw) / refIdf);
|
|
2265
|
+
}
|
|
2238
2266
|
if (kwHits) {
|
|
2239
|
-
score2 +=
|
|
2267
|
+
score2 += kwScore;
|
|
2240
2268
|
reasons.push(`kw=${kwHits}`);
|
|
2241
2269
|
}
|
|
2242
2270
|
const symbols = symbolsByFile.get(file.path) ?? [];
|