|
| 1 | +--- |
| 2 | +name: feast-user-guide |
| 3 | +description: Guide for working with Feast (Feature Store) — defining features, configuring feature_store.yaml, retrieving features online/offline, using the CLI, and building RAG retrieval pipelines. Use when the user asks about creating entities, feature views, on-demand feature views, stream feature views, feature services, data sources, feature_store.yaml configuration, feast apply/materialize commands, online or historical feature retrieval, or vector-based document retrieval with Feast. |
| 4 | +license: Apache-2.0 |
| 5 | +compatibility: Works with Claude Code, OpenAI Codex, and any Agent Skills compatible tool. |
| 6 | +metadata: |
| 7 | + author: feast-dev |
| 8 | + version: "1.0" |
| 9 | +--- |
| 10 | + |
| 11 | +# Feast User Guide |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +A Feast project requires: |
| 16 | +1. A `feature_store.yaml` config file |
| 17 | +2. Python files defining entities, data sources, feature views, and feature services |
| 18 | +3. Running `feast apply` to register definitions |
| 19 | + |
| 20 | +```bash |
| 21 | +feast init my_project |
| 22 | +cd my_project |
| 23 | +feast apply |
| 24 | +``` |
| 25 | + |
| 26 | +## Core Concepts |
| 27 | + |
| 28 | +### Entity |
| 29 | +An entity is a collection of semantically related features (e.g., a customer, a driver). Entities have join keys used to look up features. |
| 30 | + |
| 31 | +```python |
| 32 | +from feast import Entity |
| 33 | +from feast.value_type import ValueType |
| 34 | + |
| 35 | +driver = Entity( |
| 36 | + name="driver_id", |
| 37 | + description="Driver identifier", |
| 38 | + value_type=ValueType.INT64, |
| 39 | +) |
| 40 | +``` |
| 41 | + |
| 42 | +### Data Sources |
| 43 | +Data sources describe where raw feature data lives. |
| 44 | + |
| 45 | +```python |
| 46 | +from feast import FileSource, BigQuerySource, KafkaSource, PushSource, RequestSource |
| 47 | +from feast.data_format import ParquetFormat |
| 48 | + |
| 49 | +# Batch source (file) |
| 50 | +driver_stats_source = FileSource( |
| 51 | + name="driver_stats_source", |
| 52 | + path="data/driver_stats.parquet", |
| 53 | + timestamp_field="event_timestamp", |
| 54 | + created_timestamp_column="created", |
| 55 | +) |
| 56 | + |
| 57 | +# Request source (for on-demand features) |
| 58 | +input_request = RequestSource( |
| 59 | + name="vals_to_add", |
| 60 | + schema=[Field(name="val_to_add", dtype=Float64)], |
| 61 | +) |
| 62 | +``` |
| 63 | + |
| 64 | +### FeatureView |
| 65 | +Maps features from a data source to entities with a schema, TTL, and online/offline settings. |
| 66 | + |
| 67 | +```python |
| 68 | +from feast import FeatureView, Field |
| 69 | +from feast.types import Float32, Int64, String |
| 70 | +from datetime import timedelta |
| 71 | + |
| 72 | +driver_hourly_stats = FeatureView( |
| 73 | + name="driver_hourly_stats", |
| 74 | + entities=[driver], |
| 75 | + ttl=timedelta(days=365), |
| 76 | + schema=[ |
| 77 | + Field(name="conv_rate", dtype=Float32), |
| 78 | + Field(name="acc_rate", dtype=Float32), |
| 79 | + Field(name="avg_daily_trips", dtype=Int64), |
| 80 | + ], |
| 81 | + online=True, |
| 82 | + source=driver_stats_source, |
| 83 | +) |
| 84 | +``` |
| 85 | + |
| 86 | +### OnDemandFeatureView |
| 87 | +Computes features at request time from other feature views and/or request data. |
| 88 | + |
| 89 | +```python |
| 90 | +from feast import on_demand_feature_view |
| 91 | +import pandas as pd |
| 92 | + |
| 93 | +@on_demand_feature_view( |
| 94 | + sources=[driver_hourly_stats, input_request], |
| 95 | + schema=[Field(name="conv_rate_plus_val", dtype=Float64)], |
| 96 | + mode="pandas", |
| 97 | +) |
| 98 | +def transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame: |
| 99 | + df = pd.DataFrame() |
| 100 | + df["conv_rate_plus_val"] = inputs["conv_rate"] + inputs["val_to_add"] |
| 101 | + return df |
| 102 | +``` |
| 103 | + |
| 104 | +### FeatureService |
| 105 | +Groups features from multiple views for retrieval. |
| 106 | + |
| 107 | +```python |
| 108 | +from feast import FeatureService |
| 109 | + |
| 110 | +driver_fs = FeatureService( |
| 111 | + name="driver_ranking", |
| 112 | + features=[driver_hourly_stats, transformed_conv_rate], |
| 113 | +) |
| 114 | +``` |
| 115 | + |
| 116 | +## Feature Retrieval |
| 117 | + |
| 118 | +### Online (low-latency) |
| 119 | +```python |
| 120 | +from feast import FeatureStore |
| 121 | + |
| 122 | +store = FeatureStore(repo_path=".") |
| 123 | + |
| 124 | +features = store.get_online_features( |
| 125 | + features=[ |
| 126 | + "driver_hourly_stats:conv_rate", |
| 127 | + "driver_hourly_stats:acc_rate", |
| 128 | + ], |
| 129 | + entity_rows=[{"driver_id": 1001}, {"driver_id": 1002}], |
| 130 | +).to_dict() |
| 131 | +``` |
| 132 | + |
| 133 | +### Historical (training data with point-in-time joins) |
| 134 | +```python |
| 135 | +entity_df = pd.DataFrame({ |
| 136 | + "driver_id": [1001, 1002], |
| 137 | + "event_timestamp": [datetime(2023, 1, 1), datetime(2023, 1, 2)], |
| 138 | +}) |
| 139 | + |
| 140 | +training_df = store.get_historical_features( |
| 141 | + entity_df=entity_df, |
| 142 | + features=["driver_hourly_stats:conv_rate", "driver_hourly_stats:acc_rate"], |
| 143 | +).to_df() |
| 144 | +``` |
| 145 | + |
| 146 | +Or use a FeatureService: |
| 147 | +```python |
| 148 | +training_df = store.get_historical_features( |
| 149 | + entity_df=entity_df, |
| 150 | + features=driver_fs, |
| 151 | +).to_df() |
| 152 | +``` |
| 153 | + |
| 154 | +## Materialization |
| 155 | + |
| 156 | +Load features from offline store into online store: |
| 157 | + |
| 158 | +```bash |
| 159 | +# Full materialization over a time range |
| 160 | +feast materialize 2023-01-01T00:00:00 2023-12-31T23:59:59 |
| 161 | + |
| 162 | +# Incremental (from last materialized timestamp) |
| 163 | +feast materialize-incremental $(date -u +"%Y-%m-%dT%H:%M:%S") |
| 164 | +``` |
| 165 | + |
| 166 | +Python API: |
| 167 | +```python |
| 168 | +from datetime import datetime |
| 169 | +store.materialize(start_date=datetime(2023, 1, 1), end_date=datetime(2023, 12, 31)) |
| 170 | +store.materialize_incremental(end_date=datetime.utcnow()) |
| 171 | +``` |
| 172 | + |
| 173 | +## CLI Commands |
| 174 | + |
| 175 | +| Command | Purpose | |
| 176 | +|---------|---------| |
| 177 | +| `feast init [DIR]` | Create new feature repository | |
| 178 | +| `feast apply` | Register/update feature definitions | |
| 179 | +| `feast plan` | Preview changes without applying | |
| 180 | +| `feast materialize START END` | Materialize features to online store | |
| 181 | +| `feast materialize-incremental END` | Incremental materialization | |
| 182 | +| `feast entities list` | List registered entities | |
| 183 | +| `feast feature-views list` | List feature views | |
| 184 | +| `feast feature-services list` | List feature services | |
| 185 | +| `feast on-demand-feature-views list` | List on-demand feature views | |
| 186 | +| `feast teardown` | Remove infrastructure resources | |
| 187 | +| `feast version` | Show SDK version | |
| 188 | + |
| 189 | +Options: `--chdir` / `-c` (run in different directory), `--feature-store-yaml` / `-f` (override config path). |
| 190 | + |
| 191 | +## Vector Search / RAG |
| 192 | + |
| 193 | +Define a feature view with vector fields for similarity search: |
| 194 | + |
| 195 | +```python |
| 196 | +from feast.types import Array, Float32 |
| 197 | + |
| 198 | +wiki_passages = FeatureView( |
| 199 | + name="wiki_passages", |
| 200 | + entities=[passage_entity], |
| 201 | + schema=[ |
| 202 | + Field(name="passage_text", dtype=String), |
| 203 | + Field( |
| 204 | + name="embedding", |
| 205 | + dtype=Array(Float32), |
| 206 | + vector_index=True, |
| 207 | + vector_length=384, |
| 208 | + vector_search_metric="COSINE", |
| 209 | + ), |
| 210 | + ], |
| 211 | + source=passages_source, |
| 212 | + online=True, |
| 213 | +) |
| 214 | +``` |
| 215 | + |
| 216 | +Retrieve similar documents: |
| 217 | +```python |
| 218 | +results = store.retrieve_online_documents( |
| 219 | + feature="wiki_passages:embedding", |
| 220 | + query=query_embedding, |
| 221 | + top_k=5, |
| 222 | +) |
| 223 | +``` |
| 224 | + |
| 225 | +## feature_store.yaml Minimal Config |
| 226 | + |
| 227 | +```yaml |
| 228 | +project: my_project |
| 229 | +registry: data/registry.db |
| 230 | +provider: local |
| 231 | +online_store: |
| 232 | + type: sqlite |
| 233 | + path: data/online_store.db |
| 234 | +``` |
| 235 | +
|
| 236 | +## Common Imports |
| 237 | +
|
| 238 | +```python |
| 239 | +from feast import ( |
| 240 | + Entity, FeatureView, OnDemandFeatureView, FeatureService, |
| 241 | + Field, FileSource, RequestSource, FeatureStore, |
| 242 | +) |
| 243 | +from feast.on_demand_feature_view import on_demand_feature_view |
| 244 | +from feast.types import Float32, Float64, Int64, String, Bool, Array |
| 245 | +from feast.value_type import ValueType |
| 246 | +from datetime import timedelta |
| 247 | +``` |
| 248 | + |
| 249 | +## Detailed References |
| 250 | + |
| 251 | +- **Feature definitions** (all types, parameters, patterns): See [references/feature-definitions.md](references/feature-definitions.md) |
| 252 | +- **Configuration** (feature_store.yaml, all store types, auth): See [references/configuration.md](references/configuration.md) |
| 253 | +- **Retrieval & RAG** (online/offline retrieval, vector search, RAG retriever): See [references/retrieval-and-rag.md](references/retrieval-and-rag.md) |
0 commit comments