Skip to content

Commit b23bbe0

Browse files
committed
fix(query): 知识库更新
- 修复切换知识库之后,检索结果没有刷新 - 修复文件上传模块 UI的边距、配色有问题
1 parent f1098f0 commit b23bbe0

File tree

4 files changed

+62
-72
lines changed

4 files changed

+62
-72
lines changed

docs/changelog/update.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,18 @@
1313

1414
🐛**BUGs**
1515
- [x] 智能体的工具切换有问题
16-
- [ ] 知识图谱可视化页面的效果有点问题
16+
- [x] 知识图谱可视化页面的效果有点问题
1717
- [x] 处理失败的文件,在特定情况下会一直处于 processing 状态,且无法删除
18-
- [ ] 与最新的 LightRAG 版本兼容性存在问题 #233
18+
- [x] 与最新的 LightRAG 版本兼容性存在问题 #233
19+
- [x] 切换知识库之后,检索结果没有刷新
20+
- [x] 文件上传模块 UI的边距、配色有问题
1921

2022
# 💯 More:
2123

2224
下面的功能会放在后续版本实现,暂时未定
2325

2426
- [ ] 封装现有工具为 mcp(stdio)调用
2527
- [ ] 支持额外 mcp 配置(代码端)
26-
- [ ] 添加用户日志与用户反馈模块,可以在 AgentView 中查看信息(🌟🌟)
27-
- [ ] 对话页面支持文档/图片临时上传(🌟🌟🌟🌟)
28+
- [ ] 添加用户日志与用户反馈模块,可以在 AgentView 中查看信息
29+
- [ ] 对话页面支持文档/图片临时上传
2830
- [ ] 优化对文档信息的检索展示(检索结果页、详情页)
29-
30-
31-
TODO1:知识库页面的文档信息的查看(检索结果页、详情页)
32-
33-
根据这个模糊的分析,判断一下这个需求应该如何实现,务必阅读所有相关的文献,包括但不限于当前代码中,保存文本片段的时候所保存的信息是否支撑功能的实现,当某些需求无法实现的时候,能否采用退而求其次的方法实现略差一些的功能(不要过度增加代码的复杂度)。
34-
35-
模糊的需求如下:先实现在 FileTable.vue, FileDetailModal.vue 中,点击文件详情按钮,能够弹出文件详情的弹窗,显示的方法有两种,一种是以现在的 chunk 的形式展示,一种是以 markdown渲染全文的形式,但是存在 overlap 拼接的问题。
36-
37-
关于全文 Markdown 的获取:目前 Milvus、Chroma 知识库里面没有存储 fulltext,需要对现有的 chunk 片段做合并,但是因为存在 overlap,所以需要想办法去除 overlap。如果有 start_idx 和 end_idx 就好办了(不一定有这两个参数)。请注意,直接读取源文件的方法是错的,因为源文件并不全是 markdown 格式,可能是 html、pdf 等结构文件,因此,只能想办法拼接,而不是尝试读取文件。项目中已经安装了 md-editor-v3 ,可以参考 AgentMessageComponent.vue 中对于 markdown 的渲染。
38-
39-
先告诉我你要如何实现这些功能,重点实现的是 milvus db 和 chroma db ,lightrag db 尽量实现,实现不了也没事。相关的上下文如下 knowledge_router.py knowledge_base.py DataBaseInfoView.vue。
40-
41-
TODO2:检索以及知识库工具调用情况下的片段展示
42-
43-
result 中可以按照 file_id 聚合信息;信息的展示以结果卡片的形式展示,卡片之间有间隔,卡片中可以选择点击查看全文或者下载原文件。下载源文件需要根据 file_id 可以从后端获取文件的基本信息,比如可下载的路径,chunks 等信息;在 @web/src/components/ToolCallingResult/KnowledgeBaseResult.vue 文件中,添加点击某个片段的时候可以弹出信息预览框(最好可以提供源文件下载的功能)这里可以复用 FileDetailModal.vue 组件。

