fix: SQL errors in learning engine for best model selection
This commit is contained in:
parent
9808184384
commit
d614795545
@ -90,7 +90,7 @@ async function detectImprovements(
|
|||||||
const routingResult = await pool.query(
|
const routingResult = await pool.query(
|
||||||
`SELECT routing_model, task_type, COUNT(*) as total, SUM(CASE WHEN was_fallback THEN 1 ELSE 0 END) as fallback_count
|
`SELECT routing_model, task_type, COUNT(*) as total, SUM(CASE WHEN was_fallback THEN 1 ELSE 0 END) as fallback_count
|
||||||
FROM routing_decisions
|
FROM routing_decisions
|
||||||
WHERE created_at > NOW() - INTERVAL '1 day' * $1
|
WHERE created_at > NOW() - MAKE_INTERVAL(days => $1)
|
||||||
GROUP BY routing_model, task_type
|
GROUP BY routing_model, task_type
|
||||||
HAVING SUM(CASE WHEN was_fallback THEN 1 ELSE 0 END)::float / COUNT(*) > 0.3
|
HAVING SUM(CASE WHEN was_fallback THEN 1 ELSE 0 END)::float / COUNT(*) > 0.3
|
||||||
ORDER BY fallback_count DESC
|
ORDER BY fallback_count DESC
|
||||||
@ -152,11 +152,15 @@ async function analyzeAndImprove(pool: any, duration: string): Promise<number> {
|
|||||||
|
|
||||||
// 2. Identify best-performing models per task type and insert recommendations
|
// 2. Identify best-performing models per task type and insert recommendations
|
||||||
const bestModels = await pool.query(
|
const bestModels = await pool.query(
|
||||||
`SELECT DISTINCT ON (task_type) task_type, routing_model, success_rate, avg_latency_ms
|
`SELECT DISTINCT ON (task_type)
|
||||||
|
task_type,
|
||||||
|
routing_model,
|
||||||
|
ROUND((SUM(CASE WHEN success THEN 1 ELSE 0 END)::float / COUNT(*) * 100)::numeric, 2) as success_rate,
|
||||||
|
AVG(latency_ms)::int as avg_latency_ms
|
||||||
FROM routing_decisions rd
|
FROM routing_decisions rd
|
||||||
WHERE created_at > NOW() - INTERVAL '1 day'
|
WHERE created_at > NOW() - INTERVAL '1 day'
|
||||||
ORDER BY task_type, (CASE WHEN success THEN 1 ELSE 0 END) DESC, latency_ms ASC
|
GROUP BY task_type, routing_model
|
||||||
LIMIT 50`,
|
ORDER BY task_type, (SUM(CASE WHEN success THEN 1 ELSE 0 END)::float / COUNT(*)) DESC, AVG(latency_ms) ASC`,
|
||||||
);
|
);
|
||||||
|
|
||||||
for (const row of bestModels.rows) {
|
for (const row of bestModels.rows) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user