|
12 | 12 | # See the License for the specific language governing permissions and |
13 | 13 | # limitations under the License. |
14 | 14 | import itertools |
| 15 | +import logging |
15 | 16 | import os |
16 | 17 | import sqlite3 |
17 | 18 | import struct |
|
20 | 21 | from pathlib import Path |
21 | 22 | from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Tuple, Union |
22 | 23 |
|
23 | | -import sqlite_vec |
24 | 24 | from google.protobuf.internal.containers import RepeatedScalarFieldContainer |
25 | 25 | from pydantic import StrictStr |
26 | 26 |
|
@@ -84,7 +84,9 @@ def _get_conn(self, config: RepoConfig): |
84 | 84 | if not self._conn: |
85 | 85 | db_path = self._get_db_path(config) |
86 | 86 | 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 | + |
88 | 90 | self._conn.enable_load_extension(True) # type: ignore |
89 | 91 | sqlite_vec.load(self._conn) |
90 | 92 |
|
@@ -410,6 +412,10 @@ def retrieve_online_documents( |
410 | 412 |
|
411 | 413 |
|
412 | 414 | 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") |
413 | 419 | Path(db_path).parent.mkdir(exist_ok=True) |
414 | 420 | return sqlite3.connect( |
415 | 421 | db_path, |
@@ -482,8 +488,13 @@ def from_proto(sqlite_table_proto: SqliteTableProto) -> Any: |
482 | 488 |
|
483 | 489 | def update(self): |
484 | 490 | 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") |
487 | 498 | self.conn.execute( |
488 | 499 | 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))" |
489 | 500 | ) |
|
0 commit comments