plugin-knowledge-base 1.1.0 → 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.
|
@@ -76,6 +76,9 @@ class KnowledgeBaseFeatureImpl {
|
|
|
76
76
|
vectorStoreConfigId,
|
|
77
77
|
vectorStoreProps: [
|
|
78
78
|
...((_b = kbData.options) == null ? void 0 : _b.vectorStoreProps) ?? [],
|
|
79
|
+
// CRITICAL: vectorStoreConfigId must be in props — plugin-ai passes only
|
|
80
|
+
// kb.vectorStoreProps to createVectorStoreService, not the top-level field
|
|
81
|
+
{ key: "vectorStoreConfigId", value: vectorStoreConfigId },
|
|
79
82
|
// Pass accessLevel for downstream vector filtering (Fix #2)
|
|
80
83
|
{ key: "accessLevel", value: kbData.accessLevel ?? "PUBLIC" },
|
|
81
84
|
// Pass ownerId for BASIC KB per-user vector filtering
|
package/dist/server/plugin.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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,17 +180,22 @@ 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 =
|
|
170
|
-
const score = "0.
|
|
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;
|
|
174
193
|
try {
|
|
175
194
|
if (knowledgeBaseType === "LOCAL") {
|
|
195
|
+
const firstKB = knowledgeBaseList[0];
|
|
176
196
|
const vectorStoreService = await vectorStoreProvider.createVectorStoreService(
|
|
177
197
|
vectorStoreConfig.vectorStoreProvider,
|
|
178
|
-
|
|
198
|
+
firstKB.vectorStoreProps
|
|
179
199
|
);
|
|
180
200
|
const knowledgeBaseOuterIds = knowledgeBaseList.map((x) => x.knowledgeBaseOuterId);
|
|
181
201
|
const result = await vectorStoreService.search(queryString, {
|
|
@@ -183,26 +203,22 @@ class PluginKnowledgeBaseServer extends import_server.Plugin {
|
|
|
183
203
|
score,
|
|
184
204
|
filter: { knowledgeBaseOuterId: { in: knowledgeBaseOuterIds } }
|
|
185
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(", ")}`);
|
|
186
210
|
allDocs.push(...result);
|
|
187
|
-
} else
|
|
188
|
-
for (const kb of knowledgeBaseList) {
|
|
189
|
-
const vectorStoreService = await vectorStoreProvider.createVectorStoreService(
|
|
190
|
-
vectorStoreConfig.vectorStoreProvider,
|
|
191
|
-
[
|
|
192
|
-
...kb.vectorStoreProps,
|
|
193
|
-
{ key: "vectorStoreConfigId", value: vectorStoreConfig.vectorStoreConfigId }
|
|
194
|
-
]
|
|
195
|
-
);
|
|
196
|
-
const result = await vectorStoreService.search(queryString, { topK, score });
|
|
197
|
-
allDocs.push(...result);
|
|
198
|
-
}
|
|
199
|
-
} else if (knowledgeBaseType === "EXTERNAL") {
|
|
211
|
+
} else {
|
|
200
212
|
for (const kb of knowledgeBaseList) {
|
|
201
213
|
const vectorStoreService = await vectorStoreProvider.createVectorStoreService(
|
|
202
214
|
vectorStoreConfig.vectorStoreProvider,
|
|
203
215
|
kb.vectorStoreProps
|
|
204
216
|
);
|
|
205
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(", ")}`);
|
|
206
222
|
allDocs.push(...result);
|
|
207
223
|
}
|
|
208
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.
|
|
9
|
+
"version": "1.1.2",
|
|
10
10
|
"license": "Apache-2.0",
|
|
11
11
|
"main": "./dist/server/index.js",
|
|
12
12
|
"files": [
|