web/src/components/FileUploadModal.vue

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,16 @@ const chunkData = async () => {
455455
456456
</script>
457457
458-
<style scoped>
458+
<style lang="less" scoped>
459459
.add-files-content {
460460
padding: 16px 0;
461461
display: flex;
462462
flex-direction: column;
463463
height: 100%;
464+
465+
.ant-form-item {
466+
margin: 0;
467+
}
464468
}
465469
466470
.upload-header {
@@ -477,20 +481,20 @@ const chunkData = async () => {
477481
478482
.upload-mode-selector {
479483
padding: 8px 16px;
480-
border: 1px solid #d9d9d9;
481-
border-radius: 4px;
484+
border: 1px solid var(--gray-300);
485+
border-radius: 6px;
482486
cursor: pointer;
483487
transition: all 0.3s;
484488
}
485489
486490
.upload-mode-selector:hover {
487-
border-color: #1890ff;
491+
border-color: var(--main-color);
488492
}
489493
490494
.upload-mode-selector.active {
491-
border-color: #1890ff;
492-
background-color: #e6f7ff;
493-
color: #1890ff;
495+
border-color: var(--main-color);
496+
background-color: var(--main-30);
497+
color: var(--main-color);
494498
}
495499
496500
.config-controls {
@@ -502,8 +506,8 @@ const chunkData = async () => {
502506
.qa-split-config {
503507
margin-bottom: 20px;
504508
padding: 16px;
505-
background-color: #fafafa;
506-
border-radius: 4px;
509+
background-color: var(--gray-50);
510+
border-radius: 6px;
507511
}
508512
509513
.toggle-controls {
@@ -513,7 +517,7 @@ const chunkData = async () => {
513517
514518
.param-description {
515519
font-size: 12px;
516-
color: #8c8c8c;
520+
color: var(--gray-600);
517521
margin-top: 4px;
518522
}
519523
@@ -531,7 +535,7 @@ const chunkData = async () => {
531535
532536
.url-hint {
533537
font-size: 12px;
534-
color: #8c8c8c;
538+
color: var(--gray-600);
535539
margin-top: 8px;
536540
}
537541

web/src/components/QuerySection.vue

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
import { ref, computed, onMounted, onUnmounted } from 'vue';
111111
import { useDatabaseStore } from '@/stores/database';
112112
import { message } from 'ant-design-vue';
113+
import { queryApi } from '@/apis/knowledge_api';
113114
import {
114115
SearchOutlined,
115116
SettingOutlined,
@@ -144,7 +145,7 @@ const meta = computed({
144145
get: () => store.meta,
145146
set: (value) => Object.assign(store.meta, value)
146147
});
147-
const queryResult = computed(() => store.queryResult);
148+
const queryResult = ref('');
148149
149150
// 查询测试
150151
const queryText = ref('');
@@ -171,12 +172,47 @@ const toggleVisible = () => {
171172
emit('toggleVisible');
172173
};
173174
174-
const onQuery = () => {
175+
const onQuery = async () => {
175176
if (!queryText.value.trim()) {
176177
message.error('请输入查询内容');
177178
return;
178179
}
179-
store.onQuery(queryText.value.trim());
180+
181+
store.state.searchLoading = true;
182+
183+
// 确保只传递当前知识库类型支持的参数
184+
const supportedParamKeys = new Set(queryParams.value.map(param => param.key));
185+
const queryMeta = {};
186+
187+
console.log('Supported param keys:', Array.from(supportedParamKeys));
188+
console.log('All meta params:', meta.value);
189+
console.log('Database info:', store.database);
190+
191+
// 遍历 meta 中的参数,只保留当前知识库类型支持的参数
192+
for (const [key, value] of Object.entries(meta.value)) {
193+
// 跳过 db_id 参数
194+
if (key === 'db_id') continue;
195+
196+
// 只保留当前知识库类型支持的参数
197+
if (supportedParamKeys.has(key)) {
198+
queryMeta[key] = value;
199+
} else {
200+
console.log(`Skipping unsupported parameter: ${key}`);
201+
}
202+
}
203+
204+
console.log('Filtered query meta:', queryMeta);
205+
206+
try {
207+
const data = await queryApi.queryTest(store.database.db_id, queryText.value.trim(), queryMeta);
208+
queryResult.value = data;
209+
} catch (error) {
210+
console.error(error);
211+
message.error(error.message);
212+
queryResult.value = '';
213+
} finally {
214+
store.state.searchLoading = false;
215+
}
180216
};
181217
182218
const useQueryExample = (example) => {

web/src/stores/database.js

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const useDatabaseStore = defineStore('database', () => {
1212
const database = ref({});
1313
const databaseId = ref(null);
1414
const selectedFile = ref(null);
15-
const queryResult = ref('');
15+
1616
const queryParams = ref([]);
1717
const meta = reactive({});
1818
const graphStats = ref({
@@ -266,43 +266,7 @@ export const useDatabaseStore = defineStore('database', () => {
266266
}
267267
}
268268

269-
async function onQuery(queryText) {
270-
state.searchLoading = true;
271-
queryResult.value = '';
272-
273-
// 确保只传递当前知识库类型支持的参数
274-
const supportedParamKeys = new Set(queryParams.value.map(param => param.key));
275-
const queryMeta = {};
276-
277-
console.log('Supported param keys:', Array.from(supportedParamKeys));
278-
console.log('All meta params:', meta);
279-
console.log('Database info:', database.value);
280-
281-
// 遍历 meta 中的参数,只保留当前知识库类型支持的参数
282-
for (const [key, value] of Object.entries(meta)) {
283-
// 跳过 db_id 参数
284-
if (key === 'db_id') continue;
285-
286-
// 只保留当前知识库类型支持的参数
287-
if (supportedParamKeys.has(key)) {
288-
queryMeta[key] = value;
289-
} else {
290-
console.log(`Skipping unsupported parameter: ${key}`);
291-
}
292-
}
293-
294-
console.log('Filtered query meta:', queryMeta);
295269

296-
try {
297-
const data = await queryApi.queryTest(database.value.db_id, queryText, queryMeta);
298-
queryResult.value = data;
299-
} catch (error) {
300-
console.error(error);
301-
message.error(error.message);
302-
} finally {
303-
state.searchLoading = false;
304-
}
305-
}
306270

307271
function startAutoRefresh() {
308272
if (state.autoRefresh && !refreshInterval) {
@@ -348,7 +312,6 @@ export const useDatabaseStore = defineStore('database', () => {
348312
database,
349313
databaseId,
350314
selectedFile,
351-
queryResult,
352315
queryParams,
353316
meta,
354317
graphStats,
@@ -363,7 +326,7 @@ export const useDatabaseStore = defineStore('database', () => {
363326
addFiles,
364327
openFileDetail,
365328
loadQueryParams,
366-
onQuery,
329+
367330
startAutoRefresh,
368331
stopAutoRefresh,
369332
toggleAutoRefresh,

0 commit comments

Comments
 (0)