neomemx 0.1.2

A high-performance memory library for AI agents with semantic search
Documentation
//! Graph backend for entity relationships
//! TODO - Needs to implement full feature

use crate::core::{FactId, ScopeFilter, StoredFact};
use crate::error::Result;
use async_trait::async_trait;

/// Entity extracted from text
#[derive(Debug, Clone)]
pub struct Entity {
    /// Entity name/value
    pub name: String,
    /// Entity type (person, place, organization, etc.)
    pub entity_type: String,
}

/// Trait for graph storage backend
#[async_trait]
pub trait GraphBackend: Send + Sync {
    /// Extract entities from text
    async fn extract_entities(&self, text: &str) -> Result<Vec<Entity>>;

    /// Build relationships between entities and a fact
    async fn build_relationships(&self, entities: &[Entity], fact_id: &FactId) -> Result<()>;

    /// Get related facts through graph relationships
    async fn get_related_facts(
        &self,
        fact_id: &FactId,
        max_depth: usize,
        filter: Option<&ScopeFilter>,
    ) -> Result<Vec<StoredFact>>;

    /// Delete fact from graph
    async fn delete_fact_graph(&self, fact_id: &FactId) -> Result<()>;
}

/// No-op implementation of GraphBackend (graph features disabled)
#[derive(Debug, Clone)]
pub struct NoOpGraphBackend;

impl NoOpGraphBackend {
    /// Create a new no-op graph backend
    pub fn new() -> Self {
        Self
    }
}

impl Default for NoOpGraphBackend {
    fn default() -> Self {
        Self::new()
    }
}

#[async_trait]
impl GraphBackend for NoOpGraphBackend {
    async fn extract_entities(&self, _text: &str) -> Result<Vec<Entity>> {
        // No-op: return empty entities
        Ok(Vec::new())
    }

    async fn build_relationships(&self, _entities: &[Entity], _fact_id: &FactId) -> Result<()> {
        // No-op: do nothing
        Ok(())
    }

    async fn get_related_facts(
        &self,
        _fact_id: &FactId,
        _max_depth: usize,
        _filter: Option<&ScopeFilter>,
    ) -> Result<Vec<StoredFact>> {
        // No-op: return empty results
        Ok(Vec::new())
    }

    async fn delete_fact_graph(&self, _fact_id: &FactId) -> Result<()> {
        // No-op: do nothing
        Ok(())
    }
}