plugin-knowledge-base 1.1.1 → 1.1.2

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.
@@ -130,7 +130,7 @@ class PluginKnowledgeBaseServer extends import_server.Plugin {
130
130
  return `[Knowledge Base: ${contextItem.title || contextItem.uid}]`;
131
131
  },
132
132
  background: async (ctx, aiMessages, workContextItems) => {
133
- var _a, _b, _c, _d;
133
+ var _a, _b, _c;
134
134
  const kbIds = [...new Set(workContextItems.map((item) => item.uid).filter(Boolean))];
135
135
  if (!kbIds.length) return "";
136
136
  const userId = (_b = (_a = ctx.auth) == null ? void 0 : _a.user) == null ? void 0 : _b.id;
@@ -155,7 +155,22 @@ class PluginKnowledgeBaseServer extends import_server.Plugin {
155
155
  if (!filteredIds.length) return "";
156
156
  }
157
157
  const lastUserMsg = [...aiMessages].reverse().find((m) => m.role === "user");
158
- const queryString = typeof ((_d = lastUserMsg == null ? void 0 : lastUserMsg.content) == null ? void 0 : _d.content) === "string" ? lastUserMsg.content.content : "";
158
+ let queryString = "";
159
+ if (lastUserMsg) {
160
+ const c = lastUserMsg.content;
161
+ if (typeof c === "string") {
162
+ queryString = c;
163
+ } else if (c && typeof c === "object") {
164
+ if (typeof c.content === "string") {
165
+ queryString = c.content;
166
+ } else if (c.content && typeof c.content === "object" && typeof c.content.content === "string") {
167
+ queryString = c.content.content;
168
+ } else if (typeof c.text === "string") {
169
+ queryString = c.text;
170
+ }
171
+ }
172
+ }
173
+ plugin.app.logger.info(`[KB WorkContext] lastUserMsg content type: ${typeof (lastUserMsg == null ? void 0 : lastUserMsg.content)}, queryString length: ${queryString.length}, queryString: "${queryString.substring(0, 100)}"`);
159
174
  if (!queryString) return "";
160
175
  let knowledgeBaseGroup;
161
176
  try {
@@ -165,9 +180,13 @@ class PluginKnowledgeBaseServer extends import_server.Plugin {
165
180
  return "";
166
181
  }
167
182
  if (!(knowledgeBaseGroup == null ? void 0 : knowledgeBaseGroup.length)) return "";
183
+ plugin.app.logger.info(`[KB WorkContext] Found ${knowledgeBaseGroup.length} KB groups: ${JSON.stringify(knowledgeBaseGroup.map((g) => {
184
+ var _a2, _b2, _c2;
185
+ return { type: g.knowledgeBaseType, provider: (_a2 = g.vectorStoreConfig) == null ? void 0 : _a2.vectorStoreProvider, configId: (_b2 = g.vectorStoreConfig) == null ? void 0 : _b2.vectorStoreConfigId, kbCount: (_c2 = g.knowledgeBaseList) == null ? void 0 : _c2.length };
186
+ }))}`);
168
187
  const allDocs = [];
169
- const topK = 3;
170
- const score = "0.6";
188
+ const topK = 5;
189
+ const score = "0.3";
171
190
  for (const entry of knowledgeBaseGroup) {
172
191
  const { vectorStoreConfig, knowledgeBaseType, knowledgeBaseList } = entry;
173
192
  if (!(knowledgeBaseList == null ? void 0 : knowledgeBaseList.length)) continue;
@@ -184,6 +203,10 @@ class PluginKnowledgeBaseServer extends import_server.Plugin {
184
203
  score,
185
204
  filter: { knowledgeBaseOuterId: { in: knowledgeBaseOuterIds } }
186
205
  });
206
+ plugin.app.logger.info(`[KB WorkContext] LOCAL search: ${result.length} results, scores: ${result.map((r) => {
207
+ var _a2;
208
+ return (_a2 = r.score) == null ? void 0 : _a2.toFixed(3);
209
+ }).join(", ")}`);
187
210
  allDocs.push(...result);
188
211
  } else {
189
212
  for (const kb of knowledgeBaseList) {
@@ -192,6 +215,10 @@ class PluginKnowledgeBaseServer extends import_server.Plugin {
192
215
  kb.vectorStoreProps
193
216
  );
194
217
  const result = await vectorStoreService.search(queryString, { topK, score });
218
+ plugin.app.logger.info(`[KB WorkContext] ${knowledgeBaseType} search (${kb.name}): ${result.length} results, scores: ${result.map((r) => {
219
+ var _a2;
220
+ return (_a2 = r.score) == null ? void 0 : _a2.toFixed(3);
221
+ }).join(", ")}`);
195
222
  allDocs.push(...result);
196
223
  }
197
224
  }
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "Provides Knowledge Base management, Vector Store, Vector Database (PGVector), and RAG retrieval capabilities for AI Employees.",
7
7
  "description.vi-VN": "Cung cấp quản lý Cơ sở tri thức, Vector Store, Vector Database (PGVector), và khả năng truy xuất RAG cho nhân viên AI.",
8
8
  "description.zh-CN": "为 AI 员工提供知识库管理、向量存储、向量数据库 (PGVector) 和 RAG 检索功能。",
9
- "version": "1.1.1",
9
+ "version": "1.1.2",
10
10
  "license": "Apache-2.0",
11
11
  "main": "./dist/server/index.js",
12
12
  "files": [