nodebb-plugin-search-agent 0.0.936 → 0.0.937

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.
@@ -255,12 +255,25 @@ async function reRankWithAI(queryText, candidates, topicMap, apiKey, model, maxR
255
255
  const scores = JSON.parse(match[0]);
256
256
  const candidateByTid = Object.fromEntries(candidates.map(c => [String(c.tid), c]));
257
257
 
258
- return Object.entries(scores)
259
- .filter(([, score]) => Number(score) >= 7)
260
- .sort(([, a], [, b]) => Number(b) - Number(a))
261
- .slice(0, maxResults)
262
- .map(([tid]) => candidateByTid[tid])
263
- .filter(Boolean);
258
+ let filtered = Object.entries(scores)
259
+ .filter(([, score]) => Number(score) >= 7)
260
+ .sort(([, a], [, b]) => Number(b) - Number(a))
261
+ .slice(0, maxResults)
262
+ .map(([tid]) => candidateByTid[tid])
263
+ .filter(Boolean);
264
+
265
+ // If nothing passed the threshold, return the top scoring candidate (if any)
266
+ if (filtered.length === 0 && candidates.length > 0) {
267
+ // Find the tid with the highest score
268
+ const sortedAll = Object.entries(scores)
269
+ .sort(([, a], [, b]) => Number(b) - Number(a));
270
+ if (sortedAll.length > 0) {
271
+ const [topTid] = sortedAll[0];
272
+ const topCandidate = candidateByTid[topTid];
273
+ if (topCandidate) filtered = [topCandidate];
274
+ }
275
+ }
276
+ return filtered;
264
277
  }
265
278
 
266
279
  // ─── Public API ───────────────────────────────────────────────────────────────
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-search-agent",
3
- "version": "0.0.936",
3
+ "version": "0.0.937",
4
4
  "description": "NodeBB plugin that adds a floating chat assistant to help users find relevant forum topics using TF-IDF text similarity",
5
5
  "main": "library.js",
6
6
  "author": "Racheli Bayfus",
@@ -34,7 +34,7 @@ const RETRY_DELAY_MS = 500;
34
34
  // Hebrew/non-ASCII text tokenizes at ~1.5–2 chars/token (UTF-8 multibyte).
35
35
  // Using 1.5 chars/token worst-case: 8000 tokens × 1.5 = 12 000 chars — gives a safe margin.
36
36
 
37
- const MAX_CHARS = 12000;
37
+ const MAX_CHARS = 10000;
38
38
  const CHUNK_OVERLAP = 200; // chars to overlap between chunks for context
39
39
 
40
40
  // Split a long string into chunks of maxLen, with optional overlap