(vector: Dict[str, float])
| 191 | |
| 192 | |
| 193 | def normalize_vector(vector: Dict[str, float]) -> Dict[str, float]: |
| 194 | norm = math.sqrt(sum(value * value for value in vector.values())) |
| 195 | if norm <= 0: |
| 196 | return {} |
| 197 | return {key: value / norm for key, value in vector.items() if value} |
| 198 | |
| 199 | |
| 200 | def cosine(left: Dict[str, float], right: Dict[str, float]) -> float: |