nodebb-plugin-search-agent 0.0.9 → 0.0.91

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/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.91",
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,12 @@ 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; ~4 chars/token → cap at 30 000 chars (~7 500 tokens)
15
+ const MAX_CHARS = 30000;
16
+
17
+ function truncate(text) {
18
+ return text.length > MAX_CHARS ? text.slice(0, MAX_CHARS) : text;
19
+ }
14
20
 
15
21
  /**
16
22
  * Performs an HTTPS POST request to the OpenAI embeddings endpoint.
@@ -95,8 +101,9 @@ async function embed(text) {
95
101
  throw new Error('OPENAI_API_KEY environment variable is not set');
96
102
  }
97
103
 
98
- winston().verbose(`[search-agent] embeddingService: generating embedding for text (${text.length} chars)`);
99
- const response = await withRetry(() => requestEmbeddings(apiKey, text));
104
+ const safe = truncate(text);
105
+ winston().verbose(`[search-agent] embeddingService: generating embedding for text (${safe.length} chars)`);
106
+ const response = await withRetry(() => requestEmbeddings(apiKey, safe));
100
107
  winston().verbose('[search-agent] embeddingService: embedding generated successfully');
101
108
  return response.data[0].embedding;
102
109
  }
@@ -122,8 +129,9 @@ async function embedBatch(texts) {
122
129
  throw new Error('OPENAI_API_KEY environment variable is not set');
123
130
  }
124
131
 
125
- winston().verbose(`[search-agent] embeddingService: generating batch embeddings for ${texts.length} text(s)`);
126
- const response = await withRetry(() => requestEmbeddings(apiKey, texts));
132
+ const safeTexts = texts.map(truncate);
133
+ winston().verbose(`[search-agent] embeddingService: generating batch embeddings for ${safeTexts.length} text(s)`);
134
+ const response = await withRetry(() => requestEmbeddings(apiKey, safeTexts));
127
135
  winston().verbose(`[search-agent] embeddingService: batch embeddings generated successfully (${texts.length} vector(s))`);
128
136
 
129
137
  // OpenAI returns items sorted by index field, but sort explicitly to be safe