hoops_ai.ml.context_layer.NearestNeighborRule
- class hoops_ai.ml.context_layer.NearestNeighborRule(threshold=0.95)
Bases:
AggregationRuleUse the top-similarity hit’s value when shape similarity is high enough.
Useful for keys whose value is essentially intrinsic to the geometry — number of internal features, hole count, surface area, bounding-box dimensions, … — and therefore better borrowed from the closest shape match than averaged out of a neighborhood. When the top-ranked hit’s score is at or above
threshold, this rule returns that hit’s value with confidence equal to the top score. Otherwise it abstains so the predictor returns anSTATUS_INSUFFICIENTsentinel.Pairs naturally with
ContextPredictor’s cross-key injection: install this rule for an intrinsic geometric key (InternalFeatures) viaper_key_rules, and the resultingSTATUS_READYprediction is forwarded into thequery_contextof every downstream numeric key (Cost,Weight, …) so theirRelevanceWeightercan re-rank neighbors with a matching feature count.- Parameters:
threshold (float) – Minimum top-hit similarity required to trust the borrowed value, in [0.0, 1.0]. Default
0.95.
Example
- from hoops_ai.ml.context_layer import (
ContextPredictor, NearestNeighborRule, NumericWeightedRule,
)
- predictor = ContextPredictor(
provider, per_key_rules={
“InternalFeatures”: NearestNeighborRule(threshold=0.95),
},
)
- predict(values, scores, key)
Predict a context value from neighbor evidence.
- Parameters:
- Returns:
ContextPrediction or None if insufficient evidence.
- Return type:
ContextPrediction | None