Merge pull request 'feat(db): add truth scoring columns migration (#31)' (#43) from feature/truth-migration into main

Merge truth scoring columns migration (#31)
This commit is contained in:
2026-04-04 03:08:58 +00:00
2 changed files with 48 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
-- V5: Add truth scoring columns for the Truth Engine integration
-- Part of: https://gitea.ingwaz.work/Ingwaz/openbrain-mcp/issues/31
--
-- All columns are nullable — existing memories start unscored and
-- get populated by the background truth scoring worker.
--
-- Rollback (manual):
-- ALTER TABLE memories
-- DROP COLUMN IF EXISTS truth_value,
-- DROP COLUMN IF EXISTS truth_confidence,
-- DROP COLUMN IF EXISTS truth_category,
-- DROP COLUMN IF EXISTS truth_evaluated_at,
-- DROP COLUMN IF EXISTS ecan_sti,
-- DROP COLUMN IF EXISTS ecan_lti;
-- DROP INDEX IF EXISTS idx_memories_truth_category;
-- DROP INDEX IF EXISTS idx_memories_truth_unevaluated;
ALTER TABLE memories
ADD COLUMN truth_value REAL,
ADD COLUMN truth_confidence REAL,
ADD COLUMN truth_category TEXT,
ADD COLUMN truth_evaluated_at TIMESTAMPTZ,
ADD COLUMN ecan_sti REAL,
ADD COLUMN ecan_lti REAL;
-- Partial index: quickly find memories by truth category
CREATE INDEX idx_memories_truth_category
ON memories (truth_category)
WHERE truth_category IS NOT NULL;
-- Partial index: efficiently find unscored memories for the background worker
CREATE INDEX idx_memories_truth_unevaluated
ON memories (created_at)
WHERE truth_evaluated_at IS NULL;

View File

@@ -30,6 +30,13 @@ pub struct MemoryRecord {
pub metadata: serde_json::Value, pub metadata: serde_json::Value,
pub created_at: chrono::DateTime<chrono::Utc>, pub created_at: chrono::DateTime<chrono::Utc>,
pub expires_at: Option<chrono::DateTime<chrono::Utc>>, pub expires_at: Option<chrono::DateTime<chrono::Utc>>,
// Truth scoring fields (populated by background worker)
pub truth_value: Option<f32>,
pub truth_confidence: Option<f32>,
pub truth_category: Option<String>,
pub truth_evaluated_at: Option<chrono::DateTime<chrono::Utc>>,
pub ecan_sti: Option<f32>,
pub ecan_lti: Option<f32>,
} }
/// Query result with similarity score /// Query result with similarity score
@@ -299,6 +306,13 @@ impl Database {
metadata: row.get("metadata"), metadata: row.get("metadata"),
created_at: row.get("created_at"), created_at: row.get("created_at"),
expires_at: row.get("expires_at"), expires_at: row.get("expires_at"),
// Truth fields will be populated by issue #39
truth_value: None,
truth_confidence: None,
truth_category: None,
truth_evaluated_at: None,
ecan_sti: None,
ecan_lti: None,
}, },
similarity: row.get("hybrid_score"), similarity: row.get("hybrid_score"),
vector_score: row.get("vector_score"), vector_score: row.get("vector_score"),