Skip to content

Commit 398ea3b

Browse files
fix: Fix SQLite import issue (feast-dev#4294)
adding try and except block for import Co-authored-by: Francisco Javier Arceo <franciscojavierarceo@users.noreply.github.com>
1 parent 7072fd0 commit 398ea3b

File tree

1 file changed

+15
-4
lines changed
  • sdk/python/feast/infra/online_stores

1 file changed

+15
-4
lines changed

sdk/python/feast/infra/online_stores/sqlite.py

+15-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
import itertools
15+
import logging
1516
import os
1617
import sqlite3
1718
import struct
@@ -20,7 +21,6 @@
2021
from pathlib import Path
2122
from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Tuple, Union
2223

23-
import sqlite_vec
2424
from google.protobuf.internal.containers import RepeatedScalarFieldContainer
2525
from pydantic import StrictStr
2626

@@ -84,7 +84,9 @@ def _get_conn(self, config: RepoConfig):
8484
if not self._conn:
8585
db_path = self._get_db_path(config)
8686
self._conn = _initialize_conn(db_path)
87-
if sys.version_info[0:2] == (3, 10):
87+
if sys.version_info[0:2] == (3, 10) and config.online_store.vec_enabled:
88+
import sqlite_vec # noqa: F401
89+
8890
self._conn.enable_load_extension(True) # type: ignore
8991
sqlite_vec.load(self._conn)
9092

@@ -410,6 +412,10 @@ def retrieve_online_documents(
410412

411413

412414
def _initialize_conn(db_path: str):
415+
try:
416+
import sqlite_vec # noqa: F401
417+
except ModuleNotFoundError:
418+
logging.warning("Cannot use sqlite_vec for vector search")
413419
Path(db_path).parent.mkdir(exist_ok=True)
414420
return sqlite3.connect(
415421
db_path,
@@ -482,8 +488,13 @@ def from_proto(sqlite_table_proto: SqliteTableProto) -> Any:
482488

483489
def update(self):
484490
if sys.version_info[0:2] == (3, 10):
485-
self.conn.enable_load_extension(True)
486-
sqlite_vec.load(self.conn)
491+
try:
492+
import sqlite_vec # noqa: F401
493+
494+
self.conn.enable_load_extension(True)
495+
sqlite_vec.load(self.conn)
496+
except ModuleNotFoundError:
497+
logging.warning("Cannot use sqlite_vec for vector search")
487498
self.conn.execute(
488499
f"CREATE TABLE IF NOT EXISTS {self.name} (entity_key BLOB, feature_name TEXT, value BLOB, vector_value BLOB, event_ts timestamp, created_ts timestamp, PRIMARY KEY(entity_key, feature_name))"
489500
)

0 commit comments

Comments
 (0)