diff --git a/web/src/pages/add-knowledge/components/knowledge-testing/index.tsx b/web/src/pages/add-knowledge/components/knowledge-testing/index.tsx index d7140c926..531941d30 100644 --- a/web/src/pages/add-knowledge/components/knowledge-testing/index.tsx +++ b/web/src/pages/add-knowledge/components/knowledge-testing/index.tsx @@ -3,33 +3,50 @@ import { useTestChunkRetrieval, } from '@/hooks/knowledge-hooks'; import { Flex, Form } from 'antd'; +import { useMemo, useState } from 'react'; import TestingControl from './testing-control'; import TestingResult from './testing-result'; -import { useState } from 'react'; import styles from './index.less'; const KnowledgeTesting = () => { const [form] = Form.useForm(); - const { testChunk } = useTestChunkRetrieval(); - const { testChunkAll } = useTestChunkAllRetrieval(); + const { + data: retrievalData, + testChunk, + loading: retrievalLoading, + } = useTestChunkRetrieval(); + const { + data: allRetrievalData, + testChunkAll, + loading: allRetrievalLoading, + } = useTestChunkAllRetrieval(); const [selectedDocumentIds, setSelectedDocumentIds] = useState([]); const handleTesting = async (documentIds: string[] = []) => { const values = await form.validateFields(); - testChunk({ + const params = { ...values, - doc_ids: Array.isArray(documentIds) ? documentIds : [], vector_similarity_weight: 1 - values.vector_similarity_weight, - }); + }; - testChunkAll({ - ...values, - doc_ids: [], - vector_similarity_weight: 1 - values.vector_similarity_weight, - }); + if (Array.isArray(documentIds) && documentIds.length > 0) { + testChunk({ + ...params, + doc_ids: documentIds, + }); + } else { + testChunkAll({ + ...params, + doc_ids: [], + }); + } }; + const testingResult = useMemo(() => { + return selectedDocumentIds.length > 0 ? retrievalData : allRetrievalData; + }, [allRetrievalData, retrievalData, selectedDocumentIds.length]); + return ( { selectedDocumentIds={selectedDocumentIds} > Promise; selectedDocumentIds: string[]; setSelectedDocumentIds: (ids: string[]) => void; + data?: ITestingResult; + loading?: boolean; } const TestingResult = ({ handleTesting, selectedDocumentIds, setSelectedDocumentIds, + data, + loading, }: IProps) => { - const { documents, chunks, total } = useSelectTestingResult(); - const { documents: documentsAll, total: totalAll } = useAllTestingResult(); + const { documents, chunks, total } = data || {}; const { t } = useTranslate('knowledgeDetails'); const { pagination, setPagination } = useGetPaginationWithRouter(); - const isSuccess = useSelectIsTestingSuccess(); - const isAllSuccess = useAllTestingSuccess(); const onChange: PaginationProps['onChange'] = (pageNumber, pageSize) => { pagination.onChange?.(pageNumber, pageSize); @@ -97,8 +92,7 @@ const TestingResult = ({ > - {selectedDocumentIds?.length ?? 0}/ - {documentsAll?.length ?? 0} + {selectedDocumentIds?.length ?? 0}/{documents?.length ?? 0} {t('filesSelected')} @@ -121,7 +115,7 @@ const TestingResult = ({ flex={1} className={styles.selectFilesCollapse} > - {isSuccess && chunks.length > 0 ? ( + {loading === false && chunks && chunks.length > 0 ? ( chunks?.map((x) => ( }>
@@ -136,7 +130,7 @@ const TestingResult = ({
{x.content_with_weight}
)) - ) : isSuccess && chunks.length === 0 ? ( + ) : loading === false && chunks && chunks.length === 0 ? ( ) : null}