balibabu
commited on
Commit
·
51db3f9
1
Parent(s):
47ec63e
Feat: Display the knowledge graph on the knowledge base page #4543 (#4587)
Browse files### What problem does this PR solve?
Feat: Display the knowledge graph on the knowledge base page #4543
### Type of change
- [x] New Feature (non-breaking change which adds functionality)
- web/src/components/chunk-method-modal/index.tsx +4 -0
- web/src/components/entity-types-item.tsx +10 -4
- web/src/components/indented-tree/modal.tsx +4 -5
- web/src/components/layout-recognize.tsx +22 -4
- web/src/components/parse-configuration/graph-rag-items.tsx +120 -0
- web/src/components/use-knowledge-graph-item.tsx +21 -0
- web/src/constants/knowledge.ts +1 -0
- web/src/hooks/chunk-hooks.ts +0 -20
- web/src/hooks/common-hooks.tsx +4 -3
- web/src/hooks/knowledge-hooks.ts +19 -0
- web/src/interfaces/database/document.ts +9 -0
- web/src/interfaces/database/knowledge.ts +6 -0
- web/src/locales/en.ts +20 -3
- web/src/locales/zh-traditional.ts +19 -1
- web/src/locales/zh.ts +19 -2
- web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/modal.tsx +0 -75
- web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx +0 -2
- web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx +6 -1
- web/src/pages/add-knowledge/components/{knowledge-chunk/components/knowledge-graph → knowledge-graph}/constant.ts +0 -0
- web/src/pages/add-knowledge/components/{knowledge-chunk/components/knowledge-graph → knowledge-graph}/force-graph.tsx +3 -3
- web/src/pages/add-knowledge/components/{knowledge-chunk/components/knowledge-graph → knowledge-graph}/index.less +0 -5
- web/src/pages/add-knowledge/components/knowledge-graph/index.tsx +15 -0
- web/src/pages/add-knowledge/components/{knowledge-chunk/components/knowledge-graph → knowledge-graph}/util.ts +0 -0
- web/src/pages/add-knowledge/components/knowledge-setting/configuration.tsx +5 -0
- web/src/pages/add-knowledge/components/knowledge-sidebar/index.tsx +22 -4
- web/src/pages/add-knowledge/components/knowledge-testing/testing-control/index.tsx +2 -0
- web/src/pages/chat/chat-configuration-modal/prompt-engine.tsx +4 -0
- web/src/pages/knowledge/knowledge-card/index.tsx +1 -1
- web/src/routes.ts +4 -0
- web/src/services/knowledge-service.ts +4 -0
- web/src/utils/api.ts +2 -0
web/src/components/chunk-method-modal/index.tsx
CHANGED
@@ -30,6 +30,9 @@ import LayoutRecognize from '../layout-recognize';
|
|
30 |
import ParseConfiguration, {
|
31 |
showRaptorParseConfiguration,
|
32 |
} from '../parse-configuration';
|
|
|
|
|
|
|
33 |
import styles from './index.less';
|
34 |
|
35 |
interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
|
@@ -296,6 +299,7 @@ const ChunkMethodModal: React.FC<IProps> = ({
|
|
296 |
{showRaptorParseConfiguration(selectedTag) && (
|
297 |
<ParseConfiguration></ParseConfiguration>
|
298 |
)}
|
|
|
299 |
{showEntityTypes && <EntityTypesItem></EntityTypesItem>}
|
300 |
</Form>
|
301 |
</Modal>
|
|
|
30 |
import ParseConfiguration, {
|
31 |
showRaptorParseConfiguration,
|
32 |
} from '../parse-configuration';
|
33 |
+
import GraphRagItems, {
|
34 |
+
showGraphRagItems,
|
35 |
+
} from '../parse-configuration/graph-rag-items';
|
36 |
import styles from './index.less';
|
37 |
|
38 |
interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
|
|
|
299 |
{showRaptorParseConfiguration(selectedTag) && (
|
300 |
<ParseConfiguration></ParseConfiguration>
|
301 |
)}
|
302 |
+
{showGraphRagItems(selectedTag) && <GraphRagItems></GraphRagItems>}
|
303 |
{showEntityTypes && <EntityTypesItem></EntityTypesItem>}
|
304 |
</Form>
|
305 |
</Modal>
|
web/src/components/entity-types-item.tsx
CHANGED
@@ -5,16 +5,22 @@ import EditTag from './edit-tag';
|
|
5 |
const initialEntityTypes = [
|
6 |
'organization',
|
7 |
'person',
|
8 |
-
'
|
9 |
'event',
|
10 |
-
'
|
11 |
];
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
const { t } = useTranslate('knowledgeConfiguration');
|
15 |
return (
|
16 |
<Form.Item
|
17 |
-
name={
|
18 |
label={t('entityTypes')}
|
19 |
rules={[{ required: true }]}
|
20 |
initialValue={initialEntityTypes}
|
|
|
5 |
const initialEntityTypes = [
|
6 |
'organization',
|
7 |
'person',
|
8 |
+
'geo',
|
9 |
'event',
|
10 |
+
'category',
|
11 |
];
|
12 |
|
13 |
+
type IProps = {
|
14 |
+
field?: string[];
|
15 |
+
};
|
16 |
+
|
17 |
+
const EntityTypesItem = ({
|
18 |
+
field = ['parser_config', 'entity_types'],
|
19 |
+
}: IProps) => {
|
20 |
const { t } = useTranslate('knowledgeConfiguration');
|
21 |
return (
|
22 |
<Form.Item
|
23 |
+
name={field}
|
24 |
label={t('entityTypes')}
|
25 |
rules={[{ required: true }]}
|
26 |
initialValue={initialEntityTypes}
|
web/src/components/indented-tree/modal.tsx
CHANGED
@@ -1,16 +1,15 @@
|
|
1 |
-
import { useFetchKnowledgeGraph } from '@/hooks/chunk-hooks';
|
2 |
-
import { Modal } from 'antd';
|
3 |
import { useTranslation } from 'react-i18next';
|
4 |
import IndentedTree from './indented-tree';
|
5 |
|
|
|
6 |
import { IModalProps } from '@/interfaces/common';
|
|
|
7 |
|
8 |
const IndentedTreeModal = ({
|
9 |
-
documentId,
|
10 |
visible,
|
11 |
hideModal,
|
12 |
}: IModalProps<any> & { documentId: string }) => {
|
13 |
-
const { data } = useFetchKnowledgeGraph(
|
14 |
const { t } = useTranslation();
|
15 |
|
16 |
return (
|
@@ -22,7 +21,7 @@ const IndentedTreeModal = ({
|
|
22 |
footer={null}
|
23 |
>
|
24 |
<section>
|
25 |
-
<IndentedTree data={data?.
|
26 |
</section>
|
27 |
</Modal>
|
28 |
);
|
|
|
|
|
|
|
1 |
import { useTranslation } from 'react-i18next';
|
2 |
import IndentedTree from './indented-tree';
|
3 |
|
4 |
+
import { useFetchKnowledgeGraph } from '@/hooks/knowledge-hooks';
|
5 |
import { IModalProps } from '@/interfaces/common';
|
6 |
+
import { Modal } from 'antd';
|
7 |
|
8 |
const IndentedTreeModal = ({
|
|
|
9 |
visible,
|
10 |
hideModal,
|
11 |
}: IModalProps<any> & { documentId: string }) => {
|
12 |
+
const { data } = useFetchKnowledgeGraph();
|
13 |
const { t } = useTranslation();
|
14 |
|
15 |
return (
|
|
|
21 |
footer={null}
|
22 |
>
|
23 |
<section>
|
24 |
+
<IndentedTree data={data?.mind_map} show></IndentedTree>
|
25 |
</section>
|
26 |
</Modal>
|
27 |
);
|
web/src/components/layout-recognize.tsx
CHANGED
@@ -1,17 +1,35 @@
|
|
|
|
1 |
import { useTranslate } from '@/hooks/common-hooks';
|
2 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
const LayoutRecognize = () => {
|
5 |
const { t } = useTranslate('knowledgeDetails');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
return (
|
7 |
<Form.Item
|
8 |
name={['parser_config', 'layout_recognize']}
|
9 |
label={t('layoutRecognize')}
|
10 |
-
initialValue={
|
11 |
-
valuePropName="checked"
|
12 |
tooltip={t('layoutRecognizeTip')}
|
13 |
>
|
14 |
-
<
|
15 |
</Form.Item>
|
16 |
);
|
17 |
};
|
|
|
1 |
+
import { LlmModelType } from '@/constants/knowledge';
|
2 |
import { useTranslate } from '@/hooks/common-hooks';
|
3 |
+
import { useSelectLlmOptionsByModelType } from '@/hooks/llm-hooks';
|
4 |
+
import { Form, Select } from 'antd';
|
5 |
+
import { useMemo } from 'react';
|
6 |
+
|
7 |
+
const enum DocumentType {
|
8 |
+
DeepDOC = 'DeepDOC',
|
9 |
+
PlainText = 'Plain Text',
|
10 |
+
}
|
11 |
|
12 |
const LayoutRecognize = () => {
|
13 |
const { t } = useTranslate('knowledgeDetails');
|
14 |
+
const allOptions = useSelectLlmOptionsByModelType();
|
15 |
+
|
16 |
+
const options = useMemo(() => {
|
17 |
+
const list = [DocumentType.DeepDOC, DocumentType.PlainText].map((x) => ({
|
18 |
+
label: x,
|
19 |
+
value: x,
|
20 |
+
}));
|
21 |
+
|
22 |
+
return [...list, ...allOptions[LlmModelType.Image2text]];
|
23 |
+
}, [allOptions]);
|
24 |
+
|
25 |
return (
|
26 |
<Form.Item
|
27 |
name={['parser_config', 'layout_recognize']}
|
28 |
label={t('layoutRecognize')}
|
29 |
+
initialValue={DocumentType.DeepDOC}
|
|
|
30 |
tooltip={t('layoutRecognizeTip')}
|
31 |
>
|
32 |
+
<Select options={options} />
|
33 |
</Form.Item>
|
34 |
);
|
35 |
};
|
web/src/components/parse-configuration/graph-rag-items.tsx
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useTranslate } from '@/hooks/common-hooks';
|
2 |
+
import { Divider, Form, Select, Switch } from 'antd';
|
3 |
+
import { upperFirst } from 'lodash';
|
4 |
+
import { useCallback, useMemo } from 'react';
|
5 |
+
import EntityTypesItem from '../entity-types-item';
|
6 |
+
|
7 |
+
const excludedTagParseMethods = ['table', 'knowledge_graph', 'tag'];
|
8 |
+
|
9 |
+
export const showTagItems = (parserId: string) => {
|
10 |
+
return !excludedTagParseMethods.includes(parserId);
|
11 |
+
};
|
12 |
+
|
13 |
+
const enum MethodValue {
|
14 |
+
General = 'general',
|
15 |
+
Light = 'light',
|
16 |
+
}
|
17 |
+
|
18 |
+
export const excludedParseMethods = [
|
19 |
+
'table',
|
20 |
+
'resume',
|
21 |
+
'picture',
|
22 |
+
'knowledge_graph',
|
23 |
+
'qa',
|
24 |
+
'tag',
|
25 |
+
];
|
26 |
+
|
27 |
+
export const showGraphRagItems = (parserId: string) => {
|
28 |
+
return !excludedParseMethods.includes(parserId);
|
29 |
+
};
|
30 |
+
|
31 |
+
// The three types "table", "resume" and "one" do not display this configuration.
|
32 |
+
const GraphRagItems = () => {
|
33 |
+
const { t } = useTranslate('knowledgeConfiguration');
|
34 |
+
|
35 |
+
const methodOptions = useMemo(() => {
|
36 |
+
return [MethodValue.Light, MethodValue.General].map((x) => ({
|
37 |
+
value: x,
|
38 |
+
label: upperFirst(x),
|
39 |
+
}));
|
40 |
+
}, []);
|
41 |
+
|
42 |
+
const renderWideTooltip = useCallback(
|
43 |
+
(title: React.ReactNode | string) => {
|
44 |
+
return {
|
45 |
+
title: typeof title === 'string' ? t(title) : title,
|
46 |
+
overlayInnerStyle: { width: '50vw' },
|
47 |
+
};
|
48 |
+
},
|
49 |
+
[t],
|
50 |
+
);
|
51 |
+
|
52 |
+
return (
|
53 |
+
<>
|
54 |
+
<Divider></Divider>
|
55 |
+
<Form.Item
|
56 |
+
name={['parser_config', 'graphrag', 'use_graphrag']}
|
57 |
+
label={t('useGraphRag')}
|
58 |
+
initialValue={false}
|
59 |
+
valuePropName="checked"
|
60 |
+
tooltip={renderWideTooltip('useGraphRagTip')}
|
61 |
+
>
|
62 |
+
<Switch />
|
63 |
+
</Form.Item>
|
64 |
+
<Form.Item
|
65 |
+
shouldUpdate={(prevValues, curValues) =>
|
66 |
+
prevValues.parser_config.graphrag.use_graphrag !==
|
67 |
+
curValues.parser_config.graphrag.use_graphrag
|
68 |
+
}
|
69 |
+
>
|
70 |
+
{({ getFieldValue }) => {
|
71 |
+
const useRaptor = getFieldValue([
|
72 |
+
'parser_config',
|
73 |
+
'graphrag',
|
74 |
+
'use_graphrag',
|
75 |
+
]);
|
76 |
+
|
77 |
+
return (
|
78 |
+
useRaptor && (
|
79 |
+
<>
|
80 |
+
<EntityTypesItem
|
81 |
+
field={['parser_config', 'graphrag', 'entity_types']}
|
82 |
+
></EntityTypesItem>
|
83 |
+
<Form.Item
|
84 |
+
name={['parser_config', 'graphrag', 'method']}
|
85 |
+
label={t('graphRagMethod')}
|
86 |
+
tooltip={renderWideTooltip(
|
87 |
+
<div
|
88 |
+
dangerouslySetInnerHTML={{
|
89 |
+
__html: t('graphRagMethodTip'),
|
90 |
+
}}
|
91 |
+
></div>,
|
92 |
+
)}
|
93 |
+
initialValue={MethodValue.Light}
|
94 |
+
>
|
95 |
+
<Select options={methodOptions} />
|
96 |
+
</Form.Item>
|
97 |
+
<Form.Item
|
98 |
+
name={['parser_config', 'graphrag', 'resolution']}
|
99 |
+
label={t('resolution')}
|
100 |
+
tooltip={renderWideTooltip('resolutionTip')}
|
101 |
+
>
|
102 |
+
<Switch />
|
103 |
+
</Form.Item>
|
104 |
+
<Form.Item
|
105 |
+
name={['parser_config', 'graphrag', 'community']}
|
106 |
+
label={t('community')}
|
107 |
+
tooltip={renderWideTooltip('communityTip')}
|
108 |
+
>
|
109 |
+
<Switch />
|
110 |
+
</Form.Item>
|
111 |
+
</>
|
112 |
+
)
|
113 |
+
);
|
114 |
+
}}
|
115 |
+
</Form.Item>
|
116 |
+
</>
|
117 |
+
);
|
118 |
+
};
|
119 |
+
|
120 |
+
export default GraphRagItems;
|
web/src/components/use-knowledge-graph-item.tsx
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { Form, Switch } from 'antd';
|
2 |
+
import { useTranslation } from 'react-i18next';
|
3 |
+
|
4 |
+
type IProps = {
|
5 |
+
filedName: string[];
|
6 |
+
};
|
7 |
+
|
8 |
+
export function UseKnowledgeGraphItem({ filedName }: IProps) {
|
9 |
+
const { t } = useTranslation();
|
10 |
+
|
11 |
+
return (
|
12 |
+
<Form.Item
|
13 |
+
label={t('chat.useKnowledgeGraph')}
|
14 |
+
tooltip={t('chat.useKnowledgeGraphTip')}
|
15 |
+
name={filedName}
|
16 |
+
initialValue={false}
|
17 |
+
>
|
18 |
+
<Switch></Switch>
|
19 |
+
</Form.Item>
|
20 |
+
);
|
21 |
+
}
|
web/src/constants/knowledge.ts
CHANGED
@@ -2,6 +2,7 @@ export enum KnowledgeRouteKey {
|
|
2 |
Dataset = 'dataset',
|
3 |
Testing = 'testing',
|
4 |
Configuration = 'configuration',
|
|
|
5 |
}
|
6 |
|
7 |
export const DatasetBaseKey = 'dataset';
|
|
|
2 |
Dataset = 'dataset',
|
3 |
Testing = 'testing',
|
4 |
Configuration = 'configuration',
|
5 |
+
KnowledgeGraph = 'knowledgeGraph',
|
6 |
}
|
7 |
|
8 |
export const DatasetBaseKey = 'dataset';
|
web/src/hooks/chunk-hooks.ts
CHANGED
@@ -206,23 +206,3 @@ export const useFetchChunk = (chunkId?: string): ResponseType<any> => {
|
|
206 |
|
207 |
return data;
|
208 |
};
|
209 |
-
|
210 |
-
export const useFetchKnowledgeGraph = (
|
211 |
-
documentId: string,
|
212 |
-
): ResponseType<any> => {
|
213 |
-
const { data } = useQuery({
|
214 |
-
queryKey: ['fetchKnowledgeGraph', documentId],
|
215 |
-
initialData: true,
|
216 |
-
enabled: !!documentId,
|
217 |
-
gcTime: 0,
|
218 |
-
queryFn: async () => {
|
219 |
-
const data = await kbService.knowledge_graph({
|
220 |
-
doc_id: documentId,
|
221 |
-
});
|
222 |
-
|
223 |
-
return data;
|
224 |
-
},
|
225 |
-
});
|
226 |
-
|
227 |
-
return data;
|
228 |
-
};
|
|
|
206 |
|
207 |
return data;
|
208 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/hooks/common-hooks.tsx
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
import { ExclamationCircleFilled } from '@ant-design/icons';
|
2 |
import { App } from 'antd';
|
3 |
import isEqual from 'lodash/isEqual';
|
4 |
-
import { useCallback, useEffect, useRef, useState } from 'react';
|
5 |
import { useTranslation } from 'react-i18next';
|
6 |
|
7 |
export const useSetModalState = () => {
|
@@ -78,6 +78,7 @@ export function useDynamicSVGImport(
|
|
78 |
|
79 |
interface IProps {
|
80 |
title?: string;
|
|
|
81 |
onOk?: (...args: any[]) => any;
|
82 |
onCancel?: (...args: any[]) => any;
|
83 |
}
|
@@ -87,12 +88,12 @@ export const useShowDeleteConfirm = () => {
|
|
87 |
const { t } = useTranslation();
|
88 |
|
89 |
const showDeleteConfirm = useCallback(
|
90 |
-
({ title, onOk, onCancel }: IProps): Promise<number> => {
|
91 |
return new Promise((resolve, reject) => {
|
92 |
modal.confirm({
|
93 |
title: title ?? t('common.deleteModalTitle'),
|
94 |
icon: <ExclamationCircleFilled />,
|
95 |
-
|
96 |
okText: t('common.ok'),
|
97 |
okType: 'danger',
|
98 |
cancelText: t('common.cancel'),
|
|
|
1 |
import { ExclamationCircleFilled } from '@ant-design/icons';
|
2 |
import { App } from 'antd';
|
3 |
import isEqual from 'lodash/isEqual';
|
4 |
+
import { ReactNode, useCallback, useEffect, useRef, useState } from 'react';
|
5 |
import { useTranslation } from 'react-i18next';
|
6 |
|
7 |
export const useSetModalState = () => {
|
|
|
78 |
|
79 |
interface IProps {
|
80 |
title?: string;
|
81 |
+
content?: ReactNode;
|
82 |
onOk?: (...args: any[]) => any;
|
83 |
onCancel?: (...args: any[]) => any;
|
84 |
}
|
|
|
88 |
const { t } = useTranslation();
|
89 |
|
90 |
const showDeleteConfirm = useCallback(
|
91 |
+
({ title, content, onOk, onCancel }: IProps): Promise<number> => {
|
92 |
return new Promise((resolve, reject) => {
|
93 |
modal.confirm({
|
94 |
title: title ?? t('common.deleteModalTitle'),
|
95 |
icon: <ExclamationCircleFilled />,
|
96 |
+
content,
|
97 |
okText: t('common.ok'),
|
98 |
okType: 'danger',
|
99 |
cancelText: t('common.cancel'),
|
web/src/hooks/knowledge-hooks.ts
CHANGED
@@ -1,11 +1,13 @@
|
|
1 |
import { ResponsePostType } from '@/interfaces/database/base';
|
2 |
import {
|
3 |
IKnowledge,
|
|
|
4 |
IRenameTag,
|
5 |
ITestingResult,
|
6 |
} from '@/interfaces/database/knowledge';
|
7 |
import i18n from '@/locales/config';
|
8 |
import kbService, {
|
|
|
9 |
listTag,
|
10 |
removeTag,
|
11 |
renameTag,
|
@@ -373,3 +375,20 @@ export const useFetchTagListByKnowledgeIds = () => {
|
|
373 |
};
|
374 |
|
375 |
//#endregion
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import { ResponsePostType } from '@/interfaces/database/base';
|
2 |
import {
|
3 |
IKnowledge,
|
4 |
+
IKnowledgeGraph,
|
5 |
IRenameTag,
|
6 |
ITestingResult,
|
7 |
} from '@/interfaces/database/knowledge';
|
8 |
import i18n from '@/locales/config';
|
9 |
import kbService, {
|
10 |
+
getKnowledgeGraph,
|
11 |
listTag,
|
12 |
removeTag,
|
13 |
renameTag,
|
|
|
375 |
};
|
376 |
|
377 |
//#endregion
|
378 |
+
|
379 |
+
export function useFetchKnowledgeGraph() {
|
380 |
+
const knowledgeBaseId = useKnowledgeBaseId();
|
381 |
+
|
382 |
+
const { data, isFetching: loading } = useQuery<IKnowledgeGraph>({
|
383 |
+
queryKey: ['fetchKnowledgeGraph', knowledgeBaseId],
|
384 |
+
initialData: { graph: {}, mind_map: {} } as IKnowledgeGraph,
|
385 |
+
enabled: !!knowledgeBaseId,
|
386 |
+
gcTime: 0,
|
387 |
+
queryFn: async () => {
|
388 |
+
const { data } = await getKnowledgeGraph(knowledgeBaseId);
|
389 |
+
return data?.data;
|
390 |
+
},
|
391 |
+
});
|
392 |
+
|
393 |
+
return { data, loading };
|
394 |
+
}
|
web/src/interfaces/database/document.ts
CHANGED
@@ -33,8 +33,17 @@ export interface IParserConfig {
|
|
33 |
layout_recognize?: boolean;
|
34 |
pages: any[];
|
35 |
raptor?: Raptor;
|
|
|
36 |
}
|
37 |
|
38 |
interface Raptor {
|
39 |
use_raptor: boolean;
|
40 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
33 |
layout_recognize?: boolean;
|
34 |
pages: any[];
|
35 |
raptor?: Raptor;
|
36 |
+
graphrag?: GraphRag;
|
37 |
}
|
38 |
|
39 |
interface Raptor {
|
40 |
use_raptor: boolean;
|
41 |
}
|
42 |
+
|
43 |
+
interface GraphRag {
|
44 |
+
community?: boolean;
|
45 |
+
entity_types?: string[];
|
46 |
+
method?: string;
|
47 |
+
resolution?: boolean;
|
48 |
+
use_graphrag?: boolean;
|
49 |
+
}
|
web/src/interfaces/database/knowledge.ts
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import { RunningStatus } from '@/constants/knowledge';
|
|
|
2 |
|
3 |
// knowledge base
|
4 |
export interface IKnowledge {
|
@@ -136,3 +137,8 @@ export interface ITestingResult {
|
|
136 |
}
|
137 |
|
138 |
export type IRenameTag = { fromTag: string; toTag: string };
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import { RunningStatus } from '@/constants/knowledge';
|
2 |
+
import { TreeData } from '@antv/g6/lib/types';
|
3 |
|
4 |
// knowledge base
|
5 |
export interface IKnowledge {
|
|
|
137 |
}
|
138 |
|
139 |
export type IRenameTag = { fromTag: string; toTag: string };
|
140 |
+
|
141 |
+
export interface IKnowledgeGraph {
|
142 |
+
graph: Record<string, any>;
|
143 |
+
mind_map: TreeData;
|
144 |
+
}
|
web/src/locales/en.ts
CHANGED
@@ -86,6 +86,7 @@ export default {
|
|
86 |
testing: 'Retrieval testing',
|
87 |
files: 'files',
|
88 |
configuration: 'Configuration',
|
|
|
89 |
name: 'Name',
|
90 |
namePlaceholder: 'Please input name!',
|
91 |
doc: 'Docs',
|
@@ -137,7 +138,7 @@ export default {
|
|
137 |
fromMessage: 'Missing start page number',
|
138 |
toPlaceholder: 'to',
|
139 |
toMessage: 'Missing end page number (excluded)',
|
140 |
-
layoutRecognize: 'Layout recognition',
|
141 |
layoutRecognizeTip:
|
142 |
'Use visual models for layout analysis to better understand the structure of the document and effectively locate document titles, text blocks, images, and tables. If disabled, only the plain text in the PDF will be retrieved.',
|
143 |
taskPageSize: 'Task page size',
|
@@ -192,6 +193,8 @@ export default {
|
|
192 |
</ul>
|
193 |
`,
|
194 |
metaData: 'Meta data',
|
|
|
|
|
195 |
},
|
196 |
knowledgeConfiguration: {
|
197 |
titleDescription:
|
@@ -363,6 +366,17 @@ This procedure will improve precision of retrieval by adding more information to
|
|
363 |
topnTags: 'Top-N Tags',
|
364 |
tags: 'Tags',
|
365 |
addTag: 'Add tag',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
366 |
},
|
367 |
chunk: {
|
368 |
chunk: 'Chunk',
|
@@ -503,6 +517,9 @@ This procedure will improve precision of retrieval by adding more information to
|
|
503 |
'This optimizes user queries using context in a multi-round conversation. When enabled, it will consume additional LLM tokens.',
|
504 |
howUseId: 'How to use chat ID?',
|
505 |
description: 'Description of assistant',
|
|
|
|
|
|
|
506 |
},
|
507 |
setting: {
|
508 |
profile: 'Profile',
|
@@ -971,8 +988,8 @@ This procedure will improve precision of retrieval by adding more information to
|
|
971 |
notEmpty: 'Not empty',
|
972 |
},
|
973 |
switchLogicOperatorOptions: {
|
974 |
-
and: '
|
975 |
-
or: '
|
976 |
},
|
977 |
operator: 'Operator',
|
978 |
value: 'Value',
|
|
|
86 |
testing: 'Retrieval testing',
|
87 |
files: 'files',
|
88 |
configuration: 'Configuration',
|
89 |
+
knowledgeGraph: 'Knowledge graph',
|
90 |
name: 'Name',
|
91 |
namePlaceholder: 'Please input name!',
|
92 |
doc: 'Docs',
|
|
|
138 |
fromMessage: 'Missing start page number',
|
139 |
toPlaceholder: 'to',
|
140 |
toMessage: 'Missing end page number (excluded)',
|
141 |
+
layoutRecognize: 'Layout recognition & OCR',
|
142 |
layoutRecognizeTip:
|
143 |
'Use visual models for layout analysis to better understand the structure of the document and effectively locate document titles, text blocks, images, and tables. If disabled, only the plain text in the PDF will be retrieved.',
|
144 |
taskPageSize: 'Task page size',
|
|
|
193 |
</ul>
|
194 |
`,
|
195 |
metaData: 'Meta data',
|
196 |
+
deleteDocumentConfirmContent:
|
197 |
+
'The document is associated with the knowledge graph. After deletion, the related node and relationship information will be deleted, but the graph will not be updated immediately. The update graph action is performed during the process of parsing the new document that carries the knowledge graph extraction task.',
|
198 |
},
|
199 |
knowledgeConfiguration: {
|
200 |
titleDescription:
|
|
|
366 |
topnTags: 'Top-N Tags',
|
367 |
tags: 'Tags',
|
368 |
addTag: 'Add tag',
|
369 |
+
useGraphRag: 'Extract knowledge graph',
|
370 |
+
useGraphRagTip:
|
371 |
+
'After files being chunked, all the chunks will be used for knowlege graph generation which helps inference of multi-hop and complex problems a lot.',
|
372 |
+
graphRagMethod: 'Method',
|
373 |
+
graphRagMethodTip: `Light: the entity and relation extraction prompt is from GitHub - HKUDS/LightRAG: "LightRAG: Simple and Fast Retrieval-Augmented Generation"</br>
|
374 |
+
General: the entity and relation extraction prompt is from GitHub - microsoft/graphrag: A modular graph-based Retrieval-Augmented Generation (RAG) system`,
|
375 |
+
resolution: 'Entity resolution',
|
376 |
+
resolutionTip: `The resolution procedure would merge entities with the same meaning together which allows the graph conciser and more accurate. Entities as following should be merged: President Trump, Donald Trump, Donald J. Trump, Donald John Trump`,
|
377 |
+
community: 'Community reports generation',
|
378 |
+
communityTip:
|
379 |
+
'Chunks are clustered into hierarchical communities with entities and relationships connecting each segment up through higher levels of abstraction. We then use an LLM to generate a summary of each community, known as a community report. More: https://www.microsoft.com/en-us/research/blog/graphrag-improving-global-search-via-dynamic-community-selection/',
|
380 |
},
|
381 |
chunk: {
|
382 |
chunk: 'Chunk',
|
|
|
517 |
'This optimizes user queries using context in a multi-round conversation. When enabled, it will consume additional LLM tokens.',
|
518 |
howUseId: 'How to use chat ID?',
|
519 |
description: 'Description of assistant',
|
520 |
+
useKnowledgeGraph: 'Use knowledge graph',
|
521 |
+
useKnowledgeGraphTip:
|
522 |
+
'It will retrieve descriptions of relevant entities,relations and community reports, which will enhance inference of multi-hop and complex question.',
|
523 |
},
|
524 |
setting: {
|
525 |
profile: 'Profile',
|
|
|
988 |
notEmpty: 'Not empty',
|
989 |
},
|
990 |
switchLogicOperatorOptions: {
|
991 |
+
and: 'AND',
|
992 |
+
or: 'OR',
|
993 |
},
|
994 |
operator: 'Operator',
|
995 |
value: 'Value',
|
web/src/locales/zh-traditional.ts
CHANGED
@@ -85,6 +85,7 @@ export default {
|
|
85 |
dataset: '數據集',
|
86 |
testing: '檢索測試',
|
87 |
configuration: '配置',
|
|
|
88 |
files: '文件',
|
89 |
name: '名稱',
|
90 |
namePlaceholder: '請輸入名稱',
|
@@ -135,7 +136,7 @@ export default {
|
|
135 |
fromMessage: '缺少起始頁碼',
|
136 |
toPlaceholder: '到',
|
137 |
toMessage: '缺少結束頁碼(不包含)',
|
138 |
-
layoutRecognize: '
|
139 |
layoutRecognizeTip:
|
140 |
'使用視覺模型進行佈局分析,以更好地識別文檔結構,找到標題、文本塊、圖像和表格的位置。如果沒有此功能,則只能獲取 PDF 的純文本。',
|
141 |
taskPageSize: '任務頁面大小',
|
@@ -187,6 +188,9 @@ export default {
|
|
187 |
<li>這是區塊內容....</li>
|
188 |
</ul>
|
189 |
`,
|
|
|
|
|
|
|
190 |
},
|
191 |
knowledgeConfiguration: {
|
192 |
titleDescription: '在這裡更新您的知識庫詳細信息,尤其是解析方法。',
|
@@ -346,6 +350,17 @@ export default {
|
|
346 |
`,
|
347 |
tags: '標籤',
|
348 |
addTag: '增加標籤',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
},
|
350 |
chunk: {
|
351 |
chunk: '解析塊',
|
@@ -486,6 +501,9 @@ export default {
|
|
486 |
'在多輪對話的中,對去知識庫查詢的問題進行最佳化。會呼叫大模型額外消耗token。',
|
487 |
howUseId: '如何使用聊天ID?',
|
488 |
description: '助理描述',
|
|
|
|
|
|
|
489 |
},
|
490 |
setting: {
|
491 |
profile: '概述',
|
|
|
85 |
dataset: '數據集',
|
86 |
testing: '檢索測試',
|
87 |
configuration: '配置',
|
88 |
+
knowledgeGraph: '知識圖譜',
|
89 |
files: '文件',
|
90 |
name: '名稱',
|
91 |
namePlaceholder: '請輸入名稱',
|
|
|
136 |
fromMessage: '缺少起始頁碼',
|
137 |
toPlaceholder: '到',
|
138 |
toMessage: '缺少結束頁碼(不包含)',
|
139 |
+
layoutRecognize: '佈局識別和 OCR',
|
140 |
layoutRecognizeTip:
|
141 |
'使用視覺模型進行佈局分析,以更好地識別文檔結構,找到標題、文本塊、圖像和表格的位置。如果沒有此功能,則只能獲取 PDF 的純文本。',
|
142 |
taskPageSize: '任務頁面大小',
|
|
|
188 |
<li>這是區塊內容....</li>
|
189 |
</ul>
|
190 |
`,
|
191 |
+
metaData: '元資料',
|
192 |
+
deleteDocumentConfirmContent:
|
193 |
+
'該文件與知識圖譜相關聯。刪除後,相關節點和關係資訊將被刪除,但圖不會立即更新。更新圖動作是在解析承載知識圖譜提取任務的新文件的過程中執行的。 ',
|
194 |
},
|
195 |
knowledgeConfiguration: {
|
196 |
titleDescription: '在這裡更新您的知識庫詳細信息,尤其是解析方法。',
|
|
|
350 |
`,
|
351 |
tags: '標籤',
|
352 |
addTag: '增加標籤',
|
353 |
+
useGraphRag: '提取知識圖譜',
|
354 |
+
useGraphRagTip:
|
355 |
+
'文件分塊後,所有區塊將用於知識圖譜生成,這對多跳和複雜問題的推理有很大幫助。',
|
356 |
+
graphRagMethod: '方法',
|
357 |
+
graphRagMethodTip: `Light:實體和關係提取提示來自 GitHub - HKUDS/LightRAG:“LightRAG:簡單快速的檢索增強生成”<br>
|
358 |
+
一般:實體和關係擷取提示來自 GitHub - microsoft/graphrag:基於模組化圖形的檢索增強生成 (RAG) 系統,`,
|
359 |
+
resolution: '實體歸一化',
|
360 |
+
resolutionTip: `解析過程會將具有相同意義的實體合併在一起,使知識圖譜更簡潔、更準確。應合併以下實體:川普總統、唐納德·川普、唐納德·J·川普、唐納德·約翰·川普`,
|
361 |
+
community: '社群報告生成',
|
362 |
+
communityTip:
|
363 |
+
'區塊被聚集成層次化的社區,其中實體和關係透過更高層次的抽象將每個部分連接起來。然後,我們使用 LLM 產生每個社群的摘要,即社群報告。更多資訊:https://www.microsoft.com/en-us/research/blog/graphrag-improving-global-search-via-dynamic-community-selection/',
|
364 |
},
|
365 |
chunk: {
|
366 |
chunk: '解析塊',
|
|
|
501 |
'在多輪對話的中,對去知識庫查詢的問題進行最佳化。會呼叫大模型額外消耗token。',
|
502 |
howUseId: '如何使用聊天ID?',
|
503 |
description: '助理描述',
|
504 |
+
useKnowledgeGraph: '使用知識圖譜',
|
505 |
+
useKnowledgeGraph提示:
|
506 |
+
'它將檢索相關實體、關係和社區報告的描述,這將增強多跳和複雜問題的推理。',
|
507 |
},
|
508 |
setting: {
|
509 |
profile: '概述',
|
web/src/locales/zh.ts
CHANGED
@@ -85,6 +85,7 @@ export default {
|
|
85 |
dataset: '数据集',
|
86 |
testing: '检索测试',
|
87 |
configuration: '配置',
|
|
|
88 |
files: '文件',
|
89 |
name: '名称',
|
90 |
namePlaceholder: '请输入名称',
|
@@ -135,7 +136,7 @@ export default {
|
|
135 |
fromMessage: '缺少起始页码',
|
136 |
toPlaceholder: '到',
|
137 |
toMessage: '缺少结束页码(不包含)',
|
138 |
-
layoutRecognize: '
|
139 |
layoutRecognizeTip:
|
140 |
'使用视觉模型进行布局分析,以更好地识别文档结构,找到标题、文本块、图像和表格的位置。 如果没有此功能,则只能获取 PDF 的纯文本。',
|
141 |
taskPageSize: '任务页面大小',
|
@@ -188,7 +189,9 @@ export default {
|
|
188 |
<li> 这是块内容....</li>
|
189 |
</ul>
|
190 |
`,
|
191 |
-
metaData: '
|
|
|
|
|
192 |
},
|
193 |
knowledgeConfiguration: {
|
194 |
titleDescription: '在这里更新您的知识库详细信息,尤其是解析方法。',
|
@@ -364,6 +367,17 @@ export default {
|
|
364 |
`,
|
365 |
tags: '标签',
|
366 |
addTag: '增加标签',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
367 |
},
|
368 |
chunk: {
|
369 |
chunk: '解析块',
|
@@ -504,6 +518,9 @@ export default {
|
|
504 |
'在多轮对话的中,对去知识库查询的问题进行优化。会调用大模型额外消耗token。',
|
505 |
howUseId: '如何使用聊天ID?',
|
506 |
description: '助理描述',
|
|
|
|
|
|
|
507 |
},
|
508 |
setting: {
|
509 |
profile: '概要',
|
|
|
85 |
dataset: '数据集',
|
86 |
testing: '检索测试',
|
87 |
configuration: '配置',
|
88 |
+
knowledgeGraph: '知识图谱',
|
89 |
files: '文件',
|
90 |
name: '名称',
|
91 |
namePlaceholder: '请输入名称',
|
|
|
136 |
fromMessage: '缺少起始页码',
|
137 |
toPlaceholder: '到',
|
138 |
toMessage: '缺少结束页码(不包含)',
|
139 |
+
layoutRecognize: '布局识别和 OCR',
|
140 |
layoutRecognizeTip:
|
141 |
'使用视觉模型进行布局分析,以更好地识别文档结构,找到标题、文本块、图像和表格的位置。 如果没有此功能,则只能获取 PDF 的纯文本。',
|
142 |
taskPageSize: '任务页面大小',
|
|
|
189 |
<li> 这是块内容....</li>
|
190 |
</ul>
|
191 |
`,
|
192 |
+
metaData: '元数据',
|
193 |
+
deleteDocumentConfirmContent:
|
194 |
+
'该文档与知识图谱相关联。删除后,相关节点和关系信息将被删除,但图不会立即更新。更新图动作是在解析承载知识图谱提取任务的新文档的过程中执行的。',
|
195 |
},
|
196 |
knowledgeConfiguration: {
|
197 |
titleDescription: '在这里更新您的知识库详细信息,尤其是解析方法。',
|
|
|
367 |
`,
|
368 |
tags: '标签',
|
369 |
addTag: '增加标签',
|
370 |
+
useGraphRag: '提取知识图谱',
|
371 |
+
useGraphRagTip:
|
372 |
+
'文件分块后,所有块将用于知识图谱生成,这对多跳和复杂问题的推理大有帮助。',
|
373 |
+
graphRagMethod: '方法',
|
374 |
+
graphRagMethodTip: `Light:实体和关系提取提示来自 GitHub - HKUDS/LightRAG:“LightRAG:简单快速的检索增强生成”<br>
|
375 |
+
General:实体和关系提取提示来自 GitHub - microsoft/graphrag:基于图形的模块化检索增强生成 (RAG) 系统`,
|
376 |
+
resolution: '实体归一化',
|
377 |
+
resolutionTip: `解析过程会将具有相同含义的实体合并在一起,从而使知识图谱更简洁、更准确。应合并以下实体:特朗普总统、唐纳德·特朗普、唐纳德·J·特朗普、唐纳德·约翰·特朗普`,
|
378 |
+
community: '社区报告生成',
|
379 |
+
communityTip:
|
380 |
+
'区块被聚集成层次化的社区,实体和关系通过更高抽象层次将每个部分连接起来。然后,我们使用 LLM 生成每个社区的摘要,称为社区报告。更多信息:https://www.microsoft.com/en-us/research/blog/graphrag-improving-global-search-via-dynamic-community-selection/',
|
381 |
},
|
382 |
chunk: {
|
383 |
chunk: '解析块',
|
|
|
518 |
'在多轮对话的中,对去知识库查询的问题进行优化。会调用大模型额外消耗token。',
|
519 |
howUseId: '如何使用聊天ID?',
|
520 |
description: '助理描述',
|
521 |
+
useKnowledgeGraph: '使用知识图谱',
|
522 |
+
useKnowledgeGraphTip:
|
523 |
+
'它将检索相关实体、关系和社区报告的描述,这将增强多跳和复杂问题的推理。',
|
524 |
},
|
525 |
setting: {
|
526 |
profile: '概要',
|
web/src/pages/add-knowledge/components/knowledge-chunk/components/knowledge-graph/modal.tsx
DELETED
@@ -1,75 +0,0 @@
|
|
1 |
-
import IndentedTree from '@/components/indented-tree/indented-tree';
|
2 |
-
import { useFetchKnowledgeGraph } from '@/hooks/chunk-hooks';
|
3 |
-
import { useGetKnowledgeSearchParams } from '@/hooks/route-hook';
|
4 |
-
import { Flex, Modal, Segmented } from 'antd';
|
5 |
-
import React, { useEffect, useMemo, useState } from 'react';
|
6 |
-
import { useTranslation } from 'react-i18next';
|
7 |
-
import ForceGraph from './force-graph';
|
8 |
-
import styles from './index.less';
|
9 |
-
import { isDataExist } from './util';
|
10 |
-
|
11 |
-
enum SegmentedValue {
|
12 |
-
Graph = 'Graph',
|
13 |
-
Mind = 'Mind',
|
14 |
-
}
|
15 |
-
|
16 |
-
const KnowledgeGraphModal: React.FC = () => {
|
17 |
-
const [isModalOpen, setIsModalOpen] = useState(false);
|
18 |
-
const { documentId } = useGetKnowledgeSearchParams();
|
19 |
-
const { data } = useFetchKnowledgeGraph(documentId);
|
20 |
-
const [value, setValue] = useState<SegmentedValue>(SegmentedValue.Graph);
|
21 |
-
const { t } = useTranslation();
|
22 |
-
|
23 |
-
const options = useMemo(() => {
|
24 |
-
return [
|
25 |
-
{ value: SegmentedValue.Graph, label: t('chunk.graph') },
|
26 |
-
{ value: SegmentedValue.Mind, label: t('chunk.mind') },
|
27 |
-
];
|
28 |
-
}, [t]);
|
29 |
-
|
30 |
-
const handleOk = () => {
|
31 |
-
setIsModalOpen(false);
|
32 |
-
};
|
33 |
-
|
34 |
-
const handleCancel = () => {
|
35 |
-
setIsModalOpen(false);
|
36 |
-
};
|
37 |
-
|
38 |
-
useEffect(() => {
|
39 |
-
if (isDataExist(data)) {
|
40 |
-
setIsModalOpen(true);
|
41 |
-
}
|
42 |
-
}, [setIsModalOpen, data]);
|
43 |
-
|
44 |
-
return (
|
45 |
-
<Modal
|
46 |
-
title={t('chunk.graph')}
|
47 |
-
open={isModalOpen}
|
48 |
-
onOk={handleOk}
|
49 |
-
onCancel={handleCancel}
|
50 |
-
width={'90vw'}
|
51 |
-
footer={null}
|
52 |
-
>
|
53 |
-
<section className={styles.modalContainer}>
|
54 |
-
<Flex justify="end">
|
55 |
-
<Segmented
|
56 |
-
size="large"
|
57 |
-
options={options}
|
58 |
-
value={value}
|
59 |
-
onChange={(v) => setValue(v as SegmentedValue)}
|
60 |
-
/>
|
61 |
-
</Flex>
|
62 |
-
<ForceGraph
|
63 |
-
data={data?.data?.graph}
|
64 |
-
show={value === SegmentedValue.Graph}
|
65 |
-
></ForceGraph>
|
66 |
-
<IndentedTree
|
67 |
-
data={data?.data?.mind_map}
|
68 |
-
show={value === SegmentedValue.Mind}
|
69 |
-
></IndentedTree>
|
70 |
-
</section>
|
71 |
-
</Modal>
|
72 |
-
);
|
73 |
-
};
|
74 |
-
|
75 |
-
export default KnowledgeGraphModal;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/add-knowledge/components/knowledge-chunk/index.tsx
CHANGED
@@ -8,7 +8,6 @@ import ChunkCard from './components/chunk-card';
|
|
8 |
import CreatingModal from './components/chunk-creating-modal';
|
9 |
import ChunkToolBar from './components/chunk-toolbar';
|
10 |
import DocumentPreview from './components/document-preview/preview';
|
11 |
-
import KnowledgeGraphModal from './components/knowledge-graph/modal';
|
12 |
import {
|
13 |
useChangeChunkTextMode,
|
14 |
useDeleteChunkByIds,
|
@@ -196,7 +195,6 @@ const Chunk = () => {
|
|
196 |
parserId={documentInfo.parser_id}
|
197 |
/>
|
198 |
)}
|
199 |
-
<KnowledgeGraphModal></KnowledgeGraphModal>
|
200 |
</>
|
201 |
);
|
202 |
};
|
|
|
8 |
import CreatingModal from './components/chunk-creating-modal';
|
9 |
import ChunkToolBar from './components/chunk-toolbar';
|
10 |
import DocumentPreview from './components/document-preview/preview';
|
|
|
11 |
import {
|
12 |
useChangeChunkTextMode,
|
13 |
useDeleteChunkByIds,
|
|
|
195 |
parserId={documentInfo.parser_id}
|
196 |
/>
|
197 |
)}
|
|
|
198 |
</>
|
199 |
);
|
200 |
};
|
web/src/pages/add-knowledge/components/knowledge-file/parsing-action-cell/index.tsx
CHANGED
@@ -39,7 +39,12 @@ const ParsingActionCell = ({
|
|
39 |
|
40 |
const onRmDocument = () => {
|
41 |
if (!isRunning) {
|
42 |
-
showDeleteConfirm({
|
|
|
|
|
|
|
|
|
|
|
43 |
}
|
44 |
};
|
45 |
|
|
|
39 |
|
40 |
const onRmDocument = () => {
|
41 |
if (!isRunning) {
|
42 |
+
showDeleteConfirm({
|
43 |
+
onOk: () => removeDocument([documentId]),
|
44 |
+
content: record?.parser_config?.graphrag?.use_graphrag
|
45 |
+
? t('deleteDocumentConfirmContent')
|
46 |
+
: '',
|
47 |
+
});
|
48 |
}
|
49 |
};
|
50 |
|
web/src/pages/add-knowledge/components/{knowledge-chunk/components/knowledge-graph → knowledge-graph}/constant.ts
RENAMED
File without changes
|
web/src/pages/add-knowledge/components/{knowledge-chunk/components/knowledge-graph → knowledge-graph}/force-graph.tsx
RENAMED
@@ -24,7 +24,7 @@ const ForceGraph = ({ data, show }: IProps) => {
|
|
24 |
if (!isEmpty(data)) {
|
25 |
const graphData = data;
|
26 |
const mi = buildNodesAndCombos(graphData.nodes);
|
27 |
-
return { edges: graphData.
|
28 |
}
|
29 |
return { nodes: [], edges: [] };
|
30 |
}, [data]);
|
@@ -130,8 +130,8 @@ const ForceGraph = ({ data, show }: IProps) => {
|
|
130 |
ref={containerRef}
|
131 |
className={styles.forceContainer}
|
132 |
style={{
|
133 |
-
width: '
|
134 |
-
height: '
|
135 |
display: show ? 'block' : 'none',
|
136 |
}}
|
137 |
/>
|
|
|
24 |
if (!isEmpty(data)) {
|
25 |
const graphData = data;
|
26 |
const mi = buildNodesAndCombos(graphData.nodes);
|
27 |
+
return { edges: graphData.edges, ...mi };
|
28 |
}
|
29 |
return { nodes: [], edges: [] };
|
30 |
}, [data]);
|
|
|
130 |
ref={containerRef}
|
131 |
className={styles.forceContainer}
|
132 |
style={{
|
133 |
+
width: '100%',
|
134 |
+
height: '100%',
|
135 |
display: show ? 'block' : 'none',
|
136 |
}}
|
137 |
/>
|
web/src/pages/add-knowledge/components/{knowledge-chunk/components/knowledge-graph → knowledge-graph}/index.less
RENAMED
@@ -3,8 +3,3 @@
|
|
3 |
border-radius: 10px !important;
|
4 |
}
|
5 |
}
|
6 |
-
|
7 |
-
.modalContainer {
|
8 |
-
width: 100%;
|
9 |
-
height: 100%;
|
10 |
-
}
|
|
|
3 |
border-radius: 10px !important;
|
4 |
}
|
5 |
}
|
|
|
|
|
|
|
|
|
|
web/src/pages/add-knowledge/components/knowledge-graph/index.tsx
ADDED
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { useFetchKnowledgeGraph } from '@/hooks/knowledge-hooks';
|
2 |
+
import React from 'react';
|
3 |
+
import ForceGraph from './force-graph';
|
4 |
+
|
5 |
+
const KnowledgeGraphModal: React.FC = () => {
|
6 |
+
const { data } = useFetchKnowledgeGraph();
|
7 |
+
|
8 |
+
return (
|
9 |
+
<section className={'w-full h-full'}>
|
10 |
+
<ForceGraph data={data?.graph} show></ForceGraph>
|
11 |
+
</section>
|
12 |
+
);
|
13 |
+
};
|
14 |
+
|
15 |
+
export default KnowledgeGraphModal;
|
web/src/pages/add-knowledge/components/{knowledge-chunk/components/knowledge-graph → knowledge-graph}/util.ts
RENAMED
File without changes
|
web/src/pages/add-knowledge/components/knowledge-setting/configuration.tsx
CHANGED
@@ -13,6 +13,9 @@ import ParseConfiguration, {
|
|
13 |
showRaptorParseConfiguration,
|
14 |
showTagItems,
|
15 |
} from '@/components/parse-configuration';
|
|
|
|
|
|
|
16 |
import { useTranslate } from '@/hooks/common-hooks';
|
17 |
import { useHandleChunkMethodSelectChange } from '@/hooks/logic-hooks';
|
18 |
import { normFile } from '@/utils/file-util';
|
@@ -149,6 +152,8 @@ const ConfigurationForm = ({ form }: { form: FormInstance }) => {
|
|
149 |
<ParseConfiguration></ParseConfiguration>
|
150 |
)}
|
151 |
|
|
|
|
|
152 |
{showTagItems(parserId) && <TagItems></TagItems>}
|
153 |
</>
|
154 |
);
|
|
|
13 |
showRaptorParseConfiguration,
|
14 |
showTagItems,
|
15 |
} from '@/components/parse-configuration';
|
16 |
+
import GraphRagItems, {
|
17 |
+
showGraphRagItems,
|
18 |
+
} from '@/components/parse-configuration/graph-rag-items';
|
19 |
import { useTranslate } from '@/hooks/common-hooks';
|
20 |
import { useHandleChunkMethodSelectChange } from '@/hooks/logic-hooks';
|
21 |
import { normFile } from '@/utils/file-util';
|
|
|
152 |
<ParseConfiguration></ParseConfiguration>
|
153 |
)}
|
154 |
|
155 |
+
{showGraphRagItems(parserId) && <GraphRagItems></GraphRagItems>}
|
156 |
+
|
157 |
{showTagItems(parserId) && <TagItems></TagItems>}
|
158 |
</>
|
159 |
);
|
web/src/pages/add-knowledge/components/knowledge-sidebar/index.tsx
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
import { ReactComponent as ConfigurationIcon } from '@/assets/svg/knowledge-configration.svg';
|
2 |
import { ReactComponent as DatasetIcon } from '@/assets/svg/knowledge-dataset.svg';
|
3 |
import { ReactComponent as TestingIcon } from '@/assets/svg/knowledge-testing.svg';
|
4 |
-
import {
|
|
|
|
|
|
|
5 |
import {
|
6 |
useGetKnowledgeSearchParams,
|
7 |
useSecondPathName,
|
@@ -14,6 +17,8 @@ import { useTranslation } from 'react-i18next';
|
|
14 |
import { useNavigate } from 'umi';
|
15 |
import { KnowledgeRouteKey } from '../../constant';
|
16 |
|
|
|
|
|
17 |
import styles from './index.less';
|
18 |
|
19 |
const KnowledgeSidebar = () => {
|
@@ -30,6 +35,8 @@ const KnowledgeSidebar = () => {
|
|
30 |
navigate(`/knowledge/${e.key}?id=${knowledgeId}`);
|
31 |
};
|
32 |
|
|
|
|
|
33 |
type MenuItem = Required<MenuProps>['items'][number];
|
34 |
|
35 |
const getItem = useCallback(
|
@@ -54,7 +61,7 @@ const KnowledgeSidebar = () => {
|
|
54 |
);
|
55 |
|
56 |
const items: MenuItem[] = useMemo(() => {
|
57 |
-
|
58 |
getItem(
|
59 |
KnowledgeRouteKey.Dataset, // TODO: Change icon color when selected
|
60 |
KnowledgeRouteKey.Dataset,
|
@@ -71,7 +78,19 @@ const KnowledgeSidebar = () => {
|
|
71 |
<ConfigurationIcon />,
|
72 |
),
|
73 |
];
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
useEffect(() => {
|
77 |
if (windowWidth.width > 957) {
|
@@ -81,7 +100,6 @@ const KnowledgeSidebar = () => {
|
|
81 |
}
|
82 |
}, [windowWidth.width]);
|
83 |
|
84 |
-
// 标记一下
|
85 |
useEffect(() => {
|
86 |
const widthSize = () => {
|
87 |
const width = getWidth();
|
|
|
1 |
import { ReactComponent as ConfigurationIcon } from '@/assets/svg/knowledge-configration.svg';
|
2 |
import { ReactComponent as DatasetIcon } from '@/assets/svg/knowledge-dataset.svg';
|
3 |
import { ReactComponent as TestingIcon } from '@/assets/svg/knowledge-testing.svg';
|
4 |
+
import {
|
5 |
+
useFetchKnowledgeBaseConfiguration,
|
6 |
+
useFetchKnowledgeGraph,
|
7 |
+
} from '@/hooks/knowledge-hooks';
|
8 |
import {
|
9 |
useGetKnowledgeSearchParams,
|
10 |
useSecondPathName,
|
|
|
17 |
import { useNavigate } from 'umi';
|
18 |
import { KnowledgeRouteKey } from '../../constant';
|
19 |
|
20 |
+
import { isEmpty } from 'lodash';
|
21 |
+
import { GitGraph } from 'lucide-react';
|
22 |
import styles from './index.less';
|
23 |
|
24 |
const KnowledgeSidebar = () => {
|
|
|
35 |
navigate(`/knowledge/${e.key}?id=${knowledgeId}`);
|
36 |
};
|
37 |
|
38 |
+
const { data } = useFetchKnowledgeGraph();
|
39 |
+
|
40 |
type MenuItem = Required<MenuProps>['items'][number];
|
41 |
|
42 |
const getItem = useCallback(
|
|
|
61 |
);
|
62 |
|
63 |
const items: MenuItem[] = useMemo(() => {
|
64 |
+
const list = [
|
65 |
getItem(
|
66 |
KnowledgeRouteKey.Dataset, // TODO: Change icon color when selected
|
67 |
KnowledgeRouteKey.Dataset,
|
|
|
78 |
<ConfigurationIcon />,
|
79 |
),
|
80 |
];
|
81 |
+
|
82 |
+
if (!isEmpty(data.graph)) {
|
83 |
+
list.push(
|
84 |
+
getItem(
|
85 |
+
KnowledgeRouteKey.KnowledgeGraph,
|
86 |
+
KnowledgeRouteKey.KnowledgeGraph,
|
87 |
+
<GitGraph />,
|
88 |
+
),
|
89 |
+
);
|
90 |
+
}
|
91 |
+
|
92 |
+
return list;
|
93 |
+
}, [data, getItem]);
|
94 |
|
95 |
useEffect(() => {
|
96 |
if (windowWidth.width > 957) {
|
|
|
100 |
}
|
101 |
}, [windowWidth.width]);
|
102 |
|
|
|
103 |
useEffect(() => {
|
104 |
const widthSize = () => {
|
105 |
const width = getWidth();
|
web/src/pages/add-knowledge/components/knowledge-testing/testing-control/index.tsx
CHANGED
@@ -6,6 +6,7 @@ import { Button, Card, Divider, Flex, Form, Input } from 'antd';
|
|
6 |
import { FormInstance } from 'antd/lib';
|
7 |
import { LabelWordCloud } from './label-word-cloud';
|
8 |
|
|
|
9 |
import styles from './index.less';
|
10 |
|
11 |
type FieldType = {
|
@@ -38,6 +39,7 @@ const TestingControl = ({ form, handleTesting }: IProps) => {
|
|
38 |
<Form name="testing" layout="vertical" form={form}>
|
39 |
<SimilaritySlider isTooltipShown></SimilaritySlider>
|
40 |
<Rerank></Rerank>
|
|
|
41 |
<Card size="small" title={t('testText')}>
|
42 |
<Form.Item<FieldType>
|
43 |
name={'question'}
|
|
|
6 |
import { FormInstance } from 'antd/lib';
|
7 |
import { LabelWordCloud } from './label-word-cloud';
|
8 |
|
9 |
+
import { UseKnowledgeGraphItem } from '@/components/use-knowledge-graph-item';
|
10 |
import styles from './index.less';
|
11 |
|
12 |
type FieldType = {
|
|
|
39 |
<Form name="testing" layout="vertical" form={form}>
|
40 |
<SimilaritySlider isTooltipShown></SimilaritySlider>
|
41 |
<Rerank></Rerank>
|
42 |
+
<UseKnowledgeGraphItem filedName={['use_kg']}></UseKnowledgeGraphItem>
|
43 |
<Card size="small" title={t('testText')}>
|
44 |
<Form.Item<FieldType>
|
45 |
name={'question'}
|
web/src/pages/chat/chat-configuration-modal/prompt-engine.tsx
CHANGED
@@ -30,6 +30,7 @@ import { EditableCell, EditableRow } from './editable-cell';
|
|
30 |
|
31 |
import Rerank from '@/components/rerank';
|
32 |
import TopNItem from '@/components/top-n-item';
|
|
|
33 |
import { useTranslate } from '@/hooks/common-hooks';
|
34 |
import { useSelectPromptConfigParameters } from '../hooks';
|
35 |
import styles from './index.less';
|
@@ -168,6 +169,9 @@ const PromptEngine = (
|
|
168 |
>
|
169 |
<Switch></Switch>
|
170 |
</Form.Item>
|
|
|
|
|
|
|
171 |
<Rerank></Rerank>
|
172 |
<section className={classNames(styles.variableContainer)}>
|
173 |
<Row align={'middle'} justify="end">
|
|
|
30 |
|
31 |
import Rerank from '@/components/rerank';
|
32 |
import TopNItem from '@/components/top-n-item';
|
33 |
+
import { UseKnowledgeGraphItem } from '@/components/use-knowledge-graph-item';
|
34 |
import { useTranslate } from '@/hooks/common-hooks';
|
35 |
import { useSelectPromptConfigParameters } from '../hooks';
|
36 |
import styles from './index.less';
|
|
|
169 |
>
|
170 |
<Switch></Switch>
|
171 |
</Form.Item>
|
172 |
+
<UseKnowledgeGraphItem
|
173 |
+
filedName={['prompt_config', 'use_kg']}
|
174 |
+
></UseKnowledgeGraphItem>
|
175 |
<Rerank></Rerank>
|
176 |
<section className={classNames(styles.variableContainer)}>
|
177 |
<Row align={'middle'} justify="end">
|
web/src/pages/knowledge/knowledge-card/index.tsx
CHANGED
@@ -41,7 +41,7 @@ const KnowledgeCard = ({ item }: IProps) => {
|
|
41 |
return (
|
42 |
<Badge.Ribbon
|
43 |
text={item?.nickname}
|
44 |
-
color={userInfo
|
45 |
className={classNames(styles.ribbon, {
|
46 |
[styles.hideRibbon]: item.permission !== 'team',
|
47 |
})}
|
|
|
41 |
return (
|
42 |
<Badge.Ribbon
|
43 |
text={item?.nickname}
|
44 |
+
color={userInfo?.nickname === item?.nickname ? '#1677ff' : 'pink'}
|
45 |
className={classNames(styles.ribbon, {
|
46 |
[styles.hideRibbon]: item.permission !== 'team',
|
47 |
})}
|
web/src/routes.ts
CHANGED
@@ -66,6 +66,10 @@ const routes = [
|
|
66 |
path: '/knowledge/testing',
|
67 |
component: '@/pages/add-knowledge/components/knowledge-testing',
|
68 |
},
|
|
|
|
|
|
|
|
|
69 |
],
|
70 |
},
|
71 |
{
|
|
|
66 |
path: '/knowledge/testing',
|
67 |
component: '@/pages/add-knowledge/components/knowledge-testing',
|
68 |
},
|
69 |
+
{
|
70 |
+
path: '/knowledge/knowledgeGraph',
|
71 |
+
component: '@/pages/add-knowledge/components/knowledge-graph',
|
72 |
+
},
|
73 |
],
|
74 |
},
|
75 |
{
|
web/src/services/knowledge-service.ts
CHANGED
@@ -165,4 +165,8 @@ export const renameTag = (
|
|
165 |
{ fromTag, toTag }: IRenameTag,
|
166 |
) => post(api.renameTag(knowledgeId), { fromTag, toTag });
|
167 |
|
|
|
|
|
|
|
|
|
168 |
export default kbService;
|
|
|
165 |
{ fromTag, toTag }: IRenameTag,
|
166 |
) => post(api.renameTag(knowledgeId), { fromTag, toTag });
|
167 |
|
168 |
+
export function getKnowledgeGraph(knowledgeId: string) {
|
169 |
+
return request.get(api.getKnowledgeGraph(knowledgeId));
|
170 |
+
}
|
171 |
+
|
172 |
export default kbService;
|
web/src/utils/api.ts
CHANGED
@@ -36,6 +36,8 @@ export default {
|
|
36 |
update_kb: `${api_host}/kb/update`,
|
37 |
rm_kb: `${api_host}/kb/rm`,
|
38 |
get_kb_detail: `${api_host}/kb/detail`,
|
|
|
|
|
39 |
|
40 |
// tags
|
41 |
listTag: (knowledgeId: string) => `${api_host}/kb/${knowledgeId}/tags`,
|
|
|
36 |
update_kb: `${api_host}/kb/update`,
|
37 |
rm_kb: `${api_host}/kb/rm`,
|
38 |
get_kb_detail: `${api_host}/kb/detail`,
|
39 |
+
getKnowledgeGraph: (knowledgeId: string) =>
|
40 |
+
`${api_host}/kb/${knowledgeId}/knowledge_graph`,
|
41 |
|
42 |
// tags
|
43 |
listTag: (knowledgeId: string) => `${api_host}/kb/${knowledgeId}/tags`,
|