mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-14 22:25:55 +08:00
### What problem does this PR solve? Feat: Rendering a search test list with real data #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
1b4016317e
commit
42e236f464
@ -1,3 +1,4 @@
|
|||||||
|
import { INextTestingResult } from '@/interfaces/database/knowledge';
|
||||||
import { ITestRetrievalRequestBody } from '@/interfaces/request/knowledge';
|
import { ITestRetrievalRequestBody } from '@/interfaces/request/knowledge';
|
||||||
import kbService from '@/services/knowledge-service';
|
import kbService from '@/services/knowledge-service';
|
||||||
import { useQuery } from '@tanstack/react-query';
|
import { useQuery } from '@tanstack/react-query';
|
||||||
@ -33,14 +34,18 @@ export const useTestRetrieval = () => {
|
|||||||
data,
|
data,
|
||||||
isFetching: loading,
|
isFetching: loading,
|
||||||
refetch,
|
refetch,
|
||||||
} = useQuery<any>({
|
} = useQuery<INextTestingResult>({
|
||||||
queryKey: [KnowledgeApiAction.TestRetrieval, queryParams],
|
queryKey: [KnowledgeApiAction.TestRetrieval, queryParams],
|
||||||
initialData: {},
|
initialData: {
|
||||||
// enabled: !!values?.question && !!knowledgeBaseId,
|
chunks: [],
|
||||||
|
doc_aggs: [],
|
||||||
|
total: 0,
|
||||||
|
},
|
||||||
enabled: false,
|
enabled: false,
|
||||||
gcTime: 0,
|
gcTime: 0,
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const { data } = await kbService.retrieval_test(queryParams);
|
const { data } = await kbService.retrieval_test(queryParams);
|
||||||
|
console.log('🚀 ~ queryFn: ~ data:', data);
|
||||||
return data?.data ?? {};
|
return data?.data ?? {};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -137,6 +137,13 @@ export interface ITestingResult {
|
|||||||
labels?: Record<string, number>;
|
labels?: Record<string, number>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface INextTestingResult {
|
||||||
|
chunks: ITestingChunk[];
|
||||||
|
doc_aggs: ITestingDocument[];
|
||||||
|
total: number;
|
||||||
|
labels?: Record<string, number>;
|
||||||
|
}
|
||||||
|
|
||||||
export type IRenameTag = { fromTag: string; toTag: string };
|
export type IRenameTag = { fromTag: string; toTag: string };
|
||||||
|
|
||||||
export interface IKnowledgeGraph {
|
export interface IKnowledgeGraph {
|
||||||
|
@ -1,53 +1,63 @@
|
|||||||
import { Badge } from '@/components/ui/badge';
|
|
||||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||||
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
|
import { useTestRetrieval } from '@/hooks/use-knowledge-request';
|
||||||
|
import { ITestingChunk } from '@/interfaces/database/knowledge';
|
||||||
|
import { camelCase } from 'lodash';
|
||||||
import TestingForm from './testing-form';
|
import TestingForm from './testing-form';
|
||||||
|
|
||||||
const list = new Array(15).fill({
|
const similarityList: Array<{ field: keyof ITestingChunk; label: string }> = [
|
||||||
content: `Lorem ipsum odor amet, consectetuer adipiscing elit. Ullamcorper vulputate id laoreet malesuada commodo molestie. Lectus convallis class euismod; consequat in curabitur. Ablandit praesent inceptos nibh placerat lectus fringilla finibus. Hac vivamus id scelerisque et gravida nec ligula et non. Consectetur eu himenaeos eget felis quis habitant tellus. Tellus commodo inceptos litora habitant per himenaeos faucibus pretium. Gravida velit pretium amet purus rhoncus taciti. `,
|
{ field: 'similarity', label: 'Hybrid Similarity' },
|
||||||
});
|
{ field: 'term_similarity', label: 'Term Similarity' },
|
||||||
|
{ field: 'vector_similarity', label: 'Vector Similarity' },
|
||||||
const SimilarityList = [
|
|
||||||
{ label: '混合相似度', value: 45.88 },
|
|
||||||
{ label: '关键词似度', value: 45.88 },
|
|
||||||
{ label: '向量相似度', value: 45.88 },
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const ChunkTitle = ({ item }: { item: ITestingChunk }) => {
|
||||||
|
const { t } = useTranslate('knowledgeDetails');
|
||||||
|
return (
|
||||||
|
<div className="flex gap-3 text-xs">
|
||||||
|
{similarityList.map((x) => (
|
||||||
|
<div key={x.field} className="space-x-1">
|
||||||
|
<span>{((item[x.field] as number) * 100).toFixed(2)}</span>
|
||||||
|
<span>{t(camelCase(x.field))}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default function RetrievalTesting() {
|
export default function RetrievalTesting() {
|
||||||
|
const { loading, setValues, refetch, data } = useTestRetrieval();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="flex divide-x h-full">
|
<section className="flex divide-x h-full">
|
||||||
<div className="p-4">
|
<div className="p-4">
|
||||||
<TestingForm></TestingForm>
|
<TestingForm
|
||||||
|
loading={loading}
|
||||||
|
setValues={setValues}
|
||||||
|
refetch={refetch}
|
||||||
|
></TestingForm>
|
||||||
</div>
|
</div>
|
||||||
<div className="p-4 flex-1 ">
|
<div className="p-4 flex-1 ">
|
||||||
<h2 className="text-4xl font-bold mb-8 px-[10%]">
|
<h2 className="text-4xl font-bold mb-8 px-[10%]">
|
||||||
15 Results from 3 files
|
15 Results from 3 files
|
||||||
</h2>
|
</h2>
|
||||||
<section className="flex flex-col gap-4 overflow-auto h-[83vh] px-[10%]">
|
<section className="flex flex-col gap-4 overflow-auto h-[83vh] px-[10%]">
|
||||||
{list.map((x, idx) => (
|
{data.chunks.map((x) => (
|
||||||
<Card
|
<Card
|
||||||
key={idx}
|
key={x.chunk_id}
|
||||||
className="bg-colors-background-neutral-weak border-colors-outline-neutral-strong"
|
className="bg-colors-background-neutral-weak border-colors-outline-neutral-strong"
|
||||||
>
|
>
|
||||||
<CardHeader>
|
<CardHeader>
|
||||||
<CardTitle>
|
<CardTitle>
|
||||||
<div className="flex gap-2 flex-wrap">
|
<div className="flex gap-2 flex-wrap">
|
||||||
{SimilarityList.map((x, idx) => (
|
<ChunkTitle item={x}></ChunkTitle>
|
||||||
<Badge
|
|
||||||
key={idx}
|
|
||||||
variant="outline"
|
|
||||||
className="bg-colors-background-inverse-strong p-1.5 rounded-xl text-colors-text-inverse-weak text-base"
|
|
||||||
>
|
|
||||||
{x.label}
|
|
||||||
<span className="text-colors-text-inverse-strong ml-1 text-lg leading-none">
|
|
||||||
{x.value}
|
|
||||||
</span>
|
|
||||||
</Badge>
|
|
||||||
))}
|
|
||||||
</div>
|
</div>
|
||||||
</CardTitle>
|
</CardTitle>
|
||||||
</CardHeader>
|
</CardHeader>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<p className="text-colors-text-neutral-strong">{x.content}</p>
|
<p className="text-colors-text-neutral-strong">
|
||||||
|
{x.content_with_weight}
|
||||||
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
))}
|
))}
|
||||||
|
@ -28,10 +28,17 @@ import { trim } from 'lodash';
|
|||||||
import { useEffect } from 'react';
|
import { useEffect } from 'react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
export default function TestingForm() {
|
type TestingFormProps = Pick<
|
||||||
const { t } = useTranslation();
|
ReturnType<typeof useTestRetrieval>,
|
||||||
|
'loading' | 'refetch' | 'setValues'
|
||||||
|
>;
|
||||||
|
|
||||||
const { loading, setValues, refetch } = useTestRetrieval();
|
export default function TestingForm({
|
||||||
|
loading,
|
||||||
|
refetch,
|
||||||
|
setValues,
|
||||||
|
}: TestingFormProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
const formSchema = z.object({
|
const formSchema = z.object({
|
||||||
question: z.string().min(1, {
|
question: z.string().min(1, {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user