|
|
@@ -369,6 +369,7 @@ def _items_to_materials(
|
|
|
*,
|
|
|
apply_cover_blacklist: bool = True,
|
|
|
min_cost: Optional[float] = None,
|
|
|
+ apply_cost_filter: bool = True,
|
|
|
) -> tuple:
|
|
|
"""把召回 items 过滤 + 转 Material。
|
|
|
|
|
|
@@ -376,7 +377,9 @@ def _items_to_materials(
|
|
|
- modality=MATERIAL(防御性)
|
|
|
- cover URL 不在黑名单
|
|
|
- score >= sim_threshold
|
|
|
- - min_cost is not None 时:历史成本(cost, 元) >= min_cost(严格,无成本数据也排除)
|
|
|
+ - apply_cost_filter 且 min_cost is not None 时:历史成本(cost, 元) >= min_cost
|
|
|
+ (严格,无成本数据也排除)。外部合作素材召回关闭 apply_cost_filter,
|
|
|
+ 仅以访问 UV 门槛把关。
|
|
|
|
|
|
CTR / impressions 只作为审批展示和兜底排序参考,不再作为硬筛。
|
|
|
返回 (materials, stats)。
|
|
|
@@ -409,7 +412,7 @@ def _items_to_materials(
|
|
|
q = md.get("quality") or {}
|
|
|
raw_cost = q.get("cost")
|
|
|
cost = _as_float(raw_cost) if raw_cost is not None else None
|
|
|
- if min_cost is not None and (cost is None or cost < min_cost):
|
|
|
+ if apply_cost_filter and min_cost is not None and (cost is None or cost < min_cost):
|
|
|
stats["low_cost"] += 1
|
|
|
continue
|
|
|
out.append(Material(
|
|
|
@@ -586,6 +589,7 @@ def recall_materials_for_video(
|
|
|
element_features: Optional[Iterable] = None,
|
|
|
apply_cover_blacklist: bool = True,
|
|
|
min_cost: Optional[float] = None,
|
|
|
+ apply_cost_filter: bool = True,
|
|
|
) -> List[Material]:
|
|
|
"""素材召回:用 ODPS 多维特征并行召回并合并排序。
|
|
|
|
|
|
@@ -595,6 +599,7 @@ def recall_materials_for_video(
|
|
|
3. 汇总、material_id 去重、score>=阈值、按 cost 倒序。
|
|
|
|
|
|
硬筛:相似度阈值 + 历史成本(cost>=min_cost,min_cost 默认取 config.RECALL_MIN_COST_YUAN)。
|
|
|
+ 外部合作素材召回传 apply_cost_filter=False 关闭成本门槛,仅以访问 UV 门槛把关。
|
|
|
曝光/CTR 进入审批表但不拦截。
|
|
|
"""
|
|
|
from config import (
|
|
|
@@ -608,6 +613,7 @@ def recall_materials_for_video(
|
|
|
|
|
|
if min_cost is None:
|
|
|
min_cost = RECALL_MIN_COST_YUAN
|
|
|
+ cost_marker = "off" if not apply_cost_filter else f"{min_cost:.0f}"
|
|
|
|
|
|
if element_features is None:
|
|
|
element_features = landing.raw.get("element_features") or []
|
|
|
@@ -661,13 +667,14 @@ def recall_materials_for_video(
|
|
|
RECALL_SIM_THRESHOLD,
|
|
|
apply_cover_blacklist=apply_cover_blacklist,
|
|
|
min_cost=min_cost,
|
|
|
+ apply_cost_filter=apply_cost_filter,
|
|
|
)
|
|
|
query_materials.append((query, mats))
|
|
|
logger.info(
|
|
|
- "[material_recall] 策略=%s q=%r configCode=%s 返回 %d 条,⊘ 黑名单 %d,⊘ score<%.2f %d,⊘ cost<%.0f %d → 保留 %d",
|
|
|
+ "[material_recall] 策略=%s q=%r configCode=%s 返回 %d 条,⊘ 黑名单 %d,⊘ score<%.2f %d,⊘ cost<%s %d → 保留 %d",
|
|
|
query.strategy_name, query.query_text[:30], query.config_code,
|
|
|
len(items), stats["blacklist"], RECALL_SIM_THRESHOLD,
|
|
|
- stats["low_score"], min_cost, stats["low_cost"],
|
|
|
+ stats["low_score"], cost_marker, stats["low_cost"],
|
|
|
len(mats),
|
|
|
)
|
|
|
|
|
|
@@ -701,6 +708,7 @@ def recall_materials_for_video(
|
|
|
RECALL_SIM_THRESHOLD,
|
|
|
apply_cover_blacklist=apply_cover_blacklist,
|
|
|
min_cost=min_cost,
|
|
|
+ apply_cost_filter=apply_cost_filter,
|
|
|
)
|
|
|
fquery = RecallQuery(
|
|
|
query_text=query.query_text,
|
|
|
@@ -713,10 +721,10 @@ def recall_materials_for_video(
|
|
|
)
|
|
|
fmats = _merge_materials_by_policy([(fquery, fmats)])
|
|
|
logger.info(
|
|
|
- "[material_recall] fallback=%s 返回 %d 条,⊘ 黑名单 %d,⊘ score<%.2f %d,⊘ cost<%.0f %d → 保留 %d(cost desc)",
|
|
|
+ "[material_recall] fallback=%s 返回 %d 条,⊘ 黑名单 %d,⊘ score<%.2f %d,⊘ cost<%s %d → 保留 %d(cost desc)",
|
|
|
fallback_cc, len(fallback_items), fstats["blacklist"],
|
|
|
RECALL_SIM_THRESHOLD, fstats["low_score"],
|
|
|
- min_cost, fstats["low_cost"],
|
|
|
+ cost_marker, fstats["low_cost"],
|
|
|
len(fmats),
|
|
|
)
|
|
|
if fmats:
|