(profile: Dict[str, Any])
| 956 | |
| 957 | |
| 958 | def _trim_bootstrap_profile(profile: Dict[str, Any]) -> None: |
| 959 | core_items = sorted( |
| 960 | (profile.get("core_directions") or {}).items(), |
| 961 | key=lambda item: (-float(item[1]), str(item[0])), |
| 962 | ) |
| 963 | kept_core = dict(core_items[:BOOTSTRAP_MAX_CORE_DIRECTIONS]) |
| 964 | kept_keys = set(kept_core) |
| 965 | |
| 966 | profile["core_directions"] = kept_core |
| 967 | profile["topic_weights"] = { |
| 968 | key: float(value) |
| 969 | for key, value in sorted( |
| 970 | (profile.get("topic_weights") or {}).items(), |
| 971 | key=lambda item: (-float(item[1]), str(item[0])), |
| 972 | ) |
| 973 | if key in kept_keys or float(value or 0.0) >= 0.35 |
| 974 | } |
| 975 | profile["interest_vector"] = generate_interest_vector(kept_core) if kept_core else [] |
| 976 | |
| 977 | |
| 978 | def _build_bootstrap_fragment_from_structured_sources( |
no test coverage detected