Skip to content
Prev Previous commit
Next Next commit
updated docs
Signed-off-by: Francisco Javier Arceo <farceo@redhat.com>
  • Loading branch information
franciscojavierarceo committed Dec 20, 2025
commit 0f94a908c9ba4e9c9ba55f380cb922864be683bc
108 changes: 108 additions & 0 deletions docs/reference/feature-servers/python-feature-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,114 @@ To start the feature server in TLS mode, you need to provide the private and pub
feast serve --key /path/to/key.pem --cert /path/to/cert.pem
```

# Static Artifacts Loading

## Overview

Static artifacts loading allows you to load models, lookup tables, and other static resources once during feature server startup instead of loading them on each request. These artifacts are cached in memory and accessible to on-demand feature views.

## Usage

### Create Static Artifacts Module

Create a `static_artifacts.py` file in your feature repository:

```python
# static_artifacts.py
from fastapi import FastAPI
from transformers import pipeline

def load_sentiment_model():
"""Load sentiment analysis model."""
return pipeline(
"sentiment-analysis",
model="cardiffnlp/twitter-roberta-base-sentiment-latest",
device="cpu"
)

def load_lookup_tables():
"""Load static lookup tables."""
return {
"sentiment_labels": {"LABEL_0": "negative", "LABEL_1": "neutral", "LABEL_2": "positive"},
"domain_categories": {"twitter.com": "social", "news.com": "news"},
}

def load_artifacts(app: FastAPI):
"""Load static artifacts into app.state."""
app.state.sentiment_model = load_sentiment_model()
app.state.lookup_tables = load_lookup_tables()

# Update global references for access from feature views
import example_repo
example_repo._sentiment_model = app.state.sentiment_model
example_repo._lookup_tables = app.state.lookup_tables
```

### Use Artifacts in Feature Views

Access pre-loaded artifacts in your on-demand feature views:

```python
# example_repo.py
import pandas as pd
from feast.on_demand_feature_view import on_demand_feature_view

# Global references for static artifacts
_sentiment_model = None
_lookup_tables: dict = {}

@on_demand_feature_view(
sources=[text_input_request],
schema=[
Field(name="predicted_sentiment", dtype=String),
Field(name="sentiment_confidence", dtype=Float32),
],
)
def sentiment_prediction(inputs: pd.DataFrame) -> pd.DataFrame:
"""Sentiment prediction using pre-loaded artifacts."""
global _sentiment_model, _lookup_tables

results = []
for text in inputs["input_text"]:
predictions = _sentiment_model(text)
label_map = _lookup_tables["sentiment_labels"]
best_pred = max(predictions, key=lambda x: x["score"])
predicted_sentiment = label_map[best_pred["label"]]
confidence = best_pred["score"]

results.append({
"predicted_sentiment": predicted_sentiment,
"sentiment_confidence": confidence,
})

return pd.DataFrame(results)
```

### Start Feature Server

```bash
feast serve
```

The server will automatically load static artifacts during startup.

## Supported Artifact Types

- Small to medium ML models
- Lookup tables and reference data
- Configuration parameters
- Pre-computed embeddings

## Example Template

The PyTorch NLP template demonstrates static artifacts loading:

```bash
feast init my-nlp-project -t pytorch_nlp
cd my-nlp-project/feature_repo
feast serve
```

# Online Feature Server Permissions and Access Control

## API Endpoints and Permissions
Expand Down
Loading