or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

cli-operations.mddata-sources.mdentities.mdfeature-store.mdfeature-views.mdindex.mdvector-store.md

feature-views.mddocs/

0

# Feature Views

1

2

Feature views define how features are computed, stored, and served in Feast. They specify the schema, data sources, entities, and transformation logic for groups of related features. Different feature view types support various feature engineering patterns from batch processing to real-time transformations.

3

4

## Capabilities

5

6

### Standard Feature Views

7

8

Standard feature views define batch features computed from offline data sources with configurable time-to-live for freshness management.

9

10

```python { .api }

11

class FeatureView:

12

def __init__(

13

self,

14

name: str,

15

entities: List[Union[Entity, str]],

16

schema: List[Field],

17

source: DataSource,

18

ttl: Optional[timedelta] = None,

19

tags: Optional[Dict[str, str]] = None,

20

owner: str = "",

21

description: str = ""

22

):

23

"""

24

Define a standard feature view for batch features.

25

26

Parameters:

27

- name: Unique feature view name

28

- entities: List of entities this view is associated with

29

- schema: List of feature field definitions

30

- source: Data source for feature computation

31

- ttl: Time-to-live for feature freshness (None for no expiration)

32

- tags: Key-value metadata tags

33

- owner: Feature view owner/maintainer

34

- description: Human-readable description

35

"""

36

```

37

38

### Batch Feature Views

39

40

Batch feature views enable complex feature transformations using SQL or Python for advanced feature engineering workflows.

41

42

```python { .api }

43

class BatchFeatureView:

44

def __init__(

45

self,

46

name: str,

47

entities: List[Union[Entity, str]],

48

schema: List[Field],

49

source: DataSource,

50

ttl: Optional[timedelta] = None,

51

batch_source: Optional[DataSource] = None,

52

description: str = "",

53

tags: Optional[Dict[str, str]] = None,

54

owner: str = ""

55

):

56

"""

57

Define a batch feature view with transformation capabilities.

58

59

Parameters:

60

- name: Unique feature view name

61

- entities: Associated entities for join keys

62

- schema: Output feature schema after transformation

63

- source: Primary data source

64

- ttl: Feature time-to-live

65

- batch_source: Optional separate batch processing source

66

- description: Feature view description

67

- tags: Metadata tags

68

- owner: Owner identifier

69

"""

70

```

71

72

### On-Demand Feature Views

73

74

On-demand feature views compute features in real-time during serving using Python transformations applied to request data and existing features.

75

76

```python { .api }

77

class OnDemandFeatureView:

78

def __init__(

79

self,

80

name: str,

81

sources: Dict[str, Union[FeatureView, FeatureService, RequestSource]],

82

schema: List[Field],

83

udf: Union[PythonTransformation, str],

84

description: str = "",

85

tags: Optional[Dict[str, str]] = None,

86

owner: str = ""

87

):

88

"""

89

Define an on-demand feature view with real-time transformations.

90

91

Parameters:

92

- name: Unique feature view name

93

- sources: Dictionary mapping source names to feature views or request sources

94

- schema: Output schema of transformed features

95

- udf: Python transformation function or code string

96

- description: Feature view description

97

- tags: Metadata tags

98

- owner: Owner identifier

99

"""

100

```

101

102

### Stream Feature Views

103

104

Stream feature views process streaming data sources for real-time feature updates and low-latency serving scenarios.

105

106

```python { .api }

107

class StreamFeatureView:

108

def __init__(

109

self,

110

name: str,

111

entities: List[Union[Entity, str]],

112

schema: List[Field],

113

source: Union[KafkaSource, KinesisSource, PushSource],

114

ttl: Optional[timedelta] = None,

115

tags: Optional[Dict[str, str]] = None,

116

owner: str = "",

117

description: str = ""

118

):

119

"""

120

Define a stream feature view for real-time data processing.

121

122

Parameters:

123

- name: Unique feature view name

124

- entities: Associated entities

125

- schema: Feature schema

126

- source: Streaming data source (Kafka, Kinesis, or Push)

127

- ttl: Feature time-to-live

128

- tags: Metadata tags

129

- owner: Owner identifier

130

- description: Feature view description

131

"""

132

```

133

134

### Feature View Operations

135

136

Common operations available across all feature view types for inspection and configuration management.

137

138

```python { .api }

139

def with_name(self, name: str) -> "FeatureView":

140

"""Create a copy with a different name."""

141

142

def with_projection(self, feature_list: List[str]) -> FeatureViewProjection:

143

"""Create a projection with selected features."""

144

145

@property

146

def name(self) -> str:

147

"""Feature view name."""

148

149

@property

150

def entities(self) -> List[str]:

151

"""Associated entity names."""

152

153

@property

154

def features(self) -> List[Field]:

155

"""Feature schema fields."""

156

```

157

158

## Field Definitions

159

160

Feature schema fields define individual features within feature views including their data types and metadata.

161

162

```python { .api }

163

@dataclass

164

class Field:

165

name: str

166

dtype: ValueType

167

description: str = ""

168

tags: Optional[Dict[str, str]] = None

169

170

def __init__(

171

self,

172

name: str,

173

dtype: ValueType,

174

description: str = "",

175

tags: Optional[Dict[str, str]] = None

176

):

177

"""

178

Define a feature field.

179

180

Parameters:

181

- name: Feature name

182

- dtype: Feature data type (ValueType)

183

- description: Feature description

184

- tags: Feature-level metadata tags

185

"""

186

```

187

188

## Usage Examples

189

190

### Standard Feature View Creation

191

192

```python

193

from feast import FeatureView, Entity, Field, FileSource, ValueType

194

from datetime import timedelta

195

196

# Define entities

197

driver = Entity(name="driver", value_type=ValueType.INT64)

198

199

# Define data source

200

driver_source = FileSource(

201

path="data/driver_stats.parquet",

202

timestamp_field="event_timestamp"

203

)

204

205

# Create feature view

206

driver_hourly_stats = FeatureView(

207

name="driver_hourly_stats",

208

entities=[driver],

209

ttl=timedelta(hours=1),

210

schema=[

211

Field(

212

name="conv_rate",

213

dtype=ValueType.FLOAT,

214

description="Driver conversion rate"

215

),

216

Field(

217

name="acc_rate",

218

dtype=ValueType.FLOAT,

219

description="Driver acceptance rate"

220

),

221

Field(

222

name="avg_daily_trips",

223

dtype=ValueType.INT64,

224

description="Average daily trips"

225

)

226

],

227

source=driver_source,

228

description="Hourly driver performance statistics",

229

tags={"team": "ml-platform", "domain": "transportation"},

230

owner="ml-team@company.com"

231

)

232

```

233

234

### On-Demand Feature View with Transformations

235

236

```python

237

from feast import OnDemandFeatureView, RequestSource

238

from feast.transformation.python_transformation import PythonTransformation

239

240

# Define request source for real-time data

241

request_source = RequestSource(

242

name="request_data",

243

schema=[

244

Field(name="val_to_add", dtype=ValueType.INT64),

245

Field(name="val_to_add_2", dtype=ValueType.INT64)

246

]

247

)

248

249

# Define transformation function

250

@feast.on_demand_feature_view(

251

sources={"driver_stats": driver_hourly_stats, "input_request": request_source},

252

schema=[

253

Field(name="conv_rate_plus_val1", dtype=ValueType.DOUBLE),

254

Field(name="conv_rate_plus_val2", dtype=ValueType.DOUBLE)

255

]

256

)

257

def transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame:

258

df = pd.DataFrame()

259

df["conv_rate_plus_val1"] = inputs["conv_rate"] + inputs["val_to_add"]

260

df["conv_rate_plus_val2"] = inputs["conv_rate"] + inputs["val_to_add_2"]

261

return df

262

```

263

264

### Stream Feature View for Real-time Data

265

266

```python

267

from feast import StreamFeatureView, KafkaSource

268

from feast.data_format import JsonFormat

269

270

# Define Kafka source

271

kafka_source = KafkaSource(

272

kafka_bootstrap_servers="localhost:9092",

273

message_format=JsonFormat(schema_json=""),

274

topic="driver_events",

275

timestamp_field="event_timestamp"

276

)

277

278

# Create stream feature view

279

driver_stream_features = StreamFeatureView(

280

name="driver_activity_stream",

281

entities=[driver],

282

schema=[

283

Field(name="trips_today", dtype=ValueType.INT64),

284

Field(name="earnings_today", dtype=ValueType.DOUBLE),

285

Field(name="hours_worked", dtype=ValueType.FLOAT)

286

],

287

source=kafka_source,

288

ttl=timedelta(minutes=30),

289

description="Real-time driver activity metrics"

290

)

291

```

292

293

### Feature View Projections and Selection

294

295

```python

296

# Create feature view projection with selected features

297

driver_projection = driver_hourly_stats.with_projection([

298

"conv_rate",

299

"acc_rate"

300

])

301

302

# Use projection in feature service

303

from feast import FeatureService

304

305

driver_ranking_service = FeatureService(

306

name="driver_ranking",

307

features=[driver_projection]

308

)

309

310

# Create renamed copy

311

driver_daily_stats = driver_hourly_stats.with_name("driver_daily_stats")

312

```

313

314

### Multi-Entity Feature Views

315

316

```python

317

# Define multiple entities

318

customer = Entity(name="customer", value_type=ValueType.INT64)

319

product = Entity(name="product", value_type=ValueType.STRING)

320

321

# Multi-entity data source

322

order_source = FileSource(

323

path="data/order_features.parquet",

324

timestamp_field="order_timestamp"

325

)

326

327

# Multi-entity feature view

328

order_features = FeatureView(

329

name="customer_product_features",

330

entities=[customer, product],

331

schema=[

332

Field(name="order_count_7d", dtype=ValueType.INT64),

333

Field(name="total_spent_7d", dtype=ValueType.DOUBLE),

334

Field(name="avg_order_value", dtype=ValueType.DOUBLE)

335

],

336

source=order_source,

337

ttl=timedelta(days=1),

338

description="Customer-product interaction features"

339

)

340

```

341

342

## Types

343

344

```python { .api }

345

class FeatureViewProjection:

346

"""Projection of selected features from a feature view."""

347

348

@property

349

def name(self) -> str:

350

"""Projected feature view name."""

351

352

@property

353

def features(self) -> List[Field]:

354

"""Selected feature fields."""

355

356

class PythonTransformation:

357

"""Python transformation for on-demand feature views."""

358

359

def __init__(self, udf: Callable, udf_string: str = ""):

360

"""

361

Parameters:

362

- udf: Python function for transformation

363

- udf_string: String representation of the function

364

"""

365

```