//! Integration test: sqlite-vec MATCH-based recall returns the
//! nearest fact under cosine ordering (FakeEmbedder produces unit
//! vectors so L2 ordering matches cosine).

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

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

#[tokio::test]
async fn vec_recall_returns_closest_fact() {
    let mem = MemorySqlite::new(":memory:", Arc::new(FakeEmbedder::new(8)))
        .await
        .unwrap();
    mem.long_term
        .remember(
            Scope::Workspace("w".into()),
            Fact::new("the cat sat on the mat"),
        )
        .await
        .unwrap();
    mem.long_term
        .remember(
            Scope::Workspace("w".into()),
            Fact::new("completely unrelated topic about rust"),
        )
        .await
        .unwrap();
    let hits = mem
        .long_term
        .recall(Scope::Workspace("w".into()), "the cat sat on the mat", 1)
        .await
        .unwrap();
    assert_eq!(hits.len(), 1);
    assert_eq!(hits[0].text, "the cat sat on the mat");
}

#[tokio::test]
async fn vec_recall_isolates_by_scope() {
    let mem = MemorySqlite::new(":memory:", Arc::new(FakeEmbedder::new(8)))
        .await
        .unwrap();
    mem.long_term
        .remember(
            Scope::Workspace("alpha".into()),
            Fact::new("in alpha workspace"),
        )
        .await
        .unwrap();
    mem.long_term
        .remember(
            Scope::Workspace("beta".into()),
            Fact::new("in beta workspace"),
        )
        .await
        .unwrap();
    let hits = mem
        .long_term
        .recall(Scope::Workspace("alpha".into()), "any query", 10)
        .await
        .unwrap();
    assert_eq!(hits.len(), 1);
    assert_eq!(hits[0].text, "in alpha workspace");
}
