using ZB.MOM.WW.CBDD.Bson;
using ZB.MOM.WW.CBDD.Core;
using ZB.MOM.WW.CBDD.Core.Indexing;
using ZB.MOM.WW.CBDD.Shared;
using Xunit;

namespace ZB.MOM.WW.CBDD.Tests;

public class VectorSearchTests
{
    [Fact]
    public void Test_VectorSearch_Basic()
    {
        string dbPath = "vector_test.db";
        if (File.Exists(dbPath)) File.Delete(dbPath);

        using (var db = new Shared.TestDbContext(dbPath))
        {
            db.VectorItems.Insert(new VectorEntity { Title = "Near", Embedding = [1.0f, 1.0f, 1.0f] });
            db.VectorItems.Insert(new VectorEntity { Title = "Far", Embedding = [10.0f, 10.0f, 10.0f] });

            var query = new[] { 0.9f, 0.9f, 0.9f };
            var results = db.VectorItems.AsQueryable().Where(x => x.Embedding.VectorSearch(query, 1)).ToList();

            results.Count().ShouldBe(1);
            results[0].Title.ShouldBe("Near");
        }

        File.Delete(dbPath);
    }
}
