Pre-compute feature vectors for one or all FeatureServices. For each FeatureService with ``precompute_online=True`` (or matching *feature_service_name*), reads every entity's features from the online store via :meth:`OnlineStore.online_read` and writes a single serialized
(
self,
feature_service_name: Optional[str] = None,
batch_size: int = 1000,
)
| 2566 | return fvs_with_push_sources |
| 2567 | |
| 2568 | def precompute_feature_service( |
| 2569 | self, |
| 2570 | feature_service_name: Optional[str] = None, |
| 2571 | batch_size: int = 1000, |
| 2572 | ) -> int: |
| 2573 | """Pre-compute feature vectors for one or all FeatureServices. |
| 2574 | |
| 2575 | For each FeatureService with ``precompute_online=True`` (or matching |
| 2576 | *feature_service_name*), reads every entity's features from the online |
| 2577 | store via :meth:`OnlineStore.online_read` and writes a single serialized |
| 2578 | blob per entity via :meth:`OnlineStore.write_precomputed_vector`. |
| 2579 | |
| 2580 | Works with **all** online store backends (Redis, DynamoDB, PostgreSQL, etc.). |
| 2581 | |
| 2582 | Returns the total number of entity vectors written. |
| 2583 | """ |
| 2584 | from feast.protos.feast.core.PrecomputedFeatureVector_pb2 import ( |
| 2585 | FeatureViewTimestamp, |
| 2586 | PrecomputedFeatureVector, |
| 2587 | ) |
| 2588 | |
| 2589 | provider = self._get_provider() |
| 2590 | online_store = provider.online_store |
| 2591 | |
| 2592 | services = self.registry.list_feature_services(self.project) |
| 2593 | if feature_service_name: |
| 2594 | services = [s for s in services if s.name == feature_service_name] |
| 2595 | |
| 2596 | total_written = 0 |
| 2597 | for svc in services: |
| 2598 | if not svc.precompute_online and not feature_service_name: |
| 2599 | continue |
| 2600 | |
| 2601 | fv_projections = svc.feature_view_projections |
| 2602 | feature_views = [] |
| 2603 | for proj in fv_projections: |
| 2604 | fv = self.registry.get_any_feature_view( |
| 2605 | proj.name, self.project, allow_cache=True |
| 2606 | ) |
| 2607 | feature_views.append((fv, proj)) |
| 2608 | |
| 2609 | if not feature_views: |
| 2610 | continue |
| 2611 | |
| 2612 | feature_names: List[str] = [] |
| 2613 | for _fv, proj in feature_views: |
| 2614 | fv_name = proj.name_to_use() |
| 2615 | for f in proj.features: |
| 2616 | feature_names.append(f"{fv_name}__{f.name}") |
| 2617 | |
| 2618 | # Collect all unique entity key protos from the primary feature view. |
| 2619 | # Use online_read to discover entities that exist in the store. |
| 2620 | primary_fv = feature_views[0][0] |
| 2621 | |
| 2622 | # Read entity keys by scanning the primary FV's online data. |
| 2623 | # We use get_online_features with the full FeatureService to read |
| 2624 | # all features for each entity in a single call, then build vectors. |
| 2625 | # |
no test coverage detected