Visitar URL original
feat: MongoDB offline store by caseyclements · Pull Request #6138 · feast-dev/feast · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
d2c637d
feat: Add MongoDB offline store (ibis-based PIT join, v1 alpha)
caseyclements Mar 3, 2026
77f243e
refactor: improve MongoDB offline store code quality
caseyclements Mar 4, 2026
bb134a2
Started work on full Mongo/MQL implementation. Kept MongoDBOfflineSto…
caseyclements Mar 9, 2026
46e67b7
refactor: rename alpha to preview, clarify MQL pipeline comments
caseyclements Mar 17, 2026
d0c00ca
Added unit tests for offline store retrieval, requiring docker and py…
caseyclements Mar 17, 2026
c940d05
Added test of multiple feature views and compound join keys
caseyclements Mar 17, 2026
37fad38
Initial implementation of native single-collection offline store
caseyclements Mar 17, 2026
67c39d4
Added DriverInfo to MongoDBClients
caseyclements Mar 18, 2026
7987405
Optimized MQL. Applied FV-level TTL
caseyclements Mar 18, 2026
adf1fb0
filter TTL by relevant FVs only, cautiously reset df index; add creat…
caseyclements Mar 18, 2026
ed1571e
Updated docstrings
caseyclements Mar 18, 2026
c09faee
Lazy index creation via _get_client_and_ensure_indexes
caseyclements Mar 18, 2026
91e939c
Add performance benchmarks comparing Ibis vs Native MongoDB offline s…
caseyclements Mar 18, 2026
e4bfc31
Refactor Native get_historical_features: replace with fetch+pandas join
caseyclements Mar 18, 2026
6218fa8
Refactor get_historical_features with chunked processing for large en…
caseyclements Mar 19, 2026
b7ffd84
Optimize Native get_historical_features: reuse client, increase batch…
caseyclements Mar 19, 2026
affdc2d
Remove duplicate MongoDBOfflineStoreNative from mongodb.py
caseyclements Mar 19, 2026
afef4fd
Consolidate mongodb_source.py into mongodb.py
caseyclements Mar 19, 2026
f273744
Rename mongodb_offline_store to mongodb, use One/Many naming convention
caseyclements Mar 19, 2026
df00e47
Add README.md documenting MongoDB offline store implementations
caseyclements Mar 20, 2026
83d063b
Rename mongodb/ to mongodb_offline_store/, organize tests
caseyclements Mar 20, 2026
977c240
Update docstring in benchmark.py
caseyclements Mar 20, 2026
166d151
Update README to show created_at tie-breaker in Many schema
caseyclements Mar 20, 2026
fe24361
Update README index recommendations for Many implementation
caseyclements Mar 20, 2026
398110c
Add auto-create index to MongoDBOfflineStoreMany
caseyclements Mar 20, 2026
2feb97d
Update benchmark.py to use One/Many naming convention
caseyclements Mar 20, 2026
9624311
Add comprehensive module docstring to mongodb_many.py
caseyclements Mar 20, 2026
5c93a51
Add Feature Freshness and Schema Evolution docs to mongodb_many.py
caseyclements Mar 20, 2026
fd70c13
Add MongoDB DataSourceCreators for universal Feast tests
caseyclements Mar 20, 2026
b4a0260
Add .secrets.baseline
caseyclements Mar 20, 2026
9efd700
Addressed PR comment: join_keys = get_expected_join_keys(project, fea…
caseyclements Apr 14, 2026
5d67b3f
Adds tests scenario that not using offline_utils.get_expected_join_ke…
caseyclements Apr 14, 2026
f889e10
Tests revealed possible name collision in pandas.merge_asof
caseyclements Apr 15, 2026
fcbd609
Add further (Large) benchmark tests
caseyclements Apr 15, 2026
7786393
Upgrades from Devin comments. Class cache _index_initialized; get_exp…
caseyclements Apr 15, 2026
b8fa01c
Addressed PR comments
caseyclements Apr 15, 2026
6db7cce
Apply lower bound via max(TTL) when all feature viewws in a chunk hav…
caseyclements Apr 15, 2026
596b126
Add created_at to compound index so that materialization is correct i…
caseyclements Apr 15, 2026
c0173e0
Handdle numpy scalers in _serialize_entity_key_from_row as suggested.
caseyclements Apr 15, 2026
1f80f47
Add persist and tests
caseyclements Apr 15, 2026
daaaf32
Remove accidentally included design notes.
caseyclements Apr 15, 2026
3a78f9d
Fix entity key serialization: per-FV join key types and numpy 2.0 compat
caseyclements Apr 16, 2026
44abd92
Add offline_write_batch to MongoDBOfflineStoreOne
caseyclements Apr 16, 2026
63fab1b
mongodb_one: clarify pipeline sort rationale and avoid sparse-column …
caseyclements Apr 16, 2026
90dd224
Add mongodb_native.py: initial MQL-based offline store (pre-refactor …
caseyclements Apr 17, 2026
0733688
Refactor mongodb_native: Atlas-first $documents+$lookup PIT join
caseyclements Apr 17, 2026
47f1040
Add unit tests for MongoDBOfflineStoreNative
caseyclements Apr 17, 2026
84ac27b
Add cross-implementation equivalence suite (test_cross.py)
caseyclements Apr 17, 2026
8346f28
Add benchmark_sweep.py: four-dimensional scaling suite across all thr…
caseyclements Apr 17, 2026
448a698
Add mongodb_agg offline store — $match+$sort+$group, O(log P) without…
caseyclements Apr 19, 2026
810b7d0
Vectorize agg scoring path, add upfront index build, ignore design/
caseyclements Apr 19, 2026
2a56c13
Adds offline_write_batch
caseyclements Apr 20, 2026
7e35e6a
Adds detail to handling of K in benchmarks.
caseyclements Apr 20, 2026
fcbb8e1
Adds missing typing.
caseyclements Apr 21, 2026
6e8f502
Consolidate MongoDB offline store to single implementation
caseyclements Apr 23, 2026
a6dca86
Fixes strict_pit_false unit test.
caseyclements Apr 23, 2026
055d238
Fix MongoDB offline store: projection keying, TTL bounds, field mappi…
caseyclements Apr 24, 2026
136dc09
Fix MongoDB test DataSourceCreator: implement create_logged_features_…
caseyclements Apr 24, 2026
f7e6230
Fix pd.isna() ValueError on list/array features in offline_write_batch
caseyclements Apr 24, 2026
9d9f7f1
Merge branch 'master' into FEAST-OfflineStore-INTPYTHON-297
caseyclements Apr 24, 2026
274e6f8
Fix bool/int type inference order in get_table_column_names_and_types
caseyclements Apr 24, 2026
fcb92da
Fix mongodb_to_feast_value_type to accept type strings from get_table…
caseyclements Apr 24, 2026
23b6788
Sort join keys in _serialize_entity_key_from_row for consistent entit…
caseyclements Apr 24, 2026
26b5153
Resolve .secrets.baseline merge conflict with master
caseyclements Apr 24, 2026
5227804
Add mongodb to CI extras so pymongo is installed in CI
caseyclements Apr 24, 2026
2905b80
Remove MongoDB from universal test parametrization
caseyclements Apr 24, 2026
a9b9e8f
Regenerate pixi lockfile after pymongo addition to ci extras
caseyclements Apr 24, 2026
f558aa5
Fix scoring_path heuristic: check entity uniqueness per-FV, not globally
caseyclements Apr 28, 2026
349c5f1
Fix offline_write_batch: use original join key names for entity seria…
caseyclements Apr 28, 2026
8f8de11
Fix pull_latest and pull_all to return join key columns
caseyclements Apr 28, 2026
9de5548
Fix scoring_path: require homogeneous timestamps to prevent data loss
caseyclements Apr 29, 2026
c34b6cd
Fix training path: sort fv_df by created_at to break event_timestamp …
caseyclements Apr 29, 2026
1d2a1c9
Clean up stale docstrings: remove references to MongoDBOfflineStoreOn…
caseyclements Apr 29, 2026
02e457c
Clean up stale docstrings: remove references to MongoDBOfflineStoreOn…
caseyclements Apr 29, 2026
ae5256f
Added driver metadata to clients
caseyclements Apr 30, 2026
f1996fc
Update .secrets.baseline
caseyclements Apr 30, 2026
b3b7563
Remove preview warnings from MongoDB offline store
caseyclements Apr 30, 2026
4a43815
Merge branch 'master' into FEAST-OfflineStore-INTPYTHON-297
caseyclements Apr 30, 2026
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
Next Next commit
feat: Add MongoDB offline store (ibis-based PIT join, v1 alpha)
- MongoDBSource: DataSource backed by a MongoDB collection, schema
  sampled via \ aggregation (default N=100)
- MongoDBOfflineStoreConfig: connection_string + default database
- MongoDBOfflineStore: delegates to ibis PIT join engine via
  in-memory memtable approach
- SavedDatasetMongoDBStorage: persist training datasets to MongoDB
- _build_data_source_reader/_build_data_source_writer closures capture
  config (connection_string, database) for MongoDB access

Signed-off-by: Casey Clements <casey.clements@mongodb.com>
  • Loading branch information
caseyclements committed Apr 24, 2026
commit d2c637d25a33378a08db7e0346fd12b3083aa12b
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
# Copyright 2025 The Feast Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import warnings
from datetime import datetime
from typing import Any, Callable, List, Optional, Union

import ibis
import pandas as pd
from ibis.expr.types import Table
from pydantic import StrictStr

try:
from pymongo import MongoClient
except ImportError:
MongoClient = None # type: ignore[assignment,misc]

from feast.data_source import DataSource
from feast.errors import (
FeastExtrasDependencyImportError,
SavedDatasetLocationAlreadyExists,
)
from feast.feature_view import FeatureView
from feast.infra.offline_stores.contrib.mongodb_offline_store.mongodb_source import (
MongoDBSource,
)
from feast.infra.offline_stores.ibis import (
get_historical_features_ibis,
pull_all_from_table_or_query_ibis,
pull_latest_from_table_or_query_ibis,
)
from feast.infra.offline_stores.offline_store import OfflineStore, RetrievalJob
from feast.infra.registry.base_registry import BaseRegistry
from feast.repo_config import FeastConfigBaseModel, RepoConfig

# Print RuntimeWarning only once per process.
warnings.simplefilter("once", RuntimeWarning)


class MongoDBOfflineStoreConfig(FeastConfigBaseModel):
"""Configuration for the MongoDB offline store."""

type: StrictStr = "feast.infra.offline_stores.contrib.mongodb_offline_store.mongodb.MongoDBOfflineStore"
"""Offline store type selector"""

connection_string: StrictStr = "mongodb://localhost:27017"
"""MongoDB connection URI"""

database: StrictStr = "feast"
"""Default MongoDB database name"""


class MongoDBOfflineStore(OfflineStore):
"""Offline store backed by MongoDB, using ibis for point-in-time joins."""

@staticmethod
def pull_latest_from_table_or_query(
config: RepoConfig,
data_source: DataSource,
join_key_columns: List[str],
feature_name_columns: List[str],
timestamp_field: str,
created_timestamp_column: Optional[str],
start_date: datetime,
end_date: datetime,
) -> RetrievalJob:
assert isinstance(data_source, MongoDBSource)
warnings.warn(
"MongoDB offline store is in alpha. API may change without notice.",
RuntimeWarning,
)
return pull_latest_from_table_or_query_ibis(
config=config,
data_source=data_source,
join_key_columns=join_key_columns,
feature_name_columns=feature_name_columns,
timestamp_field=timestamp_field,
created_timestamp_column=created_timestamp_column,
start_date=start_date,
end_date=end_date,
data_source_reader=_build_data_source_reader(config),
data_source_writer=_build_data_source_writer(config), # type: ignore[arg-type]
)

@staticmethod
def get_historical_features(
config: RepoConfig,
feature_views: List[FeatureView],
feature_refs: List[str],
entity_df: Union[pd.DataFrame, str],
registry: BaseRegistry,
project: str,
full_feature_names: bool = False,
) -> RetrievalJob:
warnings.warn(
"MongoDB offline store is in alpha. API may change without notice.",
RuntimeWarning,
)
return get_historical_features_ibis(
config=config,
feature_views=feature_views,
feature_refs=feature_refs,
entity_df=entity_df,
registry=registry,
project=project,
full_feature_names=full_feature_names,
data_source_reader=_build_data_source_reader(config),
data_source_writer=_build_data_source_writer(config), # type: ignore[arg-type]
)

@staticmethod
def pull_all_from_table_or_query(
config: RepoConfig,
data_source: DataSource,
join_key_columns: List[str],
feature_name_columns: List[str],
timestamp_field: str,
created_timestamp_column: Optional[str] = None,
start_date: Optional[datetime] = None,
end_date: Optional[datetime] = None,
) -> RetrievalJob:
assert isinstance(data_source, MongoDBSource)
warnings.warn(
"MongoDB offline store is in alpha. API may change without notice.",
RuntimeWarning,
)
return pull_all_from_table_or_query_ibis(
config=config,
data_source=data_source,
join_key_columns=join_key_columns,
feature_name_columns=feature_name_columns,
timestamp_field=timestamp_field,
created_timestamp_column=created_timestamp_column,
start_date=start_date,
end_date=end_date,
data_source_reader=_build_data_source_reader(config),
data_source_writer=_build_data_source_writer(config), # type: ignore[arg-type]
)


def _build_data_source_reader(config: RepoConfig) -> Callable[[DataSource, str], Table]:
"""Return a closure that fetches a MongoDB collection as an ibis in-memory table."""

def reader(data_source: DataSource, repo_path: str) -> Table:
if MongoClient is None:
raise FeastExtrasDependencyImportError(
"mongodb", "pymongo is not installed."
)
assert isinstance(data_source, MongoDBSource)
connection_string = config.offline_store.connection_string
db_name = data_source.database or config.offline_store.database
client: Any = MongoClient(connection_string, tz_aware=True)
try:
docs = list(client[db_name][data_source.collection].find({}, {"_id": 0}))
finally:
client.close()

df = pd.DataFrame(docs)
if df.empty:
return ibis.memtable(df)

# Ensure datetime-like columns are timezone-aware UTC pandas timestamps.
for col in df.columns:
if pd.api.types.is_datetime64_any_dtype(df[col]):
if df[col].dt.tz is None:
df[col] = pd.to_datetime(df[col], utc=True)
elif df[col].dtype == object and len(df[col].dropna()) > 0:
sample = df[col].dropna().iloc[0]
if isinstance(sample, datetime):
try:
df[col] = pd.to_datetime(df[col], utc=True)
except Exception:
pass

return ibis.memtable(df)

return reader


def _build_data_source_writer(
config: RepoConfig,
) -> Callable[[Table, DataSource, str, str, bool], None]:
"""Return a closure that writes an ibis table to a MongoDB collection."""

def writer(
table: Table,
data_source: DataSource,
repo_path: str,
mode: str = "append",
allow_overwrite: bool = False,
) -> None:
if MongoClient is None:
raise FeastExtrasDependencyImportError(
"mongodb", "pymongo is not installed."
)
assert isinstance(data_source, MongoDBSource)
connection_string = config.offline_store.connection_string
db_name = data_source.database or config.offline_store.database
location = f"{db_name}.{data_source.collection}"
client: Any = MongoClient(connection_string)
try:
coll = client[db_name][data_source.collection]
if mode == "overwrite":
if not allow_overwrite and coll.estimated_document_count() > 0:
raise SavedDatasetLocationAlreadyExists(location=location)
coll.drop()
records = table.to_pyarrow().to_pylist()
if records:
coll.insert_many(records)
finally:
client.close()

return writer
Loading