Inferensys

Glossary

Contextual Feature Vector

A structured numerical representation of the current user, session, or environmental state that serves as the input to a contextual bandit for action selection.
Data engineer managing feature store on laptop, feature definitions visible, casual data engineering session.
INPUT REPRESENTATION

What is a Contextual Feature Vector?

A contextual feature vector is the structured numerical input that encodes the current state of a user, session, or environment for a contextual bandit algorithm.

A contextual feature vector is a dense, ordered list of numerical values that represents the observable state at the moment of decision-making. It serves as the sole input to a contextual multi-armed bandit model, encoding information such as user demographics, historical behavior, time of day, device type, and session attributes into a format the algorithm can process to predict the expected reward for each available action.

The quality of a contextual feature vector directly determines the bandit's ability to generalize across users and situations. Features are typically served in real-time from a feature store and may include raw attributes, mathematical transformations, or pre-computed user embeddings. Proper feature engineering ensures the model can distinguish between distinct contexts, enabling effective personalization while avoiding the cold-start problem through the use of descriptive side information.

ENGINEERING THE CONTEXT

Key Characteristics of Effective Feature Vectors

A contextual feature vector is only as effective as its design. The following characteristics define vectors that enable a bandit to accurately distinguish between states and learn optimal actions.

01

Predictive Power

The primary purpose of a feature vector is to reduce uncertainty about the expected reward. Every feature must carry a causal or correlational signal that helps the model differentiate between actions. Features that are statistically independent of the outcome add noise and increase the dimensionality without improving the regret minimization objective. Effective vectors focus on variables that directly influence user propensity, such as session intent signals or historical purchase categories, rather than vanity metrics.

02

Computational Efficiency

In real-time decisioning engines operating at millisecond latencies, feature vectors must be lightweight. This requires a balance between expressiveness and cost:

  • Sparse representations reduce memory footprint for high-cardinality categorical data.
  • Dimensionality reduction via PCA or feature hashing prevents the curse of dimensionality.
  • Pre-computed aggregates avoid expensive joins at serving time. A vector that requires heavy transformation during online inference violates the latency budget of a real-time decisioning engine.
03

Non-Stationarity Robustness

Consumer behavior shifts constantly. A robust feature vector captures signals that are stable indicators of intent, not brittle artifacts of a temporary trend. Techniques include:

  • Using relative time windows (e.g., 'items viewed in the last 5 minutes') instead of absolute timestamps.
  • Encoding interaction velocity rather than raw counts to normalize for session length.
  • Incorporating contextual drift monitors to trigger retraining when feature distributions shift. This ensures the model freshness is maintained without manual intervention.
04

Action-Space Alignment

The features must be relevant to the specific action space of the bandit. If the model is selecting a product category, user-level genre preferences are critical. If selecting a discount percentage, price sensitivity scores and margin constraints become vital. A common failure mode is using a generic user embedding for a highly specific decision task. The vector should encode the state relative to the available actions, often achieved through cross-features that combine user context with action attributes.

05

Clean Logging & Replayability

For off-policy evaluation and debugging, the exact feature vector used at decision time must be logged immutably alongside the action and reward. This requires:

  • Deterministic feature engineering pipelines that can be exactly replayed.
  • Point-in-time correctness to avoid leaking future information into the training set.
  • Strict schema versioning to handle feature evolution. Without this, counterfactual evaluation becomes unreliable, and the safety guarantees of champion-challenger testing are compromised.
06

Privacy Compliance by Design

Feature vectors must respect data minimization principles. Avoid storing raw Personally Identifiable Information (PII) in the vector. Instead, use:

  • On-device aggregation to generate privacy-preserving signals.
  • Differential privacy noise injection for sensitive aggregates.
  • Federated learning sub-sampling to ensure raw context never leaves the user's device. A well-architected vector enables personalization without creating a honeypot of sensitive behavioral data, aligning with sovereign AI infrastructure requirements.
CONTEXTUAL FEATURE VECTORS

Frequently Asked Questions

Clear answers to common questions about the structured numerical representations that power contextual bandit decisions.

A contextual feature vector is a structured, fixed-length numerical array that encodes the current state of a user, session, or environment at the moment of a decision. It serves as the sole input to a contextual bandit algorithm. Each dimension represents a specific attribute—such as device_type=1 (mobile), hour_of_day=14, or past_purchase_count=5—transformed into a numerical format. The bandit model uses this vector to predict the expected reward for each available action, selecting the one that maximizes the cumulative outcome. The vector acts as the model's 'eyes,' translating raw business events into a mathematical space where similarity between states can be computed and leveraged for generalization.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.