count(*) always returns 0 if table has a vector index
import random
import libsql_experimental as libsql
conn = libsql.connect(":memory:")
dims = 4
conn.execute(f"""
CREATE TABLE vectors
(
vector_id INTEGER PRIMARY KEY,
vector F32_BLOB({dims})
)
""")
conn.execute("CREATE INDEX vector_idx ON vectors(libsql_vector_idx(vector))")
data = []
for primary in range(10):
vector = ','.join(str(random.random()) for _ in range(dims))
data.append((primary, f"[{vector}]"))
conn.executemany("""
INSERT INTO vectors
values (?, ?)
""", data)
print(conn.execute("SELECT COUNT(*) FROM vectors").fetchall())
print(conn.execute("SELECT * FROM vectors").fetchall())
In this program, count(*) returns 0, even though the table has 10 rows. If you comment out the 'CREATE INDEX' line, the correct answer of 10 is given.
Using libsql-experimental 0.0.41
@andreaswimmer hi, it seems that documentation describes that, when using ":memory:" or "file.db" the code relies on Sqlite3 driver instead of libSql. In this case it doesn't support all features like vector indexes. That's why the result doesn't work as intended.
However if you use cli to create local libsql server for local development https://docs.turso.tech/local-development#turso-cli
turso dev --db-file local.db
This should work for you.
Let me know if the problem gets resolved.
@andreaswimmer actually I was wrong. I am not sure what the issue is, but bumping the version of underlying rust binary fixes the problem. https://github.com/tursodatabase/libsql-experimental-python/pull/81