revert: restore memory_entity/memory_edge table names
CI / CI (pull_request) Canceled after 8m27s

knowledge_* namespace reserved for future agentic learning tables.
memory_* namespace used for facts, events, and entity graph.

- knowledge_node → memory_entity (reverted)
- knowledge_edge → memory_edge (reverted)
- Old provenance DAG (child_sha/parent_sha) renamed to
  memory_edge_provenance via migration 009
- Kept: runtime queries in versioning.rs, UUID casts, init_schema additions
This commit is contained in:
2026-09-15 17:29:53 +09:00
parent 181b0e0f99
commit fd59c6de11
26 changed files with 175 additions and 163 deletions
+7 -7
View File
@@ -58,7 +58,7 @@ impl Tier1Compactor {
let rows = sqlx::query(
r#"
SELECT array_agg(id ORDER BY created_at)
FROM knowledge_edge
FROM memory_edge
WHERE deleted_at IS NULL
GROUP BY source_id, target_id, relation_type, md5(fact)
HAVING COUNT(*) > 1
@@ -91,7 +91,7 @@ impl Tier1Compactor {
let execute_fn = async move {
for (_master, duplicate) in duplicates {
sqlx::query(
"UPDATE knowledge_edge SET deleted_at = NOW() WHERE id = $1"
"UPDATE memory_edge SET deleted_at = NOW() WHERE id = $1"
)
.bind(&duplicate)
.execute(&pool)
@@ -126,7 +126,7 @@ impl Tier1Compactor {
let row_count: (i64,) = sqlx::query_as(
&format!(
r#"
SELECT COUNT(*) FROM knowledge_edge
SELECT COUNT(*) FROM memory_edge
WHERE fact_invalid_at IS NOT NULL
AND fact_invalid_at < {}
AND deleted_at IS NULL
@@ -149,7 +149,7 @@ impl Tier1Compactor {
sqlx::query(
&format!(
r#"
UPDATE knowledge_edge
UPDATE memory_edge
SET deleted_at = NOW()
WHERE fact_invalid_at IS NOT NULL
AND fact_invalid_at < {}
@@ -207,8 +207,8 @@ impl Tier2Compactor {
let rows = sqlx::query(
r#"
SELECT a.id, b.id, a.fact, b.fact
FROM knowledge_edge a
JOIN knowledge_edge b ON a.source_id = b.source_id
FROM memory_edge a
JOIN memory_edge b ON a.source_id = b.source_id
AND a.target_id = b.target_id
AND a.relation_type = b.relation_type
AND a.id < b.id
@@ -279,7 +279,7 @@ Respond with JSON: {{"confidence": 0.0-1.0}} where 1.0 means identical meaning."
let edge_id = edge_b_id.to_string();
let execute_fn = async move {
sqlx::query(
"UPDATE knowledge_edge SET deleted_at = NOW() WHERE id = $1"
"UPDATE memory_edge SET deleted_at = NOW() WHERE id = $1"
)
.bind(&edge_id)
.execute(&pool)
+1 -1
View File
@@ -158,7 +158,7 @@ pub async fn register_agent_handler(
// Temporal activities will:
// 1. Persist agent state to temporal_workflow_links table
// 2. Execute LLMInferenceActivity (call LLM via api.riotpiao.com/v1/chat/completions)
// 3. Store reasoning traces to knowledge_node/knowledge_edge
// 3. Store reasoning traces to memory_entity/memory_edge
if let Some(jwt) = crate::handlers::extract_jwt_token(&req) {
let client = SynthesisClient::new(
"https://api.riotpiao.com".to_string(),
@@ -199,7 +199,7 @@ async fn compute_state_checksum(pool: &PgPool, project: &str) -> Result<String,
}
let entities: Vec<IdRow> = sqlx::query_as::<_, IdRow>(
"SELECT id FROM knowledge_node WHERE project_id = $1 ORDER BY id"
"SELECT id FROM memory_entity WHERE project_id = $1 ORDER BY id"
)
.bind(project)
.fetch_all(pool)
@@ -211,7 +211,7 @@ async fn compute_state_checksum(pool: &PgPool, project: &str) -> Result<String,
// Edges in order (by id) - using runtime query to avoid sqlx compile-time check
let edges: Vec<IdRow> = sqlx::query_as::<_, IdRow>(
"SELECT id FROM knowledge_edge WHERE project_id = $1 ORDER BY id"
"SELECT id FROM memory_edge WHERE project_id = $1 ORDER BY id"
)
.bind(project)
.fetch_all(pool)
@@ -200,7 +200,7 @@ pub async fn unified_synthesis_handler(
}
// Reasoning via Temporal workflow
// Temporal activity calls LLMInferenceActivity + persists results to knowledge_node/knowledge_edge
// Temporal activity calls LLMInferenceActivity + persists results to memory_entity/memory_edge
if body.reason_query {
reasoning = match execute_reasoning_workflow(
&synthesis_client,
+4 -4
View File
@@ -383,11 +383,11 @@ pub async fn start_server(port: u16, api_key: String, database_url: &str) -> Res
loop {
interval.tick().await;
// O5: Table row counts
if let Ok(row) = sqlx::query_as::<_, (i64,)>("SELECT COUNT(*) FROM knowledge_node")
if let Ok(row) = sqlx::query_as::<_, (i64,)>("SELECT COUNT(*) FROM memory_entity")
.fetch_one(&stats_pool).await {
crate::metrics::DB_TABLE_ENTITY_ROWS.set(row.0 as u64);
}
if let Ok(row) = sqlx::query_as::<_, (i64,)>("SELECT COUNT(*) FROM knowledge_edge")
if let Ok(row) = sqlx::query_as::<_, (i64,)>("SELECT COUNT(*) FROM memory_edge")
.fetch_one(&stats_pool).await {
crate::metrics::DB_TABLE_EDGE_ROWS.set(row.0 as u64);
}
@@ -1454,7 +1454,7 @@ async fn query_temporal_graph(
) -> anyhow::Result<serde_json::Value> {
// Step 1: Find entities (order by name for deterministic results)
let entities_rows: Vec<(String, String, String)> = sqlx::query_as(
"SELECT id::TEXT, name, entity_type FROM knowledge_node WHERE project_id = $1 LIMIT $2"
"SELECT id::TEXT, name, entity_type FROM memory_entity WHERE project_id = $1 LIMIT $2"
)
.bind(&params.project)
.bind(params.limit as i32)
@@ -1470,7 +1470,7 @@ async fn query_temporal_graph(
for (entity_id, _name, _type_str) in &entities_rows {
let entity_edges: Vec<(String, String, String, String, f32, Option<chrono::DateTime<chrono::Utc>>, Option<chrono::DateTime<chrono::Utc>>)> =
sqlx::query_as(
"SELECT id::TEXT, target_id::TEXT, relation_type, fact, confidence, t_valid, t_invalid FROM knowledge_edge WHERE project_id = $1 AND source_id = $2::UUID"
"SELECT id::TEXT, target_id::TEXT, relation_type, fact, confidence, t_valid, t_invalid FROM memory_edge WHERE project_id = $1 AND source_id = $2::UUID"
)
.bind(&params.project)
.bind(entity_id)
+5 -5
View File
@@ -384,14 +384,14 @@ async fn save_entity_to_db(pool: &PgPool, entity: &mem_core::entity::Entity) ->
let t_created_str = entity.t_created.to_string();
sqlx::query(
"INSERT INTO knowledge_node (id, project_id, name, entity_type, description, t_created, t_updated, confidence)
"INSERT INTO memory_entity (id, project_id, name, entity_type, description, t_created, t_updated, confidence)
VALUES ($1::UUID, $2, $3, $4, $5, $6::TIMESTAMPTZ, $7::TIMESTAMPTZ, $8)
ON CONFLICT (project_id, name) DO UPDATE SET
entity_type = EXCLUDED.entity_type,
description = COALESCE(NULLIF(EXCLUDED.description, ''), knowledge_node.description),
description = COALESCE(NULLIF(EXCLUDED.description, ''), memory_entity.description),
t_updated = NOW(),
confidence = GREATEST(knowledge_node.confidence, EXCLUDED.confidence),
source_count = knowledge_node.source_count + 1"
confidence = GREATEST(memory_entity.confidence, EXCLUDED.confidence),
source_count = memory_entity.source_count + 1"
)
.bind(&entity.id)
.bind(&entity.project_id)
@@ -445,7 +445,7 @@ async fn save_edge_with_logging(
async fn save_edge_to_db(pool: &PgPool, edge: &mem_core::edge::Edge) -> Result<()> {
// Try temporal schema first (id, project_id, source_entity_id, etc)
let result = sqlx::query(
"INSERT INTO knowledge_edge (id, project_id, source_id, target_id, relation_type, fact, t_valid, t_invalid, t_created, confidence)
"INSERT INTO memory_edge (id, project_id, source_id, target_id, relation_type, fact, t_valid, t_invalid, t_created, confidence)
VALUES ($1::UUID, $2, $3::UUID, $4::UUID, $5, $6, $7::TIMESTAMPTZ, $8::TIMESTAMPTZ, $9::TIMESTAMPTZ, $10)
ON CONFLICT (id) DO NOTHING"
)
+4 -4
View File
@@ -274,9 +274,9 @@ pub static WRITE_BYTES_TOTAL: Counter = Counter::new(
"memory_write_bytes_total", "Total bytes written to storage");
pub static DB_ENTITY_COUNT: Gauge = Gauge::new(
"memory_db_entity_count", "Current entity count in knowledge_node table");
"memory_db_entity_count", "Current entity count in memory_entity table");
pub static DB_EDGE_COUNT: Gauge = Gauge::new(
"memory_db_edge_count", "Current edge count in knowledge_edge table");
"memory_db_edge_count", "Current edge count in memory_edge table");
pub static DB_CHUNK_COUNT: Gauge = Gauge::new(
"memory_db_chunk_count", "Current chunk count in memory_chunks table");
@@ -436,9 +436,9 @@ pub static DB_TRANSACTION_DURATION: Lazy<Histogram> = Lazy::new(||
// Table-specific row counts (updated periodically)
pub static DB_TABLE_ENTITY_ROWS: Gauge = Gauge::new(
"memory_db_table_entity_rows", "Rows in knowledge_node table");
"memory_db_table_entity_rows", "Rows in memory_entity table");
pub static DB_TABLE_EDGE_ROWS: Gauge = Gauge::new(
"memory_db_table_edge_rows", "Rows in knowledge_edge table");
"memory_db_table_edge_rows", "Rows in memory_edge table");
pub static DB_TABLE_CHUNK_ROWS: Gauge = Gauge::new(
"memory_db_table_chunk_rows", "Rows in memory_chunks table");
@@ -1,6 +1,6 @@
/// BFS graph traversal with PostgreSQL queries.
///
/// Performs breadth-first search on knowledge_node + knowledge_edge tables,
/// Performs breadth-first search on memory_entity + memory_edge tables,
/// returning a subgraph for visualization.
use std::collections::{HashMap, VecDeque};
@@ -215,7 +215,7 @@ impl BfsGraphTraversal {
async fn load_entity(&self, id: &str) -> Result<Option<(String, String, String, Option<String>)>, String> {
let query = r#"
SELECT id, entity_type, name, description
FROM knowledge_node
FROM memory_entity
WHERE id = $1 AND deleted_at IS NULL
LIMIT 1;
"#;
@@ -239,7 +239,7 @@ impl BfsGraphTraversal {
async fn load_edges_from(&self, source_id: &str, limit: usize) -> Result<Vec<(String, String, String, String, String, f32)>, String> {
let query = r#"
SELECT id, target_id, source_id, relation_type, fact, strength
FROM knowledge_edge
FROM memory_edge
WHERE source_id = $1 AND t_expired IS NULL AND t_invalid IS NULL
ORDER BY strength DESC
LIMIT $2;
@@ -228,7 +228,7 @@ impl CommunityDetector {
async fn fetch_graph(&self, _project_id: Option<&str>) -> Result<(Vec<String>, Vec<GraphEdge>), String> {
// Fetch entities
let entities = sqlx::query_as::<_, (String,)>(
"SELECT DISTINCT id FROM knowledge_node WHERE deleted_at IS NULL"
"SELECT DISTINCT id FROM memory_entity WHERE deleted_at IS NULL"
)
.fetch_all(&self.pool)
.await
@@ -240,7 +240,7 @@ impl CommunityDetector {
// Fetch edges with confidence as weight
let edges = sqlx::query_as::<_, (String, String, f32)>(
"SELECT source_entity_id, target_entity_id, confidence
FROM knowledge_edge
FROM memory_edge
WHERE fact_invalid_at IS NULL AND deleted_at IS NULL"
)
.fetch_all(&self.pool)
+4 -4
View File
@@ -108,7 +108,7 @@ impl FacetedSearch {
// Get entity types
let entity_types = sqlx::query_as::<_, (String, i64)>(
"SELECT entity_type, COUNT(*) as cnt
FROM knowledge_node
FROM memory_entity
WHERE deleted_at IS NULL
GROUP BY entity_type
ORDER BY cnt DESC
@@ -128,7 +128,7 @@ impl FacetedSearch {
// Get total count
let total_count: (i64,) = sqlx::query_as(
"SELECT COUNT(*) FROM knowledge_node WHERE deleted_at IS NULL"
"SELECT COUNT(*) FROM memory_entity WHERE deleted_at IS NULL"
)
.fetch_one(&self.pool)
.await
@@ -212,7 +212,7 @@ impl FacetedSearch {
// Get relation types
let relation_types = sqlx::query_as::<_, (String, i64)>(
"SELECT relation_type, COUNT(*) as cnt
FROM knowledge_edge
FROM memory_edge
WHERE fact_invalid_at IS NULL AND deleted_at IS NULL
GROUP BY relation_type
ORDER BY cnt DESC
@@ -232,7 +232,7 @@ impl FacetedSearch {
// Get total count
let total_count: (i64,) = sqlx::query_as(
"SELECT COUNT(*) FROM knowledge_edge WHERE fact_invalid_at IS NULL AND deleted_at IS NULL"
"SELECT COUNT(*) FROM memory_edge WHERE fact_invalid_at IS NULL AND deleted_at IS NULL"
)
.fetch_one(&self.pool)
.await
+1 -1
View File
@@ -382,7 +382,7 @@ impl PathFinder {
async fn fetch_neighbors(&self, entity_id: &str) -> Result<Vec<GraphEdge>, String> {
let edges = sqlx::query_as::<_, (String, String, String, f32)>(
"SELECT source_entity_id, target_entity_id, relation_type, confidence
FROM knowledge_edge
FROM memory_edge
WHERE (source_entity_id = $1 OR target_entity_id = $1)
AND fact_invalid_at IS NULL
AND deleted_at IS NULL"
@@ -117,7 +117,7 @@ impl SemanticRetriever {
"SELECT id, name, entity_type,
1 - (embedding <=> $1::vector) as similarity_score,
metadata
FROM knowledge_node
FROM memory_entity
WHERE deleted_at IS NULL
AND (1 - (embedding <=> $1::vector)) > $2
AND (entity_type = COALESCE($3, entity_type))
@@ -191,9 +191,9 @@ impl SemanticRetriever {
src.name, tgt.name, e.relation_type, e.fact,
1 - (e.embedding <=> $1::vector) as similarity_score,
e.confidence
FROM knowledge_edge e
JOIN knowledge_node src ON e.source_entity_id = src.id
JOIN knowledge_node tgt ON e.target_entity_id = tgt.id
FROM memory_edge e
JOIN memory_entity src ON e.source_entity_id = src.id
JOIN memory_entity tgt ON e.target_entity_id = tgt.id
WHERE e.fact_invalid_at IS NULL
AND e.deleted_at IS NULL
AND (e.relation_type = COALESCE($2, e.relation_type))