nodebb-plugin-search-agent 0.0.9 → 0.0.92

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.
@@ -188,6 +188,8 @@ async function reRankWithAI(queryText, candidates, topicMap, apiKey, model, maxR
188
188
  { role: 'user', content: userMessage },
189
189
  ]);
190
190
 
191
+ console.log('AI scoring response:', response.choices[0].message.content);
192
+
191
193
  const content = (response.choices[0].message.content || '').trim();
192
194
 
193
195
  // Extract the JSON object from the response
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-search-agent",
3
- "version": "0.0.9",
3
+ "version": "0.0.92",
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",
@@ -11,6 +11,14 @@ const OPENAI_EMBEDDINGS_PATH = '/v1/embeddings';
11
11
  const EMBEDDING_MODEL = 'text-embedding-3-small';
12
12
  const MAX_RETRIES = 3;
13
13
  const RETRY_DELAY_MS = 500;
14
+ // text-embedding-3-small supports 8 192 tokens.
15
+ // Hebrew/non-ASCII text tokenizes at ~1.5–2 chars/token (UTF-8 multibyte).
16
+ // Using 1.5 chars/token worst-case: 8000 tokens × 1.5 = 12 000 chars — gives a safe margin.
17
+ const MAX_CHARS = 12000;
18
+
19
+ function truncate(text) {
20
+ return text.length > MAX_CHARS ? text.slice(0, MAX_CHARS) : text;
21
+ }
14
22
 
15
23
  /**
16
24
  * Performs an HTTPS POST request to the OpenAI embeddings endpoint.
@@ -95,8 +103,9 @@ async function embed(text) {
95
103
  throw new Error('OPENAI_API_KEY environment variable is not set');
96
104
  }
97
105
 
98
- winston().verbose(`[search-agent] embeddingService: generating embedding for text (${text.length} chars)`);
99
- const response = await withRetry(() => requestEmbeddings(apiKey, text));
106
+ const safe = truncate(text);
107
+ winston().verbose(`[search-agent] embeddingService: generating embedding for text (${safe.length} chars)`);
108
+ const response = await withRetry(() => requestEmbeddings(apiKey, safe));
100
109
  winston().verbose('[search-agent] embeddingService: embedding generated successfully');
101
110
  return response.data[0].embedding;
102
111
  }
@@ -122,8 +131,9 @@ async function embedBatch(texts) {
122
131
  throw new Error('OPENAI_API_KEY environment variable is not set');
123
132
  }
124
133
 
125
- winston().verbose(`[search-agent] embeddingService: generating batch embeddings for ${texts.length} text(s)`);
126
- const response = await withRetry(() => requestEmbeddings(apiKey, texts));
134
+ const safeTexts = texts.map(truncate);
135
+ winston().verbose(`[search-agent] embeddingService: generating batch embeddings for ${safeTexts.length} text(s)`);
136
+ const response = await withRetry(() => requestEmbeddings(apiKey, safeTexts));
127
137
  winston().verbose(`[search-agent] embeddingService: batch embeddings generated successfully (${texts.length} vector(s))`);
128
138
 
129
139
  // OpenAI returns items sorted by index field, but sort explicitly to be safe