use std::collections::HashMap;
pub struct Entity {
pub id: String,
pub entity_type: String,
pub name: Option<String>,
pub properties: HashMap<String, serde_json::Value>,
pub confidence: Option<f32>,
}
pub struct Relation {
pub id: String,
pub from_id: String,
pub to_id: String,
pub relation_type: String,
pub properties: HashMap<String, serde_json::Value>,
pub confidence: Option<f32>,
}
pub struct CausalPath {
pub nodes: Vec<Entity>,
pub edges: Vec<Relation>,
pub chain_strength: f32,
pub chain_confidence: Option<f32>,
pub is_complete: bool,
}
pub trait GraphAdapter: Send + Sync {
type Error: std::error::Error + Send + Sync + 'static;
fn create_entity(&self, entity: Entity) -> Result<Entity, Self::Error>;
fn find_entity(&self, id: &str) -> Result<Option<Entity>, Self::Error>;
fn search_entities(&self, query: &str, limit: usize) -> Result<Vec<Entity>, Self::Error>;
fn update_entity(&self, id: &str, properties: HashMap<String, serde_json::Value>) -> Result<Entity, Self::Error>;
fn delete_entity(&self, id: &str) -> Result<(), Self::Error>;
fn create_relation(&self, relation: Relation) -> Result<Relation, Self::Error>;
fn find_relations(&self, from_id: Option<&str>, to_id: Option<&str>) -> Result<Vec<Relation>, Self::Error>;
fn update_relation(&self, id: &str, properties: HashMap<String, serde_json::Value>) -> Result<Relation, Self::Error>;
fn delete_relation(&self, id: &str) -> Result<(), Self::Error>;
fn neighbors(&self, entity_id: &str, depth: usize) -> Result<Vec<Entity>, Self::Error>;
fn shortest_path(&self, from_id: &str, to_id: &str) -> Result<Vec<Entity>, Self::Error>;
fn subgraph(&self, seed_ids: &[&str], depth: usize) -> Result<(Vec<Entity>, Vec<Relation>), Self::Error>;
fn causal_descendants(
&self,
entity_id: &str,
max_depth: usize,
max_paths: usize,
) -> Result<Vec<CausalPath>, Self::Error>;
fn causal_ancestors(
&self,
entity_id: &str,
max_depth: usize,
max_paths: usize,
) -> Result<Vec<CausalPath>, Self::Error>;
fn causal_paths(
&self,
from_id: &str,
to_id: &str,
max_depth: usize,
max_paths: usize,
) -> Result<Vec<CausalPath>, Self::Error>;
fn find_entities_as_of(&self, timestamp: std::time::SystemTime) -> Result<Vec<Entity>, Self::Error>;
fn find_relations_as_of(&self, timestamp: std::time::SystemTime) -> Result<Vec<Relation>, Self::Error>;
fn supersede_entity(&self, id: &str, replacement: Entity) -> Result<Entity, Self::Error>;
fn supersede_relation(&self, id: &str, replacement: Relation) -> Result<Relation, Self::Error>;
fn retract_entity(&self, id: &str) -> Result<(), Self::Error>;
fn retract_relation(&self, id: &str) -> Result<(), Self::Error>;
fn detect_communities(&self) -> Result<Vec<Vec<String>>, Self::Error>;
fn healthy(&self) -> Result<bool, Self::Error>;
}