'use client'
import { useState, useEffect } from 'react'
import type { Collection } from './types'
import { API_BASE } from './types'
function MetricCard({ title, value, change, positive }: {
title: string
value: string
change?: string
positive?: boolean
}) {
return (
{title}
{value}
{change && (
{change}
)}
)
}
function ScoreBar({ label, percent, color }: { label: string; percent: number; color: string }) {
return (
)
}
export function MetricsTab({ collections }: { collections: Collection[] }) {
const [metrics, setMetrics] = useState({
precision: 0,
recall: 0,
mrr: 0,
avgLatency: 0,
totalRatings: 0,
errorRate: 0,
scoreDistribution: { '0.9+': 0, '0.7-0.9': 0, '0.5-0.7': 0, '<0.5': 0 },
})
const [loading, setLoading] = useState(true)
useEffect(() => {
const fetchMetrics = async () => {
try {
const res = await fetch(`${API_BASE}/api/v1/admin/rag/metrics`)
if (res.ok) {
const data = await res.json()
setMetrics({
precision: data.precision_at_5 || 0,
recall: data.recall_at_10 || 0,
mrr: data.mrr || 0,
avgLatency: data.avg_latency_ms || 0,
totalRatings: data.total_ratings || 0,
errorRate: data.error_rate || 0,
scoreDistribution: data.score_distribution || {},
})
}
} catch (err) {
console.error('Failed to fetch metrics:', err)
} finally {
setLoading(false)
}
}
fetchMetrics()
}, [])
return (
RAG Qualitätsmetriken
Übersicht über Retrieval-Performance und Nutzerbewertungen
Score-Verteilung
{loading ? (
) : (
)}
)
}