-- name: CreateRAGTrace :one
INSERT INTO rag_traces (
    id,
    project_id,
    knowledge_base_id,
    release_id,
    request_kind,
    trace_id,
    query_hash,
    query_text,
    response_text,
    status,
    latency_ms,
    expires_at
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
RETURNING *;

-- name: CreateRAGTraceEvidence :one
INSERT INTO rag_trace_evidence (
    id,
    rag_trace_id,
    rank,
    artifact_id,
    external_ref,
    score,
    citation,
    metadata
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING *;

-- name: DeleteExpiredRAGTraces :execrows
DELETE FROM rag_traces
WHERE expires_at <= now();
