import { useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { Table, Tag, Typography, Button, App, Tabs, Input, Card, Space } from 'antd' import { ReloadOutlined, SearchOutlined, ExperimentOutlined } from '@ant-design/icons' import { knowledgeAPI, vectorAPI } from '@/api' import { candidateStatusLabels } from '@/constants/labels' import dayjs from 'dayjs' const { Title, Text } = Typography export default function KnowledgeOpsPage() { const qc = useQueryClient() const { message } = App.useApp() const [sourceId, setSourceId] = useState('') const [debugQuery, setDebugQuery] = useState('') const { data: candidates } = useQuery({ queryKey: ['ops', 'candidates'], queryFn: (): Promise => knowledgeAPI.candidates(), }) const { data: chunks } = useQuery({ queryKey: ['ops', 'chunks', sourceId], queryFn: (): Promise => knowledgeAPI.chunks(sourceId), enabled: !!sourceId, }) const handleDebugSearch = async () => { if (!debugQuery) return const res: any = await vectorAPI.debugSearch({ query: debugQuery }) message.info(JSON.stringify(res.data)) } const candidateCols = [ { title: '标题', dataIndex: 'title', width: 200, ellipsis: true }, { title: '用户', dataIndex: 'userId', width: 120, ellipsis: true, render: (_: any, r: any) => r.userName || r.userId }, { title: '状态', dataIndex: 'status', width: 80, render: (s: string) => {candidateStatusLabels[s] || s} }, { title: '置信度', dataIndex: 'confidence', width: 80, align: 'center' as const, render: (v: any) => v ? `${(Number(v)*100).toFixed(0)}%` : '-' }, { title: '难度', dataIndex: 'difficulty', width: 70 }, { title: '时间', dataIndex: 'createdAt', width: 130, render: (d: string) => dayjs(d).format('MM-DD HH:mm') }, ] const chunkCols = [ { title: '#', dataIndex: 'chunkIndex', width: 50 }, { title: '内容', dataIndex: 'content', ellipsis: true, render: (v: string) => {v?.slice(0, 150)} }, { title: '页', dataIndex: 'pageNumber', width: 50 }, { title: '章节', dataIndex: 'sectionTitle', width: 150, ellipsis: true }, { title: 'Tokens', dataIndex: 'tokenCount', width: 70, align: 'center' as const }, { title: 'Embedding', dataIndex: 'embeddingStatus', width: 80, render: (s: string) => {s} }, ] return (
<ExperimentOutlined /> 知识运维
, }, { key: 'chunks', label: 'Chunk 管理', children: ( <> setSourceId(e.target.value)} onSearch={v => setSourceId(v)} enterButton={} style={{ width: 300 }} /> {sourceId && } ), }, { key: 'rag-debug', label: 'RAG 调试', children: ( setDebugQuery(e.target.value)} onSearch={handleDebugSearch} enterButton="检索" style={{ width: 400 }} />
输入查询文本后,将显示检索参数和结果(完整 RAG 管道在 M3 阶段完善)。
), }, ]} /> ) }