Skip to content

Commit 55853e3

Browse files
committed
fix(core): count sqlite-vec autoindex storage
Signed-off-by: phernandez <paul@basicmachines.co>
1 parent afd4dbb commit 55853e3

3 files changed

Lines changed: 62 additions & 3 deletions

File tree

docs/multilingual-embedding-benchmark.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ without measurement.
107107

108108
| Backend | Model | Cold load | Index 17 notes | Notes/sec | Model RSS delta | Cache bytes | Vector storage |
109109
| --- | --- | ---: | ---: | ---: | ---: | ---: | ---: |
110-
| SQLite | BGE small English | 0.41 s | 6.31 s | 2.70 | 186,286,080 | 67,179,926 | 1,630,208 |
111-
| SQLite | Multilingual MiniLM | 2.89 s | 4.76 s | 3.57 | 314,720,256 | 252,141,023 | 1,630,208 |
110+
| SQLite | BGE small English | 0.41 s | 6.31 s | 2.70 | 186,286,080 | 67,179,926 | 1,638,400 |
111+
| SQLite | Multilingual MiniLM | 2.89 s | 4.76 s | 3.57 | 314,720,256 | 252,141,023 | 1,638,400 |
112112
| PostgreSQL | BGE small English | 1.04 s | 15.09 s | 1.13 | 212,926,464 | 67,179,926 | 262,144 |
113113
| PostgreSQL | Multilingual MiniLM | 2.65 s | 6.73 s | 2.53 | 514,326,528 | 252,141,023 | 253,952 |
114114
| PostgreSQL/Milvus Lite | BGE small English | 3.16 s | 35.42 s | 0.48 | 97,452,032 | 67,179,926 | 42,658 |

test-int/semantic/multilingual_benchmark.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,11 @@ async def vector_storage_size_bytes(
398398
"OR name IN ("
399399
"SELECT name FROM sqlite_schema WHERE tbl_name = 'search_vector_chunks'"
400400
") "
401-
"OR name LIKE 'search_vector_embeddings%'"
401+
"OR name LIKE 'search_vector_embeddings%' "
402+
"OR name IN ("
403+
"SELECT name FROM sqlite_schema "
404+
"WHERE tbl_name LIKE 'search_vector_embeddings%'"
405+
")"
402406
)
403407
)
404408
return int(result.scalar_one())

test-int/semantic/test_multilingual_benchmark_contract.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,16 @@
66
from types import SimpleNamespace
77

88
import pytest
9+
import sqlite_vec
910
from sqlalchemy import text
1011

1112
from basic_memory.config import DatabaseBackend
13+
from basic_memory.models.search import (
14+
CREATE_SQLITE_SEARCH_VECTOR_CHUNKS,
15+
CREATE_SQLITE_SEARCH_VECTOR_CHUNKS_PROJECT_ENTITY,
16+
CREATE_SQLITE_SEARCH_VECTOR_CHUNKS_UNIQUE,
17+
create_sqlite_search_vector_embeddings,
18+
)
1219
from basic_memory.repository.semantic_chunking import split_text_into_chunks
1320
from basic_memory.schemas.search import SearchRetrievalMode
1421

@@ -161,7 +168,55 @@ async def test_sqlite_vector_storage_excludes_unrelated_tables(sqlite_engine_fac
161168
if not dbstat_available:
162169
pytest.skip("SQLite dbstat is required for physical vector-storage measurement")
163170

171+
async with engine.begin() as connection:
172+
raw_connection = await connection.get_raw_connection()
173+
driver_connection = raw_connection.driver_connection
174+
await driver_connection.enable_load_extension(True)
175+
await driver_connection.load_extension(sqlite_vec.loadable_path())
176+
await driver_connection.enable_load_extension(False)
177+
await connection.execute(CREATE_SQLITE_SEARCH_VECTOR_CHUNKS)
178+
await connection.execute(CREATE_SQLITE_SEARCH_VECTOR_CHUNKS_PROJECT_ENTITY)
179+
await connection.execute(CREATE_SQLITE_SEARCH_VECTOR_CHUNKS_UNIQUE)
180+
await connection.execute(create_sqlite_search_vector_embeddings(4))
181+
164182
vector_bytes_before = await vector_storage_size_bytes(engine, storage_case)
183+
async with engine.connect() as connection:
184+
vector_relations = set(
185+
(
186+
await connection.execute(
187+
text(
188+
"SELECT name FROM sqlite_schema "
189+
"WHERE tbl_name = 'search_vector_chunks' "
190+
"OR tbl_name LIKE 'search_vector_embeddings%'"
191+
)
192+
)
193+
).scalars()
194+
)
195+
vector_relations.update(
196+
(
197+
await connection.execute(
198+
text(
199+
"SELECT DISTINCT name FROM dbstat "
200+
"WHERE name = 'search_vector_chunks' "
201+
"OR name LIKE 'search_vector_embeddings%'"
202+
)
203+
)
204+
).scalars()
205+
)
206+
dbstat_rows = await connection.execute(
207+
text("SELECT name, SUM(pgsize) FROM dbstat GROUP BY name")
208+
)
209+
dbstat_bytes = dict(dbstat_rows.tuples().all())
210+
211+
autoindexes = {
212+
name
213+
for name in vector_relations
214+
if name.startswith("sqlite_autoindex_search_vector_embeddings_")
215+
}
216+
vector_dbstat_relations = vector_relations.intersection(dbstat_bytes)
217+
assert autoindexes
218+
assert autoindexes <= vector_dbstat_relations
219+
assert vector_bytes_before == sum(dbstat_bytes[name] for name in vector_dbstat_relations)
165220

166221
async with engine.begin() as connection:
167222
await connection.execute(text("CREATE TABLE unrelated_payload (content BLOB NOT NULL)"))

0 commit comments

Comments
 (0)