mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-03-23 07:27:37 +08:00
Fix: The retrieval_test interface is continuously requested when the user enters a question. #13719 (#13720)
### What problem does this PR solve? Fix: The retrieval_test interface is continuously requested when the user enters a question. #13719 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -26,7 +26,7 @@ const mergeFilterValue = (
|
||||
filterValue: FilterValue,
|
||||
ids: string[],
|
||||
): FilterValue => {
|
||||
let value = {} as FilterValue;
|
||||
const value = {} as FilterValue;
|
||||
for (const key in filterValue) {
|
||||
if (Array.isArray(filterValue[key])) {
|
||||
const keyIds = filterValue[key] as string[];
|
||||
@ -52,7 +52,7 @@ export function useHandleFilterSubmit() {
|
||||
if (!filters?.length || !filterValue) {
|
||||
return;
|
||||
}
|
||||
let validFields = filters.reduce((pre, cur) => {
|
||||
const validFields = filters.reduce((pre, cur) => {
|
||||
return [...pre, ...getFilterIds(cur as FilterType)];
|
||||
}, [] as string[]);
|
||||
if (!validFields.length) {
|
||||
|
||||
@ -28,7 +28,8 @@ import {
|
||||
useQueryClient,
|
||||
} from '@tanstack/react-query';
|
||||
import { useDebounce } from 'ahooks';
|
||||
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { omit } from 'lodash';
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import { useParams, useSearchParams } from 'react-router';
|
||||
import {
|
||||
useGetPaginationWithRouter,
|
||||
@ -58,17 +59,11 @@ export const useKnowledgeBaseId = (): string => {
|
||||
export const useTestRetrieval = () => {
|
||||
const knowledgeBaseId = useKnowledgeBaseId();
|
||||
const [values, setValues] = useState<ITestRetrievalRequestBody>();
|
||||
const mountedRef = useRef(false);
|
||||
const { filterValue, handleFilterSubmit } = useHandleFilterSubmit();
|
||||
const { filterValue, setFilterValue } = useHandleFilterSubmit();
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [pageSize, setPageSize] = useState(10);
|
||||
|
||||
const onPaginationChange = useCallback((page: number, pageSize: number) => {
|
||||
setPage(page);
|
||||
setPageSize(pageSize);
|
||||
}, []);
|
||||
|
||||
const queryParams = useMemo(() => {
|
||||
return {
|
||||
...values,
|
||||
@ -80,37 +75,62 @@ export const useTestRetrieval = () => {
|
||||
};
|
||||
}, [filterValue, knowledgeBaseId, page, pageSize, values]);
|
||||
|
||||
const {
|
||||
data,
|
||||
isFetching: loading,
|
||||
refetch,
|
||||
} = useQuery<INextTestingResult>({
|
||||
queryKey: [KnowledgeApiAction.TestRetrieval, queryParams, page, pageSize],
|
||||
initialData: {
|
||||
chunks: [],
|
||||
doc_aggs: [],
|
||||
total: 0,
|
||||
isRuned: false,
|
||||
},
|
||||
enabled: false,
|
||||
gcTime: 0,
|
||||
queryFn: async () => {
|
||||
const { data } = await kbService.retrieval_test(queryParams);
|
||||
const mutation = useMutation<INextTestingResult, Error, typeof queryParams>({
|
||||
mutationFn: async (params) => {
|
||||
const { data } = await kbService.retrieval_test(params);
|
||||
const result = data?.data ?? {};
|
||||
return { ...result, isRuned: true };
|
||||
},
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (mountedRef.current && !!queryParams.question) {
|
||||
refetch();
|
||||
const refetch = useCallback(() => {
|
||||
if (queryParams.question) {
|
||||
mutation.mutate(queryParams);
|
||||
}
|
||||
mountedRef.current = true;
|
||||
}, [page, pageSize, refetch, filterValue, queryParams]);
|
||||
}, [mutation, queryParams]);
|
||||
|
||||
const onPaginationChange = useCallback(
|
||||
(newPage: number, newPageSize: number) => {
|
||||
setPage(newPage);
|
||||
setPageSize(newPageSize);
|
||||
if (mutation.data && queryParams.question) {
|
||||
const newParams = { ...queryParams, page: newPage, size: newPageSize };
|
||||
mutation.mutate(newParams);
|
||||
}
|
||||
},
|
||||
[mutation, queryParams],
|
||||
);
|
||||
|
||||
const handleFilterSubmit = useCallback(
|
||||
(value: { doc_ids?: string[] }) => {
|
||||
setFilterValue(value);
|
||||
setPage(1);
|
||||
if (mutation.data && queryParams.question) {
|
||||
const newParams = {
|
||||
...queryParams,
|
||||
doc_ids: value.doc_ids ?? [],
|
||||
page: 1,
|
||||
};
|
||||
mutation.mutate(newParams);
|
||||
}
|
||||
},
|
||||
[mutation, queryParams, setFilterValue],
|
||||
);
|
||||
|
||||
const data = useMemo(
|
||||
() =>
|
||||
mutation.data ?? {
|
||||
chunks: [],
|
||||
doc_aggs: [],
|
||||
total: 0,
|
||||
isRuned: false,
|
||||
},
|
||||
[mutation.data],
|
||||
);
|
||||
|
||||
return {
|
||||
data,
|
||||
loading,
|
||||
loading: mutation.isPending,
|
||||
setValues,
|
||||
refetch,
|
||||
onPaginationChange,
|
||||
@ -147,7 +167,7 @@ export const useFetchNextKnowledgeListByPage = () => {
|
||||
page: pagination.current,
|
||||
ext: {
|
||||
keywords: debouncedSearchString,
|
||||
owner_ids: filterValue.owner,
|
||||
owner_ids: filterValue.owner as string[],
|
||||
},
|
||||
});
|
||||
|
||||
@ -323,8 +343,6 @@ export const useUpdateKnowledge = (shouldFetchList = false) => {
|
||||
}) => {
|
||||
const kbId = params?.kb_id || knowledgeBaseId;
|
||||
const {
|
||||
kb_id,
|
||||
name,
|
||||
embedding_model,
|
||||
chunk_method,
|
||||
pipeline_id,
|
||||
@ -345,7 +363,7 @@ export const useUpdateKnowledge = (shouldFetchList = false) => {
|
||||
permission,
|
||||
pagerank,
|
||||
parser_config: extractParserConfigExt(parser_config),
|
||||
ext,
|
||||
...omit(ext, ['kb_id']),
|
||||
};
|
||||
const { data = {} } = await updateKb(kbId, requestBody);
|
||||
if (data.code === 0) {
|
||||
|
||||
@ -38,8 +38,6 @@ export default function RetrievalTesting() {
|
||||
<CardDescription>
|
||||
{t('knowledgeDetails.testingDescription')}
|
||||
</CardDescription>
|
||||
|
||||
{/* <Button>Save as Preset</Button> */}
|
||||
</header>
|
||||
</CardHeader>
|
||||
|
||||
@ -50,9 +48,6 @@ export default function RetrievalTesting() {
|
||||
<h2 className="font-semibold text-base leading-8">
|
||||
{t('knowledgeDetails.testSetting')}
|
||||
</h2>
|
||||
{/* <Button variant={'outline'} onClick={addCount}>
|
||||
<Plus /> Add New Test
|
||||
</Button> */}
|
||||
</header>
|
||||
|
||||
<div className="flex-1 h-0">
|
||||
|
||||
@ -127,7 +127,7 @@ export default function TestingForm({
|
||||
<div className="mt-2.5 text-end">
|
||||
<ButtonLoading
|
||||
type="submit"
|
||||
disabled={!!!trim(question)}
|
||||
disabled={!trim(question)}
|
||||
loading={loading}
|
||||
>
|
||||
{/* {!loading && <CirclePlay />} */}
|
||||
|
||||
@ -88,11 +88,8 @@ export function TestingResult({
|
||||
<>
|
||||
<section className="px-5 pb-5 flex flex-col gap-5 overflow-auto h-full scrollbar-thin">
|
||||
{data.chunks?.map((x) => (
|
||||
<article>
|
||||
<Card
|
||||
key={x.chunk_id}
|
||||
className="px-5 py-2.5 bg-transparent shadow-none"
|
||||
>
|
||||
<article key={x.chunk_id}>
|
||||
<Card className="px-5 py-2.5 bg-transparent shadow-none">
|
||||
<ChunkTitle item={x}></ChunkTitle>
|
||||
<p className="!mt-2.5"> {x.content_with_weight}</p>
|
||||
</Card>
|
||||
|
||||
Reference in New Issue
Block a user