balibabu commited on
Commit
b1e1904
·
1 Parent(s): b9c5b85

Feat: Reparse a file shall reuse existing chunks if possible #3793 (#4021)

Browse files

### What problem does this PR solve?

Feat: Reparse a file shall reuse existing chunks if possible #3793

### Type of change


- [x] New Feature (non-breaking change which adds functionality)

web/src/hooks/document-hooks.ts CHANGED
@@ -313,13 +313,16 @@ export const useRunNextDocument = () => {
313
  mutationFn: async ({
314
  documentIds,
315
  run,
 
316
  }: {
317
  documentIds: string[];
318
  run: number;
 
319
  }) => {
320
  const ret = await kbService.document_run({
321
  doc_ids: documentIds,
322
  run,
 
323
  });
324
  const code = get(ret, 'data.code');
325
  if (code === 0) {
 
313
  mutationFn: async ({
314
  documentIds,
315
  run,
316
+ shouldDelete,
317
  }: {
318
  documentIds: string[];
319
  run: number;
320
+ shouldDelete: boolean;
321
  }) => {
322
  const ret = await kbService.document_run({
323
  doc_ids: documentIds,
324
  run,
325
+ delete: shouldDelete,
326
  });
327
  const code = get(ret, 'data.code');
328
  if (code === 0) {
web/src/locales/en.ts CHANGED
@@ -165,6 +165,7 @@ export default {
165
  autoKeywordsTip: `Automatically extract N keywords for each chunk to increase their ranking for queries containing those keywords. You can check or update the added keywords for a chunk from the chunk list. Be aware that extra tokens will be consumed by the LLM specified in 'System model settings'.`,
166
  autoQuestions: 'Auto-question',
167
  autoQuestionsTip: `Automatically extract N questions for each chunk to increase their ranking for queries containing those questions. You can check or update the added questions for a chunk from the chunk list. This feature will not disrupt the chunking process if an error occurs, except that it may add an empty result to the original chunk. Be aware that extra tokens will be consumed by the LLM specified in 'System model settings'.`,
 
168
  },
169
  knowledgeConfiguration: {
170
  titleDescription:
 
165
  autoKeywordsTip: `Automatically extract N keywords for each chunk to increase their ranking for queries containing those keywords. You can check or update the added keywords for a chunk from the chunk list. Be aware that extra tokens will be consumed by the LLM specified in 'System model settings'.`,
166
  autoQuestions: 'Auto-question',
167
  autoQuestionsTip: `Automatically extract N questions for each chunk to increase their ranking for queries containing those questions. You can check or update the added questions for a chunk from the chunk list. This feature will not disrupt the chunking process if an error occurs, except that it may add an empty result to the original chunk. Be aware that extra tokens will be consumed by the LLM specified in 'System model settings'.`,
168
+ redo: 'Do you want to clear the existing {{chunkNum}} chunks?',
169
  },
170
  knowledgeConfiguration: {
171
  titleDescription:
web/src/locales/zh-traditional.ts CHANGED
@@ -161,6 +161,7 @@ export default {
161
  autoKeywordsTip: `在查詢此類關鍵字時,為每個區塊提取 N 個關鍵字以提高其排名分數。在「系統模型設定」中設定的 LLM 將消耗額外的 token。您可以在區塊清單中查看結果。 `,
162
  autoQuestions: '自動問題',
163
  autoQuestionsTip: `在查詢此類問題時,為每個區塊提取 N 個問題以提高其排名分數。在「系統模型設定」中設定的 LLM 將消耗額外的 token。您可以在區塊清單中查看結果。如果發生錯誤,此功能不會破壞整個分塊過程,除了將空結果新增至原始區塊。 `,
 
164
  },
165
  knowledgeConfiguration: {
166
  titleDescription: '在這裡更新您的知識庫詳細信息,尤其是解析方法。',
 
161
  autoKeywordsTip: `在查詢此類關鍵字時,為每個區塊提取 N 個關鍵字以提高其排名分數。在「系統模型設定」中設定的 LLM 將消耗額外的 token。您可以在區塊清單中查看結果。 `,
162
  autoQuestions: '自動問題',
163
  autoQuestionsTip: `在查詢此類問題時,為每個區塊提取 N 個問題以提高其排名分數。在「系統模型設定」中設定的 LLM 將消耗額外的 token。您可以在區塊清單中查看結果。如果發生錯誤,此功能不會破壞整個分塊過程,除了將空結果新增至原始區塊。 `,
164
+ redo: '是否清空已有 {{chunkNum}}個 chunk?',
165
  },
166
  knowledgeConfiguration: {
167
  titleDescription: '在這裡更新您的知識庫詳細信息,尤其是解析方法。',
web/src/locales/zh.ts CHANGED
@@ -162,6 +162,7 @@ export default {
162
  autoKeywordsTip: `在查询此类关键词时,为每个块提取 N 个关键词以提高其排名得分。在“系统模型设置”中设置的 LLM 将消耗额外的 token。您可以在块列表中查看结果。`,
163
  autoQuestions: '自动问题',
164
  autoQuestionsTip: `在查询此类问题时,为每个块提取 N 个问题以提高其排名得分。在“系统模型设置”中设置的 LLM 将消耗额外的 token。您可以在块列表中查看结果。如果发生错误,此功能不会破坏整个分块过程,除了将空结果添加到原始块。`,
 
165
  },
166
  knowledgeConfiguration: {
167
  titleDescription: '在这里更新您的知识库详细信息,尤其是解析方法。',
 
162
  autoKeywordsTip: `在查询此类关键词时,为每个块提取 N 个关键词以提高其排名得分。在“系统模型设置”中设置的 LLM 将消耗额外的 token。您可以在块列表中查看结果。`,
163
  autoQuestions: '自动问题',
164
  autoQuestionsTip: `在查询此类问题时,为每个块提取 N 个问题以提高其排名得分。在“系统模型设置”中设置的 LLM 将消耗额外的 token。您可以在块列表中查看结果。如果发生错误,此功能不会破坏整个分块过程,除了将空结果添加到原始块。`,
165
+ redo: '是否清空已有 {{chunkNum}}个 chunk?',
166
  },
167
  knowledgeConfiguration: {
168
  titleDescription: '在这里更新您的知识库详细信息,尤其是解析方法。',
web/src/pages/add-knowledge/components/knowledge-file/hooks.ts CHANGED
@@ -213,6 +213,7 @@ export const useHandleRunDocumentByIds = (id: string) => {
213
  const handleRunDocumentByIds = async (
214
  documentId: string,
215
  isRunning: boolean,
 
216
  ) => {
217
  if (isLoading) {
218
  return;
@@ -222,6 +223,7 @@ export const useHandleRunDocumentByIds = (id: string) => {
222
  await runDocumentByIds({
223
  documentIds: [documentId],
224
  run: isRunning ? 2 : 1,
 
225
  });
226
  setCurrentId('');
227
  } catch (error) {
 
213
  const handleRunDocumentByIds = async (
214
  documentId: string,
215
  isRunning: boolean,
216
+ shouldDelete: boolean = false,
217
  ) => {
218
  if (isLoading) {
219
  return;
 
223
  await runDocumentByIds({
224
  documentIds: [documentId],
225
  run: isRunning ? 2 : 1,
226
+ shouldDelete,
227
  });
228
  setCurrentId('');
229
  } catch (error) {
web/src/pages/add-knowledge/components/knowledge-file/parsing-status-cell/index.tsx CHANGED
@@ -3,7 +3,15 @@ import { ReactComponent as RefreshIcon } from '@/assets/svg/refresh.svg';
3
  import { ReactComponent as RunIcon } from '@/assets/svg/run.svg';
4
  import { useTranslate } from '@/hooks/common-hooks';
5
  import { IDocumentInfo } from '@/interfaces/database/document';
6
- import { Badge, DescriptionsProps, Flex, Popover, Space, Tag } from 'antd';
 
 
 
 
 
 
 
 
7
  import classNames from 'classnames';
8
  import { useTranslation } from 'react-i18next';
9
  import reactStringReplace from 'react-string-replace';
@@ -92,9 +100,11 @@ export const ParsingStatusCell = ({ record }: IProps) => {
92
 
93
  const label = t(`knowledgeDetails.runningStatus${text}`);
94
 
95
- const handleOperationIconClick = () => {
96
- handleRunDocumentByIds(record.id, isRunning);
97
- };
 
 
98
 
99
  return record.type === DocumentType.Virtual ? null : (
100
  <Flex justify={'space-between'} align="center">
@@ -111,14 +121,25 @@ export const ParsingStatusCell = ({ record }: IProps) => {
111
  )}
112
  </Tag>
113
  </Popover>
114
- <div
115
- onClick={handleOperationIconClick}
116
- className={classNames(styles.operationIcon, {
117
- [styles.operationIconSpin]: loading,
118
- })}
 
 
119
  >
120
- <OperationIcon />
121
- </div>
 
 
 
 
 
 
 
 
 
122
  </Flex>
123
  );
124
  };
 
3
  import { ReactComponent as RunIcon } from '@/assets/svg/run.svg';
4
  import { useTranslate } from '@/hooks/common-hooks';
5
  import { IDocumentInfo } from '@/interfaces/database/document';
6
+ import {
7
+ Badge,
8
+ DescriptionsProps,
9
+ Flex,
10
+ Popconfirm,
11
+ Popover,
12
+ Space,
13
+ Tag,
14
+ } from 'antd';
15
  import classNames from 'classnames';
16
  import { useTranslation } from 'react-i18next';
17
  import reactStringReplace from 'react-string-replace';
 
100
 
101
  const label = t(`knowledgeDetails.runningStatus${text}`);
102
 
103
+ const handleOperationIconClick =
104
+ (shouldDelete: boolean = false) =>
105
+ () => {
106
+ handleRunDocumentByIds(record.id, isRunning, shouldDelete);
107
+ };
108
 
109
  return record.type === DocumentType.Virtual ? null : (
110
  <Flex justify={'space-between'} align="center">
 
121
  )}
122
  </Tag>
123
  </Popover>
124
+ <Popconfirm
125
+ title={t(`knowledgeDetails.redo`, { chunkNum: record.chunk_num })}
126
+ onConfirm={handleOperationIconClick(true)}
127
+ onCancel={handleOperationIconClick(false)}
128
+ disabled={record.chunk_num === 0}
129
+ okText={t('common.ok')}
130
+ cancelText={t('common.cancel')}
131
  >
132
+ <div
133
+ className={classNames(styles.operationIcon, {
134
+ [styles.operationIconSpin]: loading,
135
+ })}
136
+ onClick={
137
+ record.chunk_num === 0 ? handleOperationIconClick(false) : () => {}
138
+ }
139
+ >
140
+ <OperationIcon />
141
+ </div>
142
+ </Popconfirm>
143
  </Flex>
144
  );
145
  };