feat(aihr): harden finance RAG retrieval and evidence gates
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
-- Generation-safe RAG candidate observability. Additive and idempotent on MySQL 8.
|
||||
|
||||
CREATE TABLE IF NOT EXISTS `aihr_query_candidate_trace` (
|
||||
`id` bigint NOT NULL AUTO_INCREMENT,
|
||||
`tenant_id` varchar(20) NOT NULL,
|
||||
`request_id` varchar(64) NOT NULL,
|
||||
`fragment_id` bigint NOT NULL,
|
||||
`candidate_rank` int DEFAULT NULL COMMENT 'Rank after rerank, null when rejected before rerank',
|
||||
`channel` varchar(20) NOT NULL COMMENT 'KEYWORD/FULLTEXT/VECTOR',
|
||||
`channel_rank` int NOT NULL,
|
||||
`raw_score` decimal(18,10) DEFAULT NULL,
|
||||
`fusion_score` decimal(18,10) DEFAULT NULL,
|
||||
`rerank_score` decimal(18,10) DEFAULT NULL,
|
||||
`rerank_model` varchar(100) DEFAULT NULL,
|
||||
`rerank_applied` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`source_authority` varchar(30) DEFAULT NULL,
|
||||
`source_kind` varchar(30) DEFAULT NULL,
|
||||
`query_variant` varchar(30) NOT NULL COMMENT 'ORIGINAL/NORMALIZED/GLOSSARY/ALTERNATE_n',
|
||||
`selected_for_evidence` tinyint(1) NOT NULL DEFAULT 0,
|
||||
`decision_reason` varchar(64) NOT NULL,
|
||||
`create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_aihr_query_candidate_channel`
|
||||
(`tenant_id`, `request_id`, `fragment_id`, `channel`, `query_variant`),
|
||||
KEY `idx_aihr_query_candidate_request` (`tenant_id`, `request_id`, `candidate_rank`),
|
||||
KEY `idx_aihr_query_candidate_reason` (`tenant_id`, `decision_reason`, `create_time`),
|
||||
KEY `idx_aihr_query_candidate_fragment` (`tenant_id`, `fragment_id`, `create_time`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
|
||||
COMMENT='Pre-generation retrieval candidates, channel contributions, rerank and gate decisions';
|
||||
Reference in New Issue
Block a user