mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-07 12:00:44 +08:00
Fix: Remove the pagination from the search and retrieval pages. (#15942)
### What problem does this PR solve? Fix: Remove the pagination from the search and retrieval pages. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@@ -1440,6 +1440,7 @@ async def search_datasets(tenant_id: str, req: dict):
|
||||
except Exception:
|
||||
logging.warning("search_datasets KG retrieval failed: datasets=%s tenant=%s", kb_ids, tenant_id, exc_info=True)
|
||||
ranks["chunks"] = settings.retriever.retrieval_by_children(ranks["chunks"], tenant_ids)
|
||||
ranks["total"] = len(ranks["chunks"])
|
||||
|
||||
for c in ranks["chunks"]:
|
||||
c.pop("vector", None)
|
||||
|
||||
38
web/src/components/top-select.tsx
Normal file
38
web/src/components/top-select.tsx
Normal file
@@ -0,0 +1,38 @@
|
||||
import { useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { SelectWithSearch } from './originui/select-with-search';
|
||||
import { RAGFlowFormItem } from './ragflow-form';
|
||||
|
||||
type TopSelectProps = {
|
||||
value?: number;
|
||||
onChange?(value: number): void;
|
||||
};
|
||||
|
||||
export function TopSelect({ value = 10, onChange }: TopSelectProps) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const sizeChangerOptions = useMemo(() => {
|
||||
return [10, 20, 50, 100].map((x) => ({
|
||||
label: <span>{t('common.top', { top: x })}</span>,
|
||||
value: x.toString(),
|
||||
}));
|
||||
}, [t]);
|
||||
|
||||
return (
|
||||
<SelectWithSearch
|
||||
options={sizeChangerOptions}
|
||||
value={value.toString()}
|
||||
onChange={(val) => onChange?.(Number(val))}
|
||||
></SelectWithSearch>
|
||||
);
|
||||
}
|
||||
|
||||
export function TopSelectFormItem() {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<RAGFlowFormItem label={t('knowledgeConfiguration.top')} name="size">
|
||||
<TopSelect></TopSelect>
|
||||
</RAGFlowFormItem>
|
||||
);
|
||||
}
|
||||
@@ -64,19 +64,15 @@ export const useTestRetrieval = () => {
|
||||
const [values, setValues] = useState<ITestRetrievalRequestBody>();
|
||||
const { filterValue, setFilterValue } = useHandleFilterSubmit();
|
||||
|
||||
const [page, setPage] = useState(1);
|
||||
const [pageSize, setPageSize] = useState(10);
|
||||
|
||||
const queryParams = useMemo(() => {
|
||||
return {
|
||||
...values,
|
||||
kb_id: values?.kb_id || knowledgeBaseId,
|
||||
page,
|
||||
size: pageSize,
|
||||
page: 1,
|
||||
doc_ids: filterValue.doc_ids,
|
||||
highlight: true,
|
||||
};
|
||||
}, [filterValue, knowledgeBaseId, page, pageSize, values]);
|
||||
}, [filterValue, knowledgeBaseId, values]);
|
||||
|
||||
const mutation = useMutation<INextTestingResult, Error, typeof queryParams>({
|
||||
mutationFn: async (params) => {
|
||||
@@ -87,30 +83,15 @@ export const useTestRetrieval = () => {
|
||||
});
|
||||
|
||||
const refetch = useCallback(() => {
|
||||
setPage(1);
|
||||
if (queryParams.question) {
|
||||
const newParams = { ...queryParams, page: 1 };
|
||||
mutation.mutate(newParams);
|
||||
}
|
||||
}, [mutation, queryParams]);
|
||||
|
||||
const onPaginationChange = useCallback(
|
||||
(newPage: number, newPageSize: number) => {
|
||||
const nextPage = newPageSize !== pageSize ? 1 : newPage;
|
||||
setPage(nextPage);
|
||||
setPageSize(newPageSize);
|
||||
if (mutation.data && queryParams.question) {
|
||||
const newParams = { ...queryParams, page: nextPage, size: newPageSize };
|
||||
mutation.mutate(newParams);
|
||||
}
|
||||
},
|
||||
[mutation, queryParams, pageSize],
|
||||
);
|
||||
|
||||
const handleFilterSubmit = useCallback(
|
||||
(value: { doc_ids?: string[] }) => {
|
||||
setFilterValue(value);
|
||||
setPage(1);
|
||||
if (mutation.data && queryParams.question) {
|
||||
const newParams = {
|
||||
...queryParams,
|
||||
@@ -139,9 +120,6 @@ export const useTestRetrieval = () => {
|
||||
loading: mutation.isPending,
|
||||
setValues,
|
||||
refetch,
|
||||
onPaginationChange,
|
||||
page,
|
||||
pageSize,
|
||||
handleFilterSubmit,
|
||||
filterValue,
|
||||
};
|
||||
|
||||
@@ -14,6 +14,7 @@ export default {
|
||||
yes: 'Yes',
|
||||
no: 'No',
|
||||
total: 'Total',
|
||||
top: 'Top {{top}}',
|
||||
rename: 'Rename',
|
||||
name: 'Name',
|
||||
save: 'Save',
|
||||
@@ -914,6 +915,7 @@ This auto-tagging feature enhances retrieval by adding another layer of domain-s
|
||||
theDocumentBeingParsedCannotBeDeleted:
|
||||
'The document being parsed cannot be deleted',
|
||||
lastWeek: 'from last week',
|
||||
top: 'Top',
|
||||
},
|
||||
chunk: {
|
||||
type: 'Type',
|
||||
|
||||
@@ -14,6 +14,7 @@ export default {
|
||||
yes: '是',
|
||||
no: '否',
|
||||
total: '总共',
|
||||
top: '前 {{top}} 条',
|
||||
rename: '重命名',
|
||||
name: '名称',
|
||||
save: '保存',
|
||||
@@ -826,6 +827,7 @@ NER:使用 spaCy NER 和基于规则的关键词提取来抽取实体和关系
|
||||
community: '社区报告生成',
|
||||
communityTip:
|
||||
'区块被聚集成层次化的社区,实体和关系通过更高抽象层次将每个部分连接起来。然后,我们使用 LLM 生成每个社区的摘要,称为社区报告。更多信息:https://www.microsoft.com/en-us/research/blog/graphrag-improving-global-search-via-dynamic-community-selection/',
|
||||
top: '前n条',
|
||||
},
|
||||
chunk: {
|
||||
chunk: '解析块',
|
||||
|
||||
@@ -12,17 +12,8 @@ import TestingForm from './testing-form';
|
||||
import { TestingResult } from './testing-result';
|
||||
|
||||
export default function RetrievalTesting() {
|
||||
const {
|
||||
loading,
|
||||
setValues,
|
||||
refetch,
|
||||
data,
|
||||
onPaginationChange,
|
||||
page,
|
||||
pageSize,
|
||||
handleFilterSubmit,
|
||||
filterValue,
|
||||
} = useTestRetrieval();
|
||||
const { loading, setValues, refetch, data, handleFilterSubmit, filterValue } =
|
||||
useTestRetrieval();
|
||||
|
||||
const [count] = useState(1); // TODO: Different layouts are needed; if they are no longer required, consider deleting them.
|
||||
|
||||
@@ -62,12 +53,9 @@ export default function RetrievalTesting() {
|
||||
<div className="flex-1">
|
||||
<TestingResult
|
||||
data={data}
|
||||
page={page}
|
||||
loading={loading}
|
||||
pageSize={pageSize}
|
||||
filterValue={filterValue}
|
||||
handleFilterSubmit={handleFilterSubmit}
|
||||
onPaginationChange={onPaginationChange}
|
||||
/>
|
||||
</div>
|
||||
</CardContent>
|
||||
@@ -81,12 +69,9 @@ export default function RetrievalTesting() {
|
||||
></TestingForm>
|
||||
<TestingResult
|
||||
data={data}
|
||||
page={page}
|
||||
loading={loading}
|
||||
pageSize={pageSize}
|
||||
filterValue={filterValue}
|
||||
handleFilterSubmit={handleFilterSubmit}
|
||||
onPaginationChange={onPaginationChange}
|
||||
></TestingResult>
|
||||
</div>
|
||||
<div className="flex-1">
|
||||
@@ -97,12 +82,9 @@ export default function RetrievalTesting() {
|
||||
></TestingForm>
|
||||
<TestingResult
|
||||
data={data}
|
||||
page={page}
|
||||
loading={loading}
|
||||
pageSize={pageSize}
|
||||
filterValue={filterValue}
|
||||
handleFilterSubmit={handleFilterSubmit}
|
||||
onPaginationChange={onPaginationChange}
|
||||
></TestingResult>
|
||||
</div>
|
||||
</CardContent>
|
||||
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
similarityThresholdSchema,
|
||||
vectorSimilarityWeightSchema,
|
||||
} from '@/components/similarity-slider';
|
||||
import { TopSelectFormItem } from '@/components/top-select';
|
||||
import { ButtonLoading } from '@/components/ui/button';
|
||||
import {
|
||||
Form,
|
||||
@@ -64,6 +65,7 @@ export default function TestingForm({
|
||||
use_kg: z.boolean().optional(),
|
||||
dataset_ids: z.array(z.string()).optional(),
|
||||
...MetadataFilterSchema,
|
||||
size: z.number().optional(),
|
||||
});
|
||||
|
||||
const form = useForm<z.infer<typeof formSchema>>({
|
||||
@@ -74,6 +76,7 @@ export default function TestingForm({
|
||||
...initialTopKValue,
|
||||
use_kg: false,
|
||||
dataset_ids: [knowledgeBaseId],
|
||||
size: 10,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -106,6 +109,7 @@ export default function TestingForm({
|
||||
name={'cross_languages'}
|
||||
></CrossLanguageFormField>
|
||||
<MetadataFilter prefix=""></MetadataFilter>
|
||||
<TopSelectFormItem></TopSelectFormItem>
|
||||
</FormContainer>
|
||||
</div>
|
||||
|
||||
@@ -115,7 +119,6 @@ export default function TestingForm({
|
||||
name="question"
|
||||
render={({ field }) => (
|
||||
<FormItem>
|
||||
{/* <FormLabel>{t('knowledgeDetails.testText')}</FormLabel> */}
|
||||
<FormControl>
|
||||
<Textarea {...field}></Textarea>
|
||||
</FormControl>
|
||||
|
||||
@@ -4,7 +4,6 @@ import { FilterButton } from '@/components/list-filter-bar';
|
||||
import { FilterPopover } from '@/components/list-filter-bar/filter-popover';
|
||||
import { FilterCollection } from '@/components/list-filter-bar/interface';
|
||||
import { Card } from '@/components/ui/card';
|
||||
import { RAGFlowPagination } from '@/components/ui/ragflow-pagination';
|
||||
import { useTranslate } from '@/hooks/common-hooks';
|
||||
import { useTestRetrieval } from '@/hooks/use-knowledge-request';
|
||||
import { ITestingChunk } from '@/interfaces/database/dataset';
|
||||
@@ -34,22 +33,13 @@ const ChunkTitle = ({ item }: { item: ITestingChunk }) => {
|
||||
|
||||
type TestingResultProps = Pick<
|
||||
ReturnType<typeof useTestRetrieval>,
|
||||
| 'data'
|
||||
| 'filterValue'
|
||||
| 'handleFilterSubmit'
|
||||
| 'page'
|
||||
| 'pageSize'
|
||||
| 'onPaginationChange'
|
||||
| 'loading'
|
||||
'data' | 'filterValue' | 'handleFilterSubmit' | 'loading'
|
||||
>;
|
||||
|
||||
export function TestingResult({
|
||||
filterValue,
|
||||
handleFilterSubmit,
|
||||
page,
|
||||
pageSize,
|
||||
loading,
|
||||
onPaginationChange,
|
||||
data,
|
||||
}: TestingResultProps) {
|
||||
const filters: FilterCollection[] = useMemo(() => {
|
||||
@@ -69,10 +59,13 @@ export function TestingResult({
|
||||
|
||||
return (
|
||||
<article className="size-full flex flex-col">
|
||||
<header className="flex-0 px-5 py-3 flex justify-between">
|
||||
<header className="flex-0 px-5 py-3 flex justify-between items-center">
|
||||
<h2 className="font-semibold text-base leading-8">
|
||||
{t('knowledgeDetails.testResults')}
|
||||
</h2>
|
||||
<span className="mr-auto text-sm text-text-secondary pl-2">
|
||||
{t('common.total')}: {data.total}
|
||||
</span>
|
||||
|
||||
<FilterPopover
|
||||
filters={filters}
|
||||
@@ -96,14 +89,6 @@ export function TestingResult({
|
||||
</article>
|
||||
))}
|
||||
</section>
|
||||
<div className="p-2">
|
||||
<RAGFlowPagination
|
||||
total={data.total}
|
||||
onChange={onPaginationChange}
|
||||
current={page}
|
||||
pageSize={pageSize}
|
||||
></RAGFlowPagination>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{!data.chunks?.length && !loading && (
|
||||
|
||||
@@ -148,10 +148,10 @@ export const useTestChunkRetrieval = (
|
||||
gcTime: 0,
|
||||
mutationFn: async (values: any) => {
|
||||
const { data } = await retrievalTestFunc({
|
||||
...values,
|
||||
kb_id: values.kb_id ?? knowledgeBaseId,
|
||||
page,
|
||||
size: pageSize,
|
||||
...values,
|
||||
kb_id: values.kb_id ?? knowledgeBaseId,
|
||||
tenant_id: tenantId,
|
||||
});
|
||||
if (data.code === 0) {
|
||||
@@ -199,11 +199,10 @@ export const useTestChunkAllRetrieval = (
|
||||
gcTime: 0,
|
||||
mutationFn: async (values: any) => {
|
||||
const { data } = await retrievalTestFunc({
|
||||
...values,
|
||||
kb_id: values.kb_id ?? knowledgeBaseId,
|
||||
doc_ids: [],
|
||||
page,
|
||||
size: pageSize,
|
||||
...values,
|
||||
kb_id: values.kb_id ?? knowledgeBaseId,
|
||||
tenant_id: tenantId,
|
||||
});
|
||||
if (data.code === 0) {
|
||||
@@ -324,14 +323,12 @@ export const useSendQuestion = (
|
||||
const [searchStr, setSearchStr] = useState<string>('');
|
||||
const [isFirstRender, setIsFirstRender] = useState(true);
|
||||
const [selectedDocumentIds, setSelectedDocumentIds] = useState<string[]>([]);
|
||||
|
||||
const { pagination, setPagination } = useGetPaginationWithRouter();
|
||||
const [pageSize, setPageSize] = useState(10);
|
||||
|
||||
const sendQuestion = useCallback(
|
||||
(question: string, enableAI: boolean = true) => {
|
||||
const q = trim(question);
|
||||
if (isEmpty(q)) return;
|
||||
setPagination({ page: 1 });
|
||||
setIsFirstRender(false);
|
||||
setCurrentAnswer({} as IAnswer);
|
||||
if (enableAI) {
|
||||
@@ -352,7 +349,7 @@ export const useSendQuestion = (
|
||||
highlight: true,
|
||||
question: q,
|
||||
page: 1,
|
||||
size: pagination.pageSize,
|
||||
size: pageSize,
|
||||
search_id: searchId,
|
||||
});
|
||||
|
||||
@@ -366,8 +363,7 @@ export const useSendQuestion = (
|
||||
askUrl,
|
||||
kbIds,
|
||||
fetchRelatedQuestions,
|
||||
setPagination,
|
||||
pagination.pageSize,
|
||||
pageSize,
|
||||
tenantId,
|
||||
searchId,
|
||||
sharedId,
|
||||
@@ -455,6 +451,8 @@ export const useSendQuestion = (
|
||||
selectedDocumentIds,
|
||||
isSearchStrEmpty: isEmpty(trim(searchStr)),
|
||||
stopOutputMessage,
|
||||
pageSize,
|
||||
setPageSize,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -479,6 +477,8 @@ export const useSearching = ({
|
||||
isSearchStrEmpty,
|
||||
setSearchStr,
|
||||
stopOutputMessage,
|
||||
pageSize,
|
||||
setPageSize,
|
||||
} = useSendQuestion(
|
||||
searchData.search_config.kb_ids,
|
||||
tenantId as string,
|
||||
@@ -537,14 +537,15 @@ export const useSearching = ({
|
||||
],
|
||||
);
|
||||
|
||||
const { pagination, setPagination } = useGetPaginationWithRouter();
|
||||
const onChange = (pageNumber: number, pageSize: number) => {
|
||||
setPagination({ page: pageNumber, pageSize });
|
||||
handleTestChunk(selectedDocumentIds, pageNumber, pageSize);
|
||||
};
|
||||
const handleTopChange = useCallback(
|
||||
(size: number) => {
|
||||
setPageSize(size);
|
||||
handleTestChunk(selectedDocumentIds, 1, size);
|
||||
},
|
||||
[handleTestChunk, selectedDocumentIds, setPageSize],
|
||||
);
|
||||
|
||||
return {
|
||||
sendQuestion,
|
||||
handleClickRelatedQuestion,
|
||||
handleSearchStrChange,
|
||||
handleTestChunk,
|
||||
@@ -573,8 +574,8 @@ export const useSearching = ({
|
||||
chunks,
|
||||
total,
|
||||
handleSearch,
|
||||
pagination,
|
||||
onChange,
|
||||
pageSize,
|
||||
handleTopChange,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@ import { FileIcon } from '@/components/icon-font';
|
||||
import { ImageWithPopover } from '@/components/image';
|
||||
import { Input } from '@/components/originui/input';
|
||||
import { SkeletonCard } from '@/components/skeleton-card';
|
||||
import { TopSelect } from '@/components/top-select';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Popover,
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from '@/components/ui/popover';
|
||||
import { RAGFlowPagination } from '@/components/ui/ragflow-pagination';
|
||||
import { IReference } from '@/interfaces/database/chat';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { isEmpty } from 'lodash';
|
||||
@@ -61,8 +61,8 @@ export default function SearchingView({
|
||||
chunks,
|
||||
total,
|
||||
handleSearch,
|
||||
pagination,
|
||||
onChange,
|
||||
pageSize,
|
||||
handleTopChange,
|
||||
showEmbedLogo,
|
||||
}: ISearchReturnProps & {
|
||||
setIsSearching?: Dispatch<SetStateAction<boolean>>;
|
||||
@@ -183,8 +183,8 @@ export default function SearchingView({
|
||||
)}
|
||||
{/* retrieval documents */}
|
||||
{!isSearchStrEmpty && !sendingLoading && (
|
||||
<>
|
||||
<div className=" mt-3 w-44 ">
|
||||
<section className="flex justify-start items-center gap-4">
|
||||
<div className="w-44 ">
|
||||
<RetrievalDocuments
|
||||
selectedDocumentIds={selectedDocumentIds}
|
||||
setSelectedDocumentIds={setSelectedDocumentIds}
|
||||
@@ -194,8 +194,16 @@ export default function SearchingView({
|
||||
}}
|
||||
></RetrievalDocuments>
|
||||
</div>
|
||||
{/* <div className="w-full border-b border-border-default/80 my-6"></div> */}
|
||||
</>
|
||||
<div className="w-44">
|
||||
<TopSelect
|
||||
value={pageSize}
|
||||
onChange={handleTopChange}
|
||||
></TopSelect>
|
||||
</div>
|
||||
<span className="ml-auto text-sm text-text-secondary pr-2">
|
||||
{t('common.total')}: {total}
|
||||
</span>
|
||||
</section>
|
||||
)}
|
||||
<div className="mt-3 ">
|
||||
{chunks?.length > 0 && (
|
||||
@@ -293,17 +301,6 @@ export default function SearchingView({
|
||||
)}
|
||||
</div>
|
||||
|
||||
{total > 0 && (
|
||||
<div className="mt-8 px-8 pb-8 text-base">
|
||||
<RAGFlowPagination
|
||||
current={pagination.current}
|
||||
pageSize={pagination.pageSize}
|
||||
total={total}
|
||||
onChange={onChange}
|
||||
></RAGFlowPagination>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{!mindMapVisible &&
|
||||
!isFirstRender &&
|
||||
!isSearchStrEmpty &&
|
||||
|
||||
Reference in New Issue
Block a user