diff --git a/web/src/components/retrieval-documents/index.tsx b/web/src/components/retrieval-documents/index.tsx index 686e410ef65..50344370e12 100644 --- a/web/src/components/retrieval-documents/index.tsx +++ b/web/src/components/retrieval-documents/index.tsx @@ -3,19 +3,22 @@ import { Collapse, Flex, Space } from 'antd'; import SelectFiles from './select-files'; import { useSelectTestingResult } from '@/hooks/knowledge-hooks'; -import { useState } from 'react'; import { useTranslation } from 'react-i18next'; import styles from './index.less'; interface IProps { - selectedDocumentIdsLength?: number; onTesting(documentIds: string[]): void; + setSelectedDocumentIds(documentIds: string[]): void; + selectedDocumentIds: string[]; } -const RetrievalDocuments = ({ onTesting }: IProps) => { +const RetrievalDocuments = ({ + onTesting, + selectedDocumentIds, + setSelectedDocumentIds, +}: IProps) => { const { t } = useTranslation(); const { documents } = useSelectTestingResult(); - const [selectedDocumentIds, setSelectedDocumentIds] = useState([]); return ( { () => [ { path: '/knowledge', name: t('knowledgeBase'), icon: KnowledgeBaseIcon }, { path: '/chat', name: t('chat'), icon: MessageOutlined }, - // { path: '/search', name: t('search'), icon: SearchOutlined }, + { path: '/search', name: t('search'), icon: SearchOutlined }, { path: '/flow', name: t('flow'), icon: GraphIcon }, { path: '/file', name: t('fileManager'), icon: FileIcon }, ], diff --git a/web/src/pages/search/hooks.ts b/web/src/pages/search/hooks.ts index c266b97f7c8..9a7de76d3b8 100644 --- a/web/src/pages/search/hooks.ts +++ b/web/src/pages/search/hooks.ts @@ -1,6 +1,9 @@ import { useFetchMindMap, useFetchRelatedQuestions } from '@/hooks/chat-hooks'; import { useTestChunkRetrieval } from '@/hooks/knowledge-hooks'; -import { useSendMessageWithSse } from '@/hooks/logic-hooks'; +import { + useGetPaginationWithRouter, + useSendMessageWithSse, +} from '@/hooks/logic-hooks'; import { IAnswer } from '@/interfaces/database/chat'; import api from '@/utils/api'; import { get, isEmpty, trim } from 'lodash'; @@ -20,6 +23,9 @@ export const useSendQuestion = (kbIds: string[]) => { } = useFetchMindMap(); const [searchStr, setSearchStr] = useState(''); const [isFirstRender, setIsFirstRender] = useState(true); + const [selectedDocumentIds, setSelectedDocumentIds] = useState([]); + + const { pagination } = useGetPaginationWithRouter(); const sendQuestion = useCallback( (question: string) => { @@ -55,7 +61,7 @@ export const useSendQuestion = (kbIds: string[]) => { ); const handleTestChunk = useCallback( - (documentIds: string[]) => { + (documentIds: string[], page: number = 1, size: number = 10) => { const q = trim(searchStr); if (sendingLoading || isEmpty(q)) return; @@ -63,10 +69,12 @@ export const useSendQuestion = (kbIds: string[]) => { kb_id: kbIds, highlight: true, question: q, - doc_ids: Array.isArray(documentIds) ? documentIds : [], + doc_ids: documentIds ?? selectedDocumentIds, + page, + size, }); }, - [sendingLoading, searchStr, kbIds, testChunk], + [sendingLoading, searchStr, kbIds, testChunk, selectedDocumentIds], ); useEffect(() => { @@ -89,6 +97,7 @@ export const useSendQuestion = (kbIds: string[]) => { handleSearchStrChange, handleClickRelatedQuestion, handleTestChunk, + setSelectedDocumentIds, loading, sendingLoading, answer: currentAnswer, @@ -97,6 +106,7 @@ export const useSendQuestion = (kbIds: string[]) => { mindMapLoading, searchStr, isFirstRender, + selectedDocumentIds, }; }; @@ -124,3 +134,45 @@ export const useFetchBackgroundImage = () => { return `https://cn.bing.com${imgUrl}`; }; + +export const useTestRetrieval = ( + kbIds: string[], + searchStr: string, + sendingLoading: boolean, +) => { + const { testChunk, loading } = useTestChunkRetrieval(); + const { pagination } = useGetPaginationWithRouter(); + + const [selectedDocumentIds, setSelectedDocumentIds] = useState([]); + + const handleTestChunk = useCallback(() => { + const q = trim(searchStr); + if (sendingLoading || isEmpty(q)) return; + + testChunk({ + kb_id: kbIds, + highlight: true, + question: q, + doc_ids: Array.isArray(selectedDocumentIds) ? selectedDocumentIds : [], + page: pagination.current, + size: pagination.pageSize, + }); + }, [ + sendingLoading, + searchStr, + kbIds, + testChunk, + selectedDocumentIds, + pagination, + ]); + + useEffect(() => { + handleTestChunk(); + }, [handleTestChunk]); + + return { + loading, + selectedDocumentIds, + setSelectedDocumentIds, + }; +}; diff --git a/web/src/pages/search/index.less b/web/src/pages/search/index.less index 1c8a3cbf4d8..6b3977c99f7 100644 --- a/web/src/pages/search/index.less +++ b/web/src/pages/search/index.less @@ -62,6 +62,10 @@ // background-color: aqua; overflow: auto; padding: 20px 10px 10px; + .chunks { + // overflow: auto; + // height: 60vh; + } } .graph { @@ -100,6 +104,9 @@ .globalInput { width: 600px; + position: sticky; + top: 0; + z-index: 1; .input(); } .partialInput { diff --git a/web/src/pages/search/index.tsx b/web/src/pages/search/index.tsx index a394ff673aa..be8bce82393 100644 --- a/web/src/pages/search/index.tsx +++ b/web/src/pages/search/index.tsx @@ -1,7 +1,11 @@ import HightLightMarkdown from '@/components/highlight-markdown'; import { ImageWithPopover } from '@/components/image'; import IndentedTree from '@/components/indented-tree/indented-tree'; +import PdfDrawer from '@/components/pdf-drawer'; +import { useClickDrawer } from '@/components/pdf-drawer/hooks'; +import RetrievalDocuments from '@/components/retrieval-documents'; import { useSelectTestingResult } from '@/hooks/knowledge-hooks'; +import { useGetPaginationWithRouter } from '@/hooks/logic-hooks'; import { IReference } from '@/interfaces/database/chat'; import { Card, @@ -10,19 +14,18 @@ import { Input, Layout, List, + Pagination, + PaginationProps, Skeleton, Space, Tag, } from 'antd'; import { useState } from 'react'; +import { useTranslation } from 'react-i18next'; import MarkdownContent from '../chat/markdown-content'; import { useFetchBackgroundImage, useSendQuestion } from './hooks'; import SearchSidebar from './sidebar'; -import PdfDrawer from '@/components/pdf-drawer'; -import { useClickDrawer } from '@/components/pdf-drawer/hooks'; -import RetrievalDocuments from '@/components/retrieval-documents'; -import { useTranslation } from 'react-i18next'; import styles from './index.less'; const { Content } = Layout; @@ -31,13 +34,14 @@ const { Search } = Input; const SearchPage = () => { const { t } = useTranslation(); const [checkedList, setCheckedList] = useState([]); - const list = useSelectTestingResult(); + const { chunks, total } = useSelectTestingResult(); // const appConf = useFetchAppConf(); const { sendQuestion, handleClickRelatedQuestion, handleSearchStrChange, handleTestChunk, + setSelectedDocumentIds, answer, sendingLoading, relatedQuestions, @@ -46,10 +50,17 @@ const SearchPage = () => { searchStr, loading, isFirstRender, + selectedDocumentIds, } = useSendQuestion(checkedList); const { visible, hideModal, documentId, selectedChunk, clickDocumentButton } = useClickDrawer(); const imgUrl = useFetchBackgroundImage(); + const { pagination } = useGetPaginationWithRouter(); + + const onChange: PaginationProps['onChange'] = (pageNumber, pageSize) => { + pagination.onChange?.(pageNumber, pageSize); + handleTestChunk(selectedDocumentIds, pageNumber, pageSize); + }; const InputSearch = ( { )} - {list.chunks.length > 0 && ( + {chunks.length > 0 && ( ( @@ -145,6 +158,12 @@ const SearchPage = () => { )} + +
{mindMapLoading ? (