hoops_ai.ml.context_layer.AggregationRule

class hoops_ai.ml.context_layer.AggregationRule

Bases: ABC

Base class for context-aggregation rules.

A rule turns a list of (value, score) pairs harvested from a single context key into one ContextPrediction. Subclasses must implement predict(); predict_with_context() is optional and defaults to ignoring the extra arguments and delegating to predict.

Override predict_with_context() when the rule wants to consume the query’s own attributes (query_context) or per-hit metadata (hits). NumericWeightedRule does this to run an internal RelevanceWeighter and/or an MLP without forcing the predictor to know about either.

Override bind() to receive a one-shot reference to the ContextProvider at predictor construction. The default is a no-op so most rules can ignore it.

abstract predict(values, scores, key)

Predict a context value from neighbor evidence.

Parameters:
  • values (list[Any]) – The context values collected from hits for this key, ordered by relevance (best match first).

  • scores (list[float]) – Similarity scores corresponding 1-to-1 with values (higher = more similar).

  • key (str) – The context key being inferred.

Returns:

ContextPrediction or None if insufficient evidence.

Return type:

ContextPrediction | None

predict_with_context(values, scores, key, query_context=None, *, hits=None)

Predict with optional query context and per-hit metadata.

Default implementation ignores query_context and hits and delegates to predict(). Override in subclasses that benefit from one or both.

Parameters:
Return type:

ContextPrediction | None