hhblaze/DBreeze

Unity

Closed this issue · 10 comments

Hello, I want to use a vector database on Android, and I found this one which seems to be exactly what I need. I am using Unity for programming. Which library should I use? Thank you!

Take DBreeze from Nuget, it will bind the correct version.

I am not a Unity programmer, so don't know either you have that NuGet, so... directly you can try .NetStandard lib
image

I am not a Unity programmer, so don't know either you have that NuGet, so... directly you can try .NetStandard lib image

Thank you for your reply. I tried it, and it works, but now I have encountered some problems:

I want to use a vector database to store the dialogue content between characters, which is just simple strings. I made an example where I stored 7 strings and their corresponding embedding vectors in the database. However, when I used LINQPad to view the database content, I found that the string database was normal, containing 7 entries, but the vector database had 16 entries. What could be the reason for this?
Considering the data volume, after storing a certain amount of data, I would consider deleting some previously stored data. However, after executing the delete operation, the string database deleted the data correctly, but the vector database did not work, and the data remained the same. What could be the reason for this?
I look forward to your reply. Below is the corresponding code and example:

Insert Seven String Data and vectors
public void InsertVectors(Dictionary<string, double[]> datas)
{
Dictionary<byte[], double[]> vectorsToInsert = new Dictionary<byte[], double[]>();
using (var tran = Program.DBEngine.GetTransaction())
{
//-sync of Doctable and vector table for searching docs
tran.SynchronizeTables(table_vertor, table_value);

        int idCnt = 0;
        for (int i = 0; i < datas.Count;  i++)
        {
            idCnt++;
            tran.Insert<byte[], string>(table_value, 2.ToIndex(idCnt), datas.ElementAt(i).Key);
            vectorsToInsert.Add(idCnt.To_4_bytes_array_BigEndian(), datas.ElementAt(i).Value);
        }

        //-storing documents as vectors (with/without deferred indexing) 
        if (vectorsToInsert.Count > 0)
        {
            //-in case of big quantity of vectors, use deferredIndexing: true (to run computation in the background)
            tran.VectorsInsert(table_vertor, vectorsToInsert, deferredIndexing: false);
        }
        tran.Commit();
        
        Debug.Log("Vertor Count == " + tran.Count(table_vertor));   //The result is 16
        Debug.Log("Docs Count == " + tran.Count(table_value));     //The result is 7
    }

    Program.DBEngine.Dispose();
}

//Remove Target data
public void Remove()
{
    using (var tran = Program.DBEngine.GetTransaction())
    {
        tran.SynchronizeTables(table_vertor, table_value);
        tran.RemoveKey<byte[]>(table_vertor, 1.To_4_bytes_array_BigEndian()); //Not Work
        //tran.VectorsRemove(table_vertor, new List<Byte[]> { 1.To_4_bytes_array_BigEndian() } );//Not Work
        tran.RemoveKey<byte[]>(table_value, 1.ToIndex(2));//Work

        tran.Commit();
    }
}
屏幕截图 2024-06-19 144555 This image shows the output from LINQPad. At the top are the keys and values of the corresponding string data, and below are the keys and values of the embedding vectors. Because the values of the embedding vectors are in double[] format, which is not supported at the moment, they are set to byte[] format.

image
Did you try tran.VectorsRemove ?

image Did you try tran.VectorsRemove ?

Yes, I have tried it, and I found that I made a mistake. It is possible to delete normally, but when I delete 1 - 7, the vector database always has two entries left that cannot be deleted. Do I need to handle this?
The Code is below:
using (var tran = Program.DBEngine.GetTransaction())
{
tran.SynchronizeTables(table_vertor, table_value);
tran.VectorsRemove(table_vertor, new List<Byte[]> { 1.To_4_bytes_array_BigEndian() } );
tran.RemoveKey<byte[]>(table_value, 2.ToIndex(1));

        tran.Commit();

        Debug.Log("Vertor Count == " + tran.Count(table_vertor));
        Debug.Log("Docs Count == " + tran.Count(table_value));
    }

There may be some technical records, id counters etc...

There may be some technical records, id counters etc...

Okay, thank you.

As it was described in docu, you should access vector tables only via the interface tran.Vectors... and not to work with them directly. Of course for the debug purposes - it is appreciated, so go on to check.
Note, that first bytes (like 01, 03, 05) reflect the stored data type.

as an extra action you must handle Vector table in tran.SynchronizeTables - when necessary (and you do it already).