(vector: List[float])
| 394 | |
| 395 | |
| 396 | def _normalize_vector(vector: List[float]) -> List[float]: |
| 397 | if not vector: |
| 398 | return [] |
| 399 | array = np.array(vector, dtype=float) |
| 400 | norm = np.linalg.norm(array) |
| 401 | if norm <= 0: |
| 402 | return [0.0] * len(array) |
| 403 | return (array / norm).tolist() |
| 404 | |
| 405 | |
| 406 | def cosine_similarity(vec1: List[float], vec2: List[float]) -> float: |
no outgoing calls
no test coverage detected