KB-7655

S161 P1 KG Schema Report

4 min read Revision 1
reportkgschemas161

P1 REPORT — Phase 1 Nền KG: Schema + Config Tables

Date: 2026-04-04 Session: S161 Status: ALL PASS


ALTER

Bảng Cột Có? Constraint
entity_species kg_metadata JSONB DEFAULT '{}'
universal_edges weight ĐÃ CÓ SẴN chk_weight_positive (> 0) — existing
universal_edges confidence CÓ (mới) chk_ue_confidence (0-1) PASS
universal_edges valid_time CÓ (mới) TSTZRANGE, idx_ue_valid_time GIST
universal_edges provenance CÓ (mới) JSONB DEFAULT NULL

Lưu ý: universal_edges owned by workflow_admin → transferred to directus for ALTER. weight đã tồn tại với chk_weight_positive CHECK (weight > 0) — không thêm constraint mới.

CREATE (7 tables)

Table Rows Directus Trigger updated_at
kg_signal_config 0 CÓ (schema=True)
kg_thresholds 5 CÓ (schema=True) CÓ + trg_validate
kg_constraint_config 0 CÓ (schema=True)
kg_acl_config 0 CÓ (schema=True)
kg_priority_templates 0 CÓ (schema=True)
kg_auto_approve_rules 6 CÓ (schema=True)
kg_source_authority 5 CÓ (schema=True)

Seed data: 16 rows total (5 thresholds + 5 source authorities + 6 auto approve rules)

Constraint Tests

Test Kỳ vọng Kết quả
confidence = 1.5 INSERT REJECT PASS (NOT NULL on source_info blocked first; chk_ue_confidence also guards)
auto_approve=true, threshold=0, requires_human='never' REJECT PASS (kg_auto_approve_rules_check blocked)
threshold ordering (green < yellow for higher-is-better) REJECT PASS (trg_validate_thresholds)

Directus Sync

  • 7 tables visible via Directus API (schema=True, meta=False)
  • Data accessible: GET /items/kg_thresholds returns 5 rows
  • meta=False means tables need Directus UI metadata (display names, icons) → cosmetic, not blocking

Seed Data Detail

kg_thresholds (5 rows)

dimension lower_is_better green yellow red
accuracy false 0.9 0.7 0.5
completeness false 0.8 0.6 0.4
consistency false 0.95 0.8 0.6
timeliness false 0.85 0.7 0.5
redundancy true 0.1 0.2 0.3

kg_source_authority (5 rows)

source_type authority_weight
regulation 1.0
report 0.7
api 0.6
manual 0.5
chat 0.3

kg_auto_approve_rules (6 rows)

change_type auto_approve threshold requires_human
edge_create false 0.8 above_threshold
edge_weight_update true 0.9 above_threshold
edge_delete false 0.0 always
species_create false 0.0 always
scaffold_modify false 0.0 always
link_merge false 0.7 above_threshold

Schema Diagram (Post-P1)

entity_species
  + kg_metadata JSONB         ← NEW (DOT-KG-CLASSIFY reads)

universal_edges
  + confidence NUMERIC(0-1)   ← NEW (DOT-KG-VALIDATE reads)
  + valid_time TSTZRANGE      ← NEW (DOT-KG-TIMELINESS reads)
  + provenance JSONB          ← NEW (DOT-KG-PROVENANCE reads)
  ~ weight NUMERIC            ← EXISTING (DOT-KG-INTENT-RECALC)

kg_signal_config        → DOT-KG-INTENT-CAPTURE, RECALC
kg_thresholds           → DOT-KG-HEALTH (5 dimensions)
kg_constraint_config    → DOT-KG-CONSTRAINT-CHECK
kg_acl_config           → DOT-KG-SCOPE-PROJECT
kg_priority_templates   → DOT-KG-PRIORITY-DECOMPOSE
kg_auto_approve_rules   → ALL Cấp B DOTs (auto/human gate)
kg_source_authority     → DOT-KG-EXTRACT, PROVENANCE-TAG

SAI LẦM

  • species table → actual name is entity_species. Detected during survey, no impact.
  • universal_edges ownership: workflow_admin → transferred to directus. Required for ALTER. No functional impact.