neomemx 0.1.2

A high-performance memory library for AI agents with semantic search
Documentation
//! Basic usage example for neomemx
//!
//! Prerequisites:
//! 1. Start ChromaDB: `docker run -d -p 8000:8000 chromadb/chroma`
//! 2. Set environment variables: `GROQ_API_KEY`, `JINA_API_KEY`, `OPENAI_API_KEY` (depending on config)
//!
//! Run with: `cargo run --example basic`

use neomemx::prelude::*;

#[tokio::main]
async fn main() -> Result<()> {
    dotenvy::dotenv().ok();

    println!("Initializing NeomemxEngine...");
    let engine = NeomemxEngine::new().await?;

    let user_id = "afjal";
    let scope = ScopeIdentifiers::for_user(user_id);

    println!("Storing memories...");
    let outcome = engine
        .store("I'm Afjal, a software engineer.")
        .with_scope(scope.clone())
        .execute()
        .await?;

    for op in outcome.operations {
        println!(
            "Fact operation: {:?} -> {} ({})",
            op.change_type, op.fact_id, op.content
        );
    }

    let outcome = engine
        .store("I enjoy playing football.")
        .with_scope(scope.clone())
        .execute()
        .await?;

    for op in outcome.operations {
        println!(
            "Fact operation: {:?} -> {} ({})",
            op.change_type, op.fact_id, op.content
        );
    }

    // Search memories
    println!("\nSearching for 'What does Afjal do?'...");
    let results = engine
        .search("What does Afjal do?")
        .with_scope(scope.clone())
        .limit(5)
        .execute()
        .await?;

    for fact in results.facts {
        println!(
            "  - {} (score: {:.2})",
            fact.content,
            fact.relevance_score.unwrap_or(0.0)
        );
    }

    // Retrieve all
    println!("\nRetrieving all facts for user...");
    let all = engine
        .retrieve_all()
        .with_scope(scope.clone())
        .limit(10)
        .execute()
        .await?;

    for fact in all.facts {
        println!("  - [{}] {}", &fact.id[..8], fact.content);
    }

    // Cleanup
    println!("\nCleaning up...");
    let count = engine.clear(scope).await?;
    println!("Deleted {} facts.", count);

    println!("Done!");
    Ok(())
}