mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-01-04 03:25:30 +08:00
### What problem does this PR solve? feat: Retrieval chunks by page #2247 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
@ -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<string>('');
|
||||
const [isFirstRender, setIsFirstRender] = useState(true);
|
||||
const [selectedDocumentIds, setSelectedDocumentIds] = useState<string[]>([]);
|
||||
|
||||
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<string[]>([]);
|
||||
|
||||
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,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user