@@ -120,16 +120,12 @@ def _get_db_path(config: RepoConfig) -> str:
120120 return db_path
121121
122122 def _get_conn (self , config : RepoConfig ):
123+ enable_sqlite_vec = (
124+ sys .version_info [0 :2 ] == (3 , 10 ) and config .online_store .vector_enabled
125+ )
123126 if not self ._conn :
124127 db_path = self ._get_db_path (config )
125- self ._conn = _initialize_conn (db_path )
126- if sys .version_info [0 :2 ] == (3 , 10 ) and config .online_store .vector_enabled :
127- import sqlite_vec # noqa: F401
128-
129- db = sqlite3 .Connection (":memory:" )
130- db .enable_load_extension (True )
131- sqlite_vec .load (db )
132- return db
128+ self ._conn = _initialize_conn (db_path , enable_sqlite_vec )
133129
134130 return self ._conn
135131
@@ -370,9 +366,9 @@ def retrieve_online_documents(
370366 conn = self ._get_conn (config )
371367 cur = conn .cursor ()
372368
369+ # Convert the embedding to a binary format instead of using SerializeToString()
373370 query_embedding_bin = serialize_f32 (embedding , config .online_store .vector_len )
374371 table_name = _table_id (project , table )
375- # Convert the embedding to a binary format instead of using SerializeToString()
376372
377373 cur .execute (
378374 f"""
@@ -572,17 +568,24 @@ def retrieve_online_documents_v2(
572568 return result
573569
574570
575- def _initialize_conn (db_path : str ):
576- try :
577- import sqlite_vec # noqa: F401
578- except ModuleNotFoundError :
579- logging .warning ("Cannot use sqlite_vec for vector search" )
571+ def _initialize_conn (
572+ db_path : str , enable_sqlite_vec : bool = False
573+ ) -> sqlite3 .Connection :
580574 Path (db_path ).parent .mkdir (exist_ok = True )
581575 db = sqlite3 .connect (
582576 db_path ,
583577 detect_types = sqlite3 .PARSE_DECLTYPES | sqlite3 .PARSE_COLNAMES ,
584578 check_same_thread = False ,
585579 )
580+ if enable_sqlite_vec :
581+ try :
582+ import sqlite_vec # noqa: F401
583+ except ModuleNotFoundError :
584+ logging .warning ("Cannot use sqlite_vec for vector search" )
585+
586+ db .enable_load_extension (True )
587+ sqlite_vec .load (db )
588+
586589 return db
587590
588591
0 commit comments