asg017 / sqlite-vss

A SQLite extension for efficient vector search, based on Faiss!
MIT License
1.59k stars 59 forks source link

Bug in sqlite3_vector_init / sqlite3_vss_init #63

Open polterguy opened 1 year ago

polterguy commented 1 year ago

sqlite3_vss_init requires the vector plugin to have been initialised before initialising the VSS plugin. The following statement fails in fact.

        // TODO: The && false parts needs to be removed, however if it is removed, the invocation returns
        // an error saying the function cannot be modified due to open statements. Not sure what this is?
        if (rc != SQLITE_OK && false) {

            *pzErrMsg = sqlite3_mprintf("%s: %s", "vector0", sqlite3_errmsg(db));
            return rc;
        }

... which is why I added the && false parts. I suspect there's something wrong in the order of initialising things, and that it might have some consequences that are "bad" in the long run. I'd love to fix this myself, but don't know exactly how ... :/

The vector0_api_from_db method seems to be correctly finalising the statement, so there should not be any "open statements" - However, if you remove the && false parts, you will see it complains about "not being able to modify/delete functions due to 'open statements'".

Might there be some statement that is not correctly disposed in there somewhere ...? :/

asg017 commented 1 year ago

I too was finding some weird stuff with that part when I was building it, will investigate. I got a feeling it might be a rare SQLite bug, since the "open statement" error message is extremely odd

polterguy commented 1 year ago

Yeh, I think so too - However, it might be some statement that isn't closed somewhere, or the order of initialisation of the different modules, etc - There are still some work left to be done on it related to memory management, etc.