neomemx 0.1.2

A high-performance memory library for AI agents with semantic search
Documentation
//! Shared types for extraction and consolidation

use serde::Deserialize;
use std::collections::HashMap;

/// A fact item that can be represented as a string or an object
#[derive(Debug, Clone, Deserialize)]
#[serde(untagged)]
pub enum FactItem {
    /// Direct string representation
    Str(String),
    /// Object representation with various possible field names
    Map(HashMap<String, serde_json::Value>),
}

impl FactItem {
    /// Convert a FactItem to a string, handling various field name variations
    pub fn into_string(self) -> Option<String> {
        match self {
            FactItem::Str(s) => Some(s),
            FactItem::Map(map) => map
                .get("text")
                .or_else(|| map.get("fact"))
                .or_else(|| map.get("value"))
                .or_else(|| map.get("content"))
                .or_else(|| map.get("description"))
                .and_then(|v| v.as_str())
                .map(|s| s.to_string()),
        }
    }
}