//! Real fastembed-rs round-trip. Auto-downloads the model on first run
//! to the OS cache dir. Slow first invocation (~30s); subsequent runs
//! are fast.

#![cfg(all(feature = "fastembed", feature = "sqlite-vec"))]

use klieo_core::memory::{Fact, Scope};
use klieo_memory_sqlite::{FastEmbedEmbedder, MemorySqlite};
use std::sync::Arc;

#[tokio::test]
async fn fastembed_with_vec_round_trip() {
    let embedder = Arc::new(FastEmbedEmbedder::new().expect("fastembed init"));
    let mem = MemorySqlite::new(":memory:", embedder).await.unwrap();

    mem.long_term
        .remember(
            Scope::Global,
            Fact {
                text: "the cat sat on the mat".into(),
                metadata: serde_json::json!({"source": "test"}),
            },
        )
        .await
        .unwrap();
    mem.long_term
        .remember(
            Scope::Global,
            Fact {
                text: "Rust async runtimes are great".into(),
                metadata: serde_json::Value::Null,
            },
        )
        .await
        .unwrap();
    mem.long_term
        .remember(
            Scope::Global,
            Fact {
                text: "octopuses are intelligent invertebrates".into(),
                metadata: serde_json::Value::Null,
            },
        )
        .await
        .unwrap();

    // Query semantically close to the cat-mat fact.
    let hits = mem
        .long_term
        .recall(Scope::Global, "where is the cat sitting?", 1)
        .await
        .unwrap();
    assert_eq!(hits.len(), 1);
    assert!(
        hits[0].text.contains("cat"),
        "expected cat-related fact for cat-related query, got: {}",
        hits[0].text
    );
}
