Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions sdk/python/feast/infra/online_stores/sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import itertools
import logging
import os
import sqlite3
import struct
Expand All @@ -20,7 +21,6 @@
from pathlib import Path
from typing import Any, Callable, Dict, List, Literal, Optional, Sequence, Tuple, Union

import sqlite_vec
from google.protobuf.internal.containers import RepeatedScalarFieldContainer
from pydantic import StrictStr

Expand Down Expand Up @@ -84,7 +84,9 @@ def _get_conn(self, config: RepoConfig):
if not self._conn:
db_path = self._get_db_path(config)
self._conn = _initialize_conn(db_path)
if sys.version_info[0:2] == (3, 10):
if sys.version_info[0:2] == (3, 10) and config.online_store.vec_enabled:
import sqlite_vec # noqa: F401

self._conn.enable_load_extension(True) # type: ignore
sqlite_vec.load(self._conn)

Expand Down Expand Up @@ -410,6 +412,10 @@ def retrieve_online_documents(


def _initialize_conn(db_path: str):
try:
import sqlite_vec # noqa: F401
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this import used anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah that code already exists

except ModuleNotFoundError:
logging.warning("Cannot use sqlite_vec for vector search")
Path(db_path).parent.mkdir(exist_ok=True)
return sqlite3.connect(
db_path,
Expand Down Expand Up @@ -482,8 +488,13 @@ def from_proto(sqlite_table_proto: SqliteTableProto) -> Any:

def update(self):
if sys.version_info[0:2] == (3, 10):
self.conn.enable_load_extension(True)
sqlite_vec.load(self.conn)
try:
import sqlite_vec # noqa: F401

self.conn.enable_load_extension(True)
sqlite_vec.load(self.conn)
except ModuleNotFoundError:
logging.warning("Cannot use sqlite_vec for vector search")
self.conn.execute(
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))"
)
Expand Down