mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
### What problem does this PR solve? feat(search): Optimized search functionality and user interface #3221 ### Type of change - Added similarity threshold adjustment function - Optimized mind map display logic - Adjusted search settings interface layout - Fixed related search and document viewing functions - Optimized time display and node selection logic - [x] Bug Fix (non-breaking change which fixes an issue)
This commit is contained in:
@ -7,4 +7,5 @@ export interface IFeedbackRequestBody {
|
|||||||
export interface IAskRequestBody {
|
export interface IAskRequestBody {
|
||||||
question: string;
|
question: string;
|
||||||
kb_ids: string[];
|
kb_ids: string[];
|
||||||
|
search_id?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
import { RAGFlowAvatar } from '@/components/ragflow-avatar';
|
import { RAGFlowAvatar } from '@/components/ragflow-avatar';
|
||||||
import { useTheme } from '@/components/theme-provider';
|
import { useTheme } from '@/components/theme-provider';
|
||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
DropdownMenu,
|
DropdownMenu,
|
||||||
@ -163,9 +162,10 @@ export function Header() {
|
|||||||
className="size-8 cursor-pointer"
|
className="size-8 cursor-pointer"
|
||||||
onClick={navigateToProfile}
|
onClick={navigateToProfile}
|
||||||
></RAGFlowAvatar>
|
></RAGFlowAvatar>
|
||||||
<Badge className="h-5 w-8 absolute font-normal p-0 justify-center -right-8 -top-2 text-bg-base bg-gradient-to-l from-[#42D7E7] to-[#478AF5]">
|
{/* Temporarily hidden */}
|
||||||
|
{/* <Badge className="h-5 w-8 absolute font-normal p-0 justify-center -right-8 -top-2 text-bg-base bg-gradient-to-l from-[#42D7E7] to-[#478AF5]">
|
||||||
Pro
|
Pro
|
||||||
</Badge>
|
</Badge> */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@ -1437,6 +1437,8 @@ This delimiter is used to split the input text into several text pieces echo of
|
|||||||
showQueryMindmap: 'Show Query Mindmap',
|
showQueryMindmap: 'Show Query Mindmap',
|
||||||
embedApp: 'Embed App',
|
embedApp: 'Embed App',
|
||||||
relatedSearch: 'Related Search',
|
relatedSearch: 'Related Search',
|
||||||
|
okText: 'Save',
|
||||||
|
cancelText: 'Cancel',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1341,6 +1341,8 @@ General:实体和关系提取提示来自 GitHub - microsoft/graphrag:基于
|
|||||||
showQueryMindmap: '显示查询思维导图',
|
showQueryMindmap: '显示查询思维导图',
|
||||||
embedApp: '嵌入网站',
|
embedApp: '嵌入网站',
|
||||||
relatedSearch: '相关搜索',
|
relatedSearch: '相关搜索',
|
||||||
|
okText: '保存',
|
||||||
|
cancelText: '返回',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@ -242,7 +242,7 @@ export function InnerNextStepDropdown({
|
|||||||
}}
|
}}
|
||||||
onClick={(e) => e.stopPropagation()}
|
onClick={(e) => e.stopPropagation()}
|
||||||
>
|
>
|
||||||
<div className="w-[300px] font-semibold bg-white border border-border rounded-md shadow-lg">
|
<div className="w-[300px] font-semibold bg-bg-base border border-border rounded-md shadow-lg">
|
||||||
<div className="px-3 py-2 border-b border-border">
|
<div className="px-3 py-2 border-b border-border">
|
||||||
<div className="text-sm font-medium">Next Step</div>
|
<div className="text-sm font-medium">Next Step</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -158,8 +158,9 @@ const ToolTimelineItem = ({
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
<span className="text-text-secondary text-xs">
|
<span className="text-text-secondary text-xs">
|
||||||
{/* 0:00
|
{/* 0:00*/}
|
||||||
{x.data.elapsed_time?.toString().slice(0, 6)} */}
|
{tool.elapsed_time?.toString().slice(0, 6) || ''}
|
||||||
|
{tool.elapsed_time ? 's' : ''}
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
|
|||||||
@ -153,6 +153,22 @@ export const WorkFlowTimeline = ({
|
|||||||
}, []);
|
}, []);
|
||||||
}, [currentEventListWithoutMessage, sendLoading]);
|
}, [currentEventListWithoutMessage, sendLoading]);
|
||||||
|
|
||||||
|
const getElapsedTime = (nodeId: string) => {
|
||||||
|
if (nodeId === 'begin') {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
const data = currentEventListWithoutMessage?.find((x) => {
|
||||||
|
return (
|
||||||
|
x.data.component_id === nodeId &&
|
||||||
|
x.event === MessageEventType.NodeFinished
|
||||||
|
);
|
||||||
|
});
|
||||||
|
if (!data || data?.data.elapsed_time < 0.000001) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
return data?.data.elapsed_time || '';
|
||||||
|
};
|
||||||
|
|
||||||
const hasTrace = useCallback(
|
const hasTrace = useCallback(
|
||||||
(componentId: string) => {
|
(componentId: string) => {
|
||||||
if (Array.isArray(traceData)) {
|
if (Array.isArray(traceData)) {
|
||||||
@ -272,7 +288,10 @@ export const WorkFlowTimeline = ({
|
|||||||
nodeLabel)}
|
nodeLabel)}
|
||||||
</span>
|
</span>
|
||||||
<span className="text-text-secondary text-xs">
|
<span className="text-text-secondary text-xs">
|
||||||
{x.data.elapsed_time?.toString().slice(0, 6)}
|
{getElapsedTime(x.data.component_id)
|
||||||
|
.toString()
|
||||||
|
.slice(0, 6)}
|
||||||
|
{getElapsedTime(x.data.component_id) ? 's' : ''}
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
className={cn(
|
className={cn(
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
import { useFetchTokenListBeforeOtherStep } from '@/components/embed-dialog/use-show-embed-dialog';
|
|
||||||
import HightLightMarkdown from '@/components/highlight-markdown';
|
import HightLightMarkdown from '@/components/highlight-markdown';
|
||||||
import { Modal } from '@/components/ui/modal/modal';
|
import { Modal } from '@/components/ui/modal/modal';
|
||||||
import { RAGFlowSelect } from '@/components/ui/select';
|
import { RAGFlowSelect } from '@/components/ui/select';
|
||||||
@ -9,7 +8,7 @@ import {
|
|||||||
} from '@/constants/common';
|
} from '@/constants/common';
|
||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
import { message } from 'antd';
|
import { message } from 'antd';
|
||||||
import { useCallback, useEffect, useMemo, useState } from 'react';
|
import { useCallback, useMemo, useState } from 'react';
|
||||||
|
|
||||||
type IEmbedAppModalProps = {
|
type IEmbedAppModalProps = {
|
||||||
open: any;
|
open: any;
|
||||||
@ -18,17 +17,13 @@ type IEmbedAppModalProps = {
|
|||||||
from: string;
|
from: string;
|
||||||
setOpen: (e: any) => void;
|
setOpen: (e: any) => void;
|
||||||
tenantId: string;
|
tenantId: string;
|
||||||
|
beta?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
const EmbedAppModal = (props: IEmbedAppModalProps) => {
|
const EmbedAppModal = (props: IEmbedAppModalProps) => {
|
||||||
const { t } = useTranslate('search');
|
const { t } = useTranslate('search');
|
||||||
const { open, setOpen, token = '', from, url, tenantId } = props;
|
const { open, setOpen, token = '', from, url, tenantId, beta = '' } = props;
|
||||||
const { beta, handleOperate } = useFetchTokenListBeforeOtherStep();
|
|
||||||
useEffect(() => {
|
|
||||||
if (open && !beta) {
|
|
||||||
handleOperate();
|
|
||||||
}
|
|
||||||
}, [handleOperate, open, beta]);
|
|
||||||
const [hideAvatar, setHideAvatar] = useState(false);
|
const [hideAvatar, setHideAvatar] = useState(false);
|
||||||
const [locale, setLocale] = useState('');
|
const [locale, setLocale] = useState('');
|
||||||
|
|
||||||
|
|||||||
@ -234,7 +234,10 @@ export const useTestRetrieval = (
|
|||||||
setSelectedDocumentIds,
|
setSelectedDocumentIds,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
export const useFetchRelatedQuestions = (tenantId?: string) => {
|
export const useFetchRelatedQuestions = (
|
||||||
|
tenantId?: string,
|
||||||
|
searchId?: string,
|
||||||
|
) => {
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
const shared_id = searchParams.get('shared_id');
|
const shared_id = searchParams.get('shared_id');
|
||||||
const retrievalTestFunc = shared_id
|
const retrievalTestFunc = shared_id
|
||||||
@ -251,6 +254,7 @@ export const useFetchRelatedQuestions = (tenantId?: string) => {
|
|||||||
const { data } = await retrievalTestFunc({
|
const { data } = await retrievalTestFunc({
|
||||||
question,
|
question,
|
||||||
tenant_id: tenantId,
|
tenant_id: tenantId,
|
||||||
|
search_id: searchId,
|
||||||
});
|
});
|
||||||
|
|
||||||
return data?.data ?? [];
|
return data?.data ?? [];
|
||||||
@ -260,7 +264,12 @@ export const useFetchRelatedQuestions = (tenantId?: string) => {
|
|||||||
return { data, loading, fetchRelatedQuestions: mutateAsync };
|
return { data, loading, fetchRelatedQuestions: mutateAsync };
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useSendQuestion = (kbIds: string[], tenantId?: string) => {
|
export const useSendQuestion = (
|
||||||
|
kbIds: string[],
|
||||||
|
tenantId?: string,
|
||||||
|
searchId: string = '',
|
||||||
|
related_search: boolean = false,
|
||||||
|
) => {
|
||||||
const { sharedId } = useGetSharedSearchParams();
|
const { sharedId } = useGetSharedSearchParams();
|
||||||
const { send, answer, done, stopOutputMessage } = useSendMessageWithSse(
|
const { send, answer, done, stopOutputMessage } = useSendMessageWithSse(
|
||||||
sharedId ? api.askShare : api.ask,
|
sharedId ? api.askShare : api.ask,
|
||||||
@ -271,7 +280,7 @@ export const useSendQuestion = (kbIds: string[], tenantId?: string) => {
|
|||||||
const [sendingLoading, setSendingLoading] = useState(false);
|
const [sendingLoading, setSendingLoading] = useState(false);
|
||||||
const [currentAnswer, setCurrentAnswer] = useState({} as IAnswer);
|
const [currentAnswer, setCurrentAnswer] = useState({} as IAnswer);
|
||||||
const { fetchRelatedQuestions, data: relatedQuestions } =
|
const { fetchRelatedQuestions, data: relatedQuestions } =
|
||||||
useFetchRelatedQuestions(tenantId);
|
useFetchRelatedQuestions(tenantId, searchId);
|
||||||
const [searchStr, setSearchStr] = useState<string>('');
|
const [searchStr, setSearchStr] = useState<string>('');
|
||||||
const [isFirstRender, setIsFirstRender] = useState(true);
|
const [isFirstRender, setIsFirstRender] = useState(true);
|
||||||
const [selectedDocumentIds, setSelectedDocumentIds] = useState<string[]>([]);
|
const [selectedDocumentIds, setSelectedDocumentIds] = useState<string[]>([]);
|
||||||
@ -286,7 +295,7 @@ export const useSendQuestion = (kbIds: string[], tenantId?: string) => {
|
|||||||
setIsFirstRender(false);
|
setIsFirstRender(false);
|
||||||
setCurrentAnswer({} as IAnswer);
|
setCurrentAnswer({} as IAnswer);
|
||||||
setSendingLoading(true);
|
setSendingLoading(true);
|
||||||
send({ kb_ids: kbIds, question: q, tenantId });
|
send({ kb_ids: kbIds, question: q, tenantId, search_id: searchId });
|
||||||
testChunk({
|
testChunk({
|
||||||
kb_id: kbIds,
|
kb_id: kbIds,
|
||||||
highlight: true,
|
highlight: true,
|
||||||
@ -295,7 +304,9 @@ export const useSendQuestion = (kbIds: string[], tenantId?: string) => {
|
|||||||
size: pagination.pageSize,
|
size: pagination.pageSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
fetchRelatedQuestions(q);
|
if (related_search) {
|
||||||
|
fetchRelatedQuestions(q);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
send,
|
send,
|
||||||
@ -305,6 +316,8 @@ export const useSendQuestion = (kbIds: string[], tenantId?: string) => {
|
|||||||
setPagination,
|
setPagination,
|
||||||
pagination.pageSize,
|
pagination.pageSize,
|
||||||
tenantId,
|
tenantId,
|
||||||
|
searchId,
|
||||||
|
related_search,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -408,7 +421,12 @@ export const useSearching = ({
|
|||||||
isSearchStrEmpty,
|
isSearchStrEmpty,
|
||||||
setSearchStr,
|
setSearchStr,
|
||||||
stopOutputMessage,
|
stopOutputMessage,
|
||||||
} = useSendQuestion(searchData.search_config.kb_ids, tenantId as string);
|
} = useSendQuestion(
|
||||||
|
searchData.search_config.kb_ids,
|
||||||
|
tenantId as string,
|
||||||
|
searchData.id,
|
||||||
|
searchData.search_config.related_search,
|
||||||
|
);
|
||||||
|
|
||||||
const handleSearchStrChange = useCallback(
|
const handleSearchStrChange = useCallback(
|
||||||
(value: string) => {
|
(value: string) => {
|
||||||
@ -435,15 +453,20 @@ export const useSearching = ({
|
|||||||
showMindMapModal,
|
showMindMapModal,
|
||||||
mindMapLoading,
|
mindMapLoading,
|
||||||
mindMap,
|
mindMap,
|
||||||
} = useShowMindMapDrawer(searchData.search_config.kb_ids, searchStr);
|
} = useShowMindMapDrawer(
|
||||||
|
searchData.search_config.kb_ids,
|
||||||
|
searchStr,
|
||||||
|
searchData.id,
|
||||||
|
);
|
||||||
const { chunks, total } = useSelectTestingResult();
|
const { chunks, total } = useSelectTestingResult();
|
||||||
|
|
||||||
const handleSearch = useCallback(
|
const handleSearch = useCallback(
|
||||||
(value: string) => {
|
(value: string) => {
|
||||||
sendQuestion(value);
|
sendQuestion(value);
|
||||||
setSearchStr?.(value);
|
setSearchStr?.(value);
|
||||||
|
hideMindMapModal();
|
||||||
},
|
},
|
||||||
[setSearchStr, sendQuestion],
|
[setSearchStr, sendQuestion, hideMindMapModal],
|
||||||
);
|
);
|
||||||
|
|
||||||
const { pagination, setPagination } = useGetPaginationWithRouter();
|
const { pagination, setPagination } = useGetPaginationWithRouter();
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
import { useFetchTokenListBeforeOtherStep } from '@/components/embed-dialog/use-show-embed-dialog';
|
||||||
import { PageHeader } from '@/components/page-header';
|
import { PageHeader } from '@/components/page-header';
|
||||||
import {
|
import {
|
||||||
Breadcrumb,
|
Breadcrumb,
|
||||||
@ -10,7 +11,10 @@ import {
|
|||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { SharedFrom } from '@/constants/chat';
|
import { SharedFrom } from '@/constants/chat';
|
||||||
import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';
|
import { useNavigatePage } from '@/hooks/logic-hooks/navigate-hooks';
|
||||||
import { useFetchTenantInfo } from '@/hooks/user-setting-hooks';
|
import {
|
||||||
|
useFetchTenantInfo,
|
||||||
|
useFetchUserInfo,
|
||||||
|
} from '@/hooks/user-setting-hooks';
|
||||||
import { Send, Settings } from 'lucide-react';
|
import { Send, Settings } from 'lucide-react';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
@ -29,11 +33,13 @@ export default function SearchPage() {
|
|||||||
const { navigateToSearchList } = useNavigatePage();
|
const { navigateToSearchList } = useNavigatePage();
|
||||||
const [isSearching, setIsSearching] = useState(false);
|
const [isSearching, setIsSearching] = useState(false);
|
||||||
const { data: SearchData } = useFetchSearchDetail();
|
const { data: SearchData } = useFetchSearchDetail();
|
||||||
|
const { beta, handleOperate } = useFetchTokenListBeforeOtherStep();
|
||||||
|
|
||||||
const [openSetting, setOpenSetting] = useState(false);
|
const [openSetting, setOpenSetting] = useState(false);
|
||||||
const [openEmbed, setOpenEmbed] = useState(false);
|
const [openEmbed, setOpenEmbed] = useState(false);
|
||||||
const [searchText, setSearchText] = useState('');
|
const [searchText, setSearchText] = useState('');
|
||||||
const { data: tenantInfo } = useFetchTenantInfo();
|
const { data: tenantInfo } = useFetchTenantInfo();
|
||||||
|
const { data: userInfo } = useFetchUserInfo();
|
||||||
const tenantId = tenantInfo.tenant_id;
|
const tenantId = tenantInfo.tenant_id;
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { openSetting: checkOpenSetting } = useCheckSettings(
|
const { openSetting: checkOpenSetting } = useCheckSettings(
|
||||||
@ -75,6 +81,7 @@ export default function SearchPage() {
|
|||||||
isSearching={isSearching}
|
isSearching={isSearching}
|
||||||
searchText={searchText}
|
searchText={searchText}
|
||||||
setSearchText={setSearchText}
|
setSearchText={setSearchText}
|
||||||
|
userInfo={userInfo}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -105,6 +112,7 @@ export default function SearchPage() {
|
|||||||
token={SearchData?.id as string}
|
token={SearchData?.id as string}
|
||||||
from={SharedFrom.Search}
|
from={SharedFrom.Search}
|
||||||
tenantId={tenantId}
|
tenantId={tenantId}
|
||||||
|
beta={beta}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
@ -121,7 +129,14 @@ export default function SearchPage() {
|
|||||||
<div className="absolute right-5 top-12 ">
|
<div className="absolute right-5 top-12 ">
|
||||||
<Button
|
<Button
|
||||||
className="bg-text-primary text-bg-base border-b-[#00BEB4] border-b-2"
|
className="bg-text-primary text-bg-base border-b-[#00BEB4] border-b-2"
|
||||||
onClick={() => setOpenEmbed(!openEmbed)}
|
onClick={() => {
|
||||||
|
handleOperate().then((res) => {
|
||||||
|
console.log(res, 'res');
|
||||||
|
if (res) {
|
||||||
|
setOpenEmbed(!openEmbed);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<Send />
|
<Send />
|
||||||
<div>{t('search.embedApp')}</div>
|
<div>{t('search.embedApp')}</div>
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import { IReference, IReferenceChunk } from '@/interfaces/database/chat';
|
|||||||
import { getExtension } from '@/utils/document-util';
|
import { getExtension } from '@/utils/document-util';
|
||||||
import { InfoCircleOutlined } from '@ant-design/icons';
|
import { InfoCircleOutlined } from '@ant-design/icons';
|
||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
import { useCallback, useEffect, useMemo } from 'react';
|
import { memo, useCallback, useEffect, useMemo } from 'react';
|
||||||
import Markdown from 'react-markdown';
|
import Markdown from 'react-markdown';
|
||||||
import reactStringReplace from 'react-string-replace';
|
import reactStringReplace from 'react-string-replace';
|
||||||
import SyntaxHighlighter from 'react-syntax-highlighter';
|
import SyntaxHighlighter from 'react-syntax-highlighter';
|
||||||
@ -82,18 +82,18 @@ const MarkdownContent = ({
|
|||||||
(
|
(
|
||||||
documentId: string,
|
documentId: string,
|
||||||
chunk: IReferenceChunk,
|
chunk: IReferenceChunk,
|
||||||
isPdf: boolean,
|
// isPdf: boolean,
|
||||||
documentUrl?: string,
|
// documentUrl?: string,
|
||||||
) =>
|
) =>
|
||||||
() => {
|
() => {
|
||||||
if (!isPdf) {
|
// if (!isPdf) {
|
||||||
if (!documentUrl) {
|
// if (!documentUrl) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
window.open(documentUrl, '_blank');
|
// window.open(documentUrl, '_blank');
|
||||||
} else {
|
// } else {
|
||||||
clickDocumentButton?.(documentId, chunk);
|
clickDocumentButton?.(documentId, chunk);
|
||||||
}
|
// }
|
||||||
},
|
},
|
||||||
[clickDocumentButton],
|
[clickDocumentButton],
|
||||||
);
|
);
|
||||||
@ -144,7 +144,6 @@ const MarkdownContent = ({
|
|||||||
const getPopoverContent = useCallback(
|
const getPopoverContent = useCallback(
|
||||||
(chunkIndex: number) => {
|
(chunkIndex: number) => {
|
||||||
const {
|
const {
|
||||||
documentUrl,
|
|
||||||
fileThumbnail,
|
fileThumbnail,
|
||||||
fileExtension,
|
fileExtension,
|
||||||
imageId,
|
imageId,
|
||||||
@ -198,8 +197,8 @@ const MarkdownContent = ({
|
|||||||
onClick={handleDocumentButtonClick(
|
onClick={handleDocumentButtonClick(
|
||||||
documentId,
|
documentId,
|
||||||
chunkItem,
|
chunkItem,
|
||||||
fileExtension === 'pdf',
|
// fileExtension === 'pdf',
|
||||||
documentUrl,
|
// documentUrl,
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
{document?.doc_name}
|
{document?.doc_name}
|
||||||
@ -218,8 +217,7 @@ const MarkdownContent = ({
|
|||||||
let replacedText = reactStringReplace(text, currentReg, (match, i) => {
|
let replacedText = reactStringReplace(text, currentReg, (match, i) => {
|
||||||
const chunkIndex = getChunkIndex(match);
|
const chunkIndex = getChunkIndex(match);
|
||||||
|
|
||||||
const { documentUrl, fileExtension, imageId, chunkItem, documentId } =
|
const { imageId, chunkItem, documentId } = getReferenceInfo(chunkIndex);
|
||||||
getReferenceInfo(chunkIndex);
|
|
||||||
|
|
||||||
const docType = chunkItem?.doc_type;
|
const docType = chunkItem?.doc_type;
|
||||||
|
|
||||||
@ -232,8 +230,8 @@ const MarkdownContent = ({
|
|||||||
? handleDocumentButtonClick(
|
? handleDocumentButtonClick(
|
||||||
documentId,
|
documentId,
|
||||||
chunkItem,
|
chunkItem,
|
||||||
fileExtension === 'pdf',
|
// fileExtension === 'pdf',
|
||||||
documentUrl,
|
// documentUrl,
|
||||||
)
|
)
|
||||||
: () => {}
|
: () => {}
|
||||||
}
|
}
|
||||||
@ -243,7 +241,9 @@ const MarkdownContent = ({
|
|||||||
<PopoverTrigger>
|
<PopoverTrigger>
|
||||||
<InfoCircleOutlined className={styles.referenceIcon} />
|
<InfoCircleOutlined className={styles.referenceIcon} />
|
||||||
</PopoverTrigger>
|
</PopoverTrigger>
|
||||||
<PopoverContent>{getPopoverContent(chunkIndex)}</PopoverContent>
|
<PopoverContent className="!w-fit">
|
||||||
|
{getPopoverContent(chunkIndex)}
|
||||||
|
</PopoverContent>
|
||||||
</Popover>
|
</Popover>
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@ -292,4 +292,4 @@ const MarkdownContent = ({
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default MarkdownContent;
|
export default memo(MarkdownContent);
|
||||||
|
|||||||
@ -27,7 +27,7 @@ const MindMapDrawer = ({ data, hideModal, visible, loading }: IProps) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{loading && (
|
{loading && (
|
||||||
<div className="absolute top-48">
|
<div className=" rounded-lg p-4 w-full h-full">
|
||||||
<Progress value={percent} className="h-1 flex-1 min-w-10" />
|
<Progress value={percent} className="h-1 flex-1 min-w-10" />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { Input } from '@/components/originui/input';
|
import { Input } from '@/components/originui/input';
|
||||||
import { useFetchUserInfo } from '@/hooks/user-setting-hooks';
|
import { IUserInfo } from '@/interfaces/database/user-setting';
|
||||||
import { cn } from '@/lib/utils';
|
import { cn } from '@/lib/utils';
|
||||||
import { Search } from 'lucide-react';
|
import { Search } from 'lucide-react';
|
||||||
import { Dispatch, SetStateAction } from 'react';
|
import { Dispatch, SetStateAction } from 'react';
|
||||||
@ -12,13 +12,15 @@ export default function SearchPage({
|
|||||||
setIsSearching,
|
setIsSearching,
|
||||||
searchText,
|
searchText,
|
||||||
setSearchText,
|
setSearchText,
|
||||||
|
userInfo,
|
||||||
}: {
|
}: {
|
||||||
isSearching: boolean;
|
isSearching: boolean;
|
||||||
setIsSearching: Dispatch<SetStateAction<boolean>>;
|
setIsSearching: Dispatch<SetStateAction<boolean>>;
|
||||||
searchText: string;
|
searchText: string;
|
||||||
setSearchText: Dispatch<SetStateAction<string>>;
|
setSearchText: Dispatch<SetStateAction<string>>;
|
||||||
|
userInfo?: IUserInfo;
|
||||||
}) {
|
}) {
|
||||||
const { data: userInfo } = useFetchUserInfo();
|
// const { data: userInfo } = useFetchUserInfo();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
return (
|
return (
|
||||||
<section className="relative w-full flex transition-all justify-center items-center mt-32">
|
<section className="relative w-full flex transition-all justify-center items-center mt-32">
|
||||||
@ -38,7 +40,11 @@ export default function SearchPage({
|
|||||||
<>
|
<>
|
||||||
<p className="mb-4 transition-opacity">👋 Hi there</p>
|
<p className="mb-4 transition-opacity">👋 Hi there</p>
|
||||||
<p className="mb-10 transition-opacity">
|
<p className="mb-10 transition-opacity">
|
||||||
{t('search.welcomeBack')}, {userInfo?.nickname}
|
{userInfo && (
|
||||||
|
<>
|
||||||
|
{t('search.welcomeBack')}, {userInfo.nickname}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</p>
|
</p>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import {
|
|||||||
} from '@/components/ui/multi-select';
|
} from '@/components/ui/multi-select';
|
||||||
import { RAGFlowSelect } from '@/components/ui/select';
|
import { RAGFlowSelect } from '@/components/ui/select';
|
||||||
import { Switch } from '@/components/ui/switch';
|
import { Switch } from '@/components/ui/switch';
|
||||||
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
import { useFetchKnowledgeList } from '@/hooks/knowledge-hooks';
|
import { useFetchKnowledgeList } from '@/hooks/knowledge-hooks';
|
||||||
import {
|
import {
|
||||||
useComposeLlmOptionsByModelTypes,
|
useComposeLlmOptionsByModelTypes,
|
||||||
@ -64,7 +65,7 @@ const SearchSettingFormSchema = z
|
|||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
search_config: z.object({
|
search_config: z.object({
|
||||||
kb_ids: z.array(z.string()).min(1, 'At least one dataset is required'),
|
kb_ids: z.array(z.string()).min(1, 'At least one dataset is required'),
|
||||||
vector_similarity_weight: z.number().min(0).max(100),
|
vector_similarity_weight: z.number().min(0).max(1),
|
||||||
web_search: z.boolean(),
|
web_search: z.boolean(),
|
||||||
similarity_threshold: z.number(),
|
similarity_threshold: z.number(),
|
||||||
use_kg: z.boolean(),
|
use_kg: z.boolean(),
|
||||||
@ -128,7 +129,7 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
|||||||
: 0.3) || 0.3,
|
: 0.3) || 0.3,
|
||||||
web_search: search_config?.web_search || false,
|
web_search: search_config?.web_search || false,
|
||||||
doc_ids: [],
|
doc_ids: [],
|
||||||
similarity_threshold: 0.0,
|
similarity_threshold: search_config?.similarity_threshold || 0.2,
|
||||||
use_kg: false,
|
use_kg: false,
|
||||||
rerank_id: search_config?.rerank_id || '',
|
rerank_id: search_config?.rerank_id || '',
|
||||||
use_rerank: search_config?.rerank_id ? true : false,
|
use_rerank: search_config?.rerank_id ? true : false,
|
||||||
@ -417,7 +418,7 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
|||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>{t('search.description')}</FormLabel>
|
<FormLabel>{t('search.description')}</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Input
|
<Textarea
|
||||||
placeholder="You are an intelligent assistant."
|
placeholder="You are an intelligent assistant."
|
||||||
{...field}
|
{...field}
|
||||||
onFocus={() => {
|
onFocus={() => {
|
||||||
@ -466,7 +467,41 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
|||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
|
<FormField
|
||||||
|
control={formMethods.control}
|
||||||
|
name="search_config.similarity_threshold"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>Similarity Threshold</FormLabel>
|
||||||
|
<div
|
||||||
|
className={cn(
|
||||||
|
'flex items-center gap-4 justify-between',
|
||||||
|
className,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<FormControl>
|
||||||
|
<SingleFormSlider
|
||||||
|
{...field}
|
||||||
|
max={1}
|
||||||
|
min={0}
|
||||||
|
step={0.01}
|
||||||
|
></SingleFormSlider>
|
||||||
|
</FormControl>
|
||||||
|
<FormControl>
|
||||||
|
<Input
|
||||||
|
type={'number'}
|
||||||
|
className="h-7 w-20 bg-bg-card"
|
||||||
|
max={1}
|
||||||
|
min={0}
|
||||||
|
step={0.01}
|
||||||
|
{...field}
|
||||||
|
></Input>
|
||||||
|
</FormControl>
|
||||||
|
</div>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
{/* Keyword Similarity Weight */}
|
{/* Keyword Similarity Weight */}
|
||||||
<FormField
|
<FormField
|
||||||
control={formMethods.control}
|
control={formMethods.control}
|
||||||
@ -474,7 +509,7 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
|||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel>
|
<FormLabel>
|
||||||
<span className="text-destructive mr-1"> *</span>Keyword
|
<span className="text-destructive mr-1"> *</span>Vector
|
||||||
Similarity Weight
|
Similarity Weight
|
||||||
</FormLabel>
|
</FormLabel>
|
||||||
<div
|
<div
|
||||||
@ -608,7 +643,7 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
{/* Feature Controls */}
|
{/* Feature Controls */}
|
||||||
<FormField
|
{/* <FormField
|
||||||
control={formMethods.control}
|
control={formMethods.control}
|
||||||
name="search_config.web_search"
|
name="search_config.web_search"
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
@ -622,7 +657,7 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
|||||||
<FormLabel>{t('search.enableWebSearch')}</FormLabel>
|
<FormLabel>{t('search.enableWebSearch')}</FormLabel>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
)}
|
)}
|
||||||
/>
|
/> */}
|
||||||
|
|
||||||
<FormField
|
<FormField
|
||||||
control={formMethods.control}
|
control={formMethods.control}
|
||||||
@ -666,9 +701,9 @@ const SearchSetting: React.FC<SearchSettingProps> = ({
|
|||||||
setOpen(false);
|
setOpen(false);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t('modal.cancelText')}
|
{t('search.cancelText')}
|
||||||
</Button>
|
</Button>
|
||||||
<Button type="submit">{t('modal.okText')}</Button>
|
<Button type="submit">{t('search.okText')}</Button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
|
|||||||
@ -276,7 +276,7 @@ export default function SearchingView({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
{mindMapVisible && (
|
{mindMapVisible && (
|
||||||
<div className="flex-1 h-[88dvh] z-30 ml-8 mt-5">
|
<div className="flex-1 h-[88dvh] z-30 ml-32 mt-5">
|
||||||
<MindMapDrawer
|
<MindMapDrawer
|
||||||
visible={mindMapVisible}
|
visible={mindMapVisible}
|
||||||
hideModal={hideMindMapModal}
|
hideModal={hideMindMapModal}
|
||||||
|
|||||||
@ -1,26 +1,28 @@
|
|||||||
import { RAGFlowAvatar } from '@/components/ragflow-avatar';
|
import { RAGFlowAvatar } from '@/components/ragflow-avatar';
|
||||||
import i18n from '@/locales/config';
|
import i18n from '@/locales/config';
|
||||||
import { useEffect } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
ISearchAppDetailProps,
|
ISearchAppDetailProps,
|
||||||
useFetchSearchDetail,
|
useFetchSearchDetail,
|
||||||
} from '../../next-searches/hooks';
|
} from '../../next-searches/hooks';
|
||||||
import { useGetSharedSearchParams, useSearching } from '../hooks';
|
import { useGetSharedSearchParams, useSearching } from '../hooks';
|
||||||
import '../index.less';
|
import '../index.less';
|
||||||
import SearchingView from '../search-view';
|
import SearchHome from '../search-home';
|
||||||
export default function SearchingPage() {
|
import SearchingPage from '../searching';
|
||||||
|
export default function ShareSeachPage() {
|
||||||
const { tenantId, locale, visibleAvatar } = useGetSharedSearchParams();
|
const { tenantId, locale, visibleAvatar } = useGetSharedSearchParams();
|
||||||
const {
|
const {
|
||||||
data: searchData = {
|
data: searchData = {
|
||||||
search_config: { kb_ids: [] },
|
search_config: { kb_ids: [] },
|
||||||
} as unknown as ISearchAppDetailProps,
|
} as unknown as ISearchAppDetailProps,
|
||||||
} = useFetchSearchDetail(tenantId as string);
|
} = useFetchSearchDetail(tenantId as string);
|
||||||
|
const [isSearching, setIsSearching] = useState(false);
|
||||||
|
const [searchText, setSearchText] = useState('');
|
||||||
const searchingParam = useSearching({
|
const searchingParam = useSearching({
|
||||||
data: searchData,
|
data: searchData,
|
||||||
});
|
});
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log('locale', locale, i18n.language);
|
|
||||||
if (locale && i18n.language !== locale) {
|
if (locale && i18n.language !== locale) {
|
||||||
i18n.changeLanguage(locale);
|
i18n.changeLanguage(locale);
|
||||||
}
|
}
|
||||||
@ -28,15 +30,36 @@ export default function SearchingPage() {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{visibleAvatar && (
|
{visibleAvatar && (
|
||||||
<div className="flex justify-start items-center gap-1 mx-6 mt-6 text-text-primary">
|
<div className="flex justify-start items-center gap-2 mx-6 mt-6 text-text-primary">
|
||||||
<RAGFlowAvatar
|
<RAGFlowAvatar
|
||||||
|
className="size-6"
|
||||||
avatar={searchData.avatar}
|
avatar={searchData.avatar}
|
||||||
name={searchData.name}
|
name={searchData.name}
|
||||||
></RAGFlowAvatar>
|
></RAGFlowAvatar>
|
||||||
<div>{searchData.name}</div>
|
<div>{searchData.name}</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
<SearchingView {...searchingParam} searchData={searchData} />;
|
{/* <SearchingView {...searchingParam} searchData={searchData} />; */}
|
||||||
|
{!isSearching && (
|
||||||
|
<div className="animate-fade-in-down">
|
||||||
|
<SearchHome
|
||||||
|
setIsSearching={setIsSearching}
|
||||||
|
isSearching={isSearching}
|
||||||
|
searchText={searchText}
|
||||||
|
setSearchText={setSearchText}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
{isSearching && (
|
||||||
|
<div className="animate-fade-in-up">
|
||||||
|
<SearchingPage
|
||||||
|
setIsSearching={setIsSearching}
|
||||||
|
searchText={searchText}
|
||||||
|
setSearchText={setSearchText}
|
||||||
|
data={searchData as ISearchAppDetailProps}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|||||||
import { useCallback, useState } from 'react';
|
import { useCallback, useState } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { useParams, useSearchParams } from 'umi';
|
import { useParams, useSearchParams } from 'umi';
|
||||||
|
|
||||||
interface CreateSearchProps {
|
interface CreateSearchProps {
|
||||||
name: string;
|
name: string;
|
||||||
description?: string;
|
description?: string;
|
||||||
@ -122,40 +121,6 @@ interface DeleteSearchResponse {
|
|||||||
message: string;
|
message: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const useDeleteSearch = () => {
|
|
||||||
const { t } = useTranslation();
|
|
||||||
|
|
||||||
const {
|
|
||||||
data,
|
|
||||||
isError,
|
|
||||||
mutateAsync: deleteSearchMutation,
|
|
||||||
} = useMutation<DeleteSearchResponse, Error, DeleteSearchProps>({
|
|
||||||
mutationKey: ['deleteSearch'],
|
|
||||||
mutationFn: async (props) => {
|
|
||||||
const response = await searchService.deleteSearch(props);
|
|
||||||
if (response.code !== 0) {
|
|
||||||
throw new Error(response.message || 'Failed to delete search');
|
|
||||||
}
|
|
||||||
return response;
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
message.success(t('message.deleted'));
|
|
||||||
},
|
|
||||||
onError: (error) => {
|
|
||||||
message.error(t('message.error', { error: error.message }));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const deleteSearch = useCallback(
|
|
||||||
(props: DeleteSearchProps) => {
|
|
||||||
return deleteSearchMutation(props);
|
|
||||||
},
|
|
||||||
[deleteSearchMutation],
|
|
||||||
);
|
|
||||||
|
|
||||||
return { data, isError, deleteSearch };
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface IllmSettingProps {
|
export interface IllmSettingProps {
|
||||||
llm_id: string;
|
llm_id: string;
|
||||||
parameter: string;
|
parameter: string;
|
||||||
@ -237,6 +202,42 @@ export const useFetchSearchDetail = (tenantId?: string) => {
|
|||||||
return { data: data?.data, isLoading, isError };
|
return { data: data?.data, isLoading, isError };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useDeleteSearch = () => {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
const {
|
||||||
|
data,
|
||||||
|
isError,
|
||||||
|
mutateAsync: deleteSearchMutation,
|
||||||
|
} = useMutation<DeleteSearchResponse, Error, DeleteSearchProps>({
|
||||||
|
mutationKey: ['deleteSearch'],
|
||||||
|
mutationFn: async (props) => {
|
||||||
|
const { data: response } = await searchService.deleteSearch(props);
|
||||||
|
if (response.code !== 0) {
|
||||||
|
throw new Error(response.message || 'Failed to delete search');
|
||||||
|
}
|
||||||
|
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['searchList'] });
|
||||||
|
return response;
|
||||||
|
},
|
||||||
|
onSuccess: () => {
|
||||||
|
message.success(t('message.deleted'));
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
message.error(t('message.error', { error: error.message }));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const deleteSearch = useCallback(
|
||||||
|
(props: DeleteSearchProps) => {
|
||||||
|
return deleteSearchMutation(props);
|
||||||
|
},
|
||||||
|
[deleteSearchMutation],
|
||||||
|
);
|
||||||
|
|
||||||
|
return { data, isError, deleteSearch };
|
||||||
|
};
|
||||||
|
|
||||||
export type IUpdateSearchProps = Omit<ISearchAppDetailProps, 'id'> & {
|
export type IUpdateSearchProps = Omit<ISearchAppDetailProps, 'id'> & {
|
||||||
search_id: string;
|
search_id: string;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -217,7 +217,11 @@ export const useTestRetrieval = (
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useShowMindMapDrawer = (kbIds: string[], question: string) => {
|
export const useShowMindMapDrawer = (
|
||||||
|
kbIds: string[],
|
||||||
|
question: string,
|
||||||
|
searchId = '',
|
||||||
|
) => {
|
||||||
const { visible, showModal, hideModal } = useSetModalState();
|
const { visible, showModal, hideModal } = useSetModalState();
|
||||||
const ref = useRef<any>();
|
const ref = useRef<any>();
|
||||||
|
|
||||||
@ -228,7 +232,7 @@ export const useShowMindMapDrawer = (kbIds: string[], question: string) => {
|
|||||||
} = useSearchFetchMindMap();
|
} = useSearchFetchMindMap();
|
||||||
|
|
||||||
const handleShowModal = useCallback(() => {
|
const handleShowModal = useCallback(() => {
|
||||||
const searchParams = { question: trim(question), kb_ids: kbIds };
|
const searchParams = { question: trim(question), kb_ids: kbIds, searchId };
|
||||||
if (
|
if (
|
||||||
!isEmpty(searchParams.question) &&
|
!isEmpty(searchParams.question) &&
|
||||||
!isEqual(searchParams, ref.current)
|
!isEqual(searchParams, ref.current)
|
||||||
@ -237,7 +241,7 @@ export const useShowMindMapDrawer = (kbIds: string[], question: string) => {
|
|||||||
fetchMindMap(searchParams);
|
fetchMindMap(searchParams);
|
||||||
}
|
}
|
||||||
showModal();
|
showModal();
|
||||||
}, [fetchMindMap, showModal, question, kbIds]);
|
}, [fetchMindMap, showModal, question, kbIds, searchId]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
mindMap,
|
mindMap,
|
||||||
|
|||||||
Reference in New Issue
Block a user