MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / normalize_vector

Function normalize_vector

experiments/baselines/knowledge_entity/runner.py:255–259  ·  view source on GitHub ↗
(vector: Dict[str, float])

Source from the content-addressed store, hash-verified

253
254
255def normalize_vector(vector: Dict[str, float]) -> Dict[str, float]:
256 norm = math.sqrt(sum(value * value for value in vector.values()))
257 if norm <= 0:
258 return {}
259 return {key: value / norm for key, value in vector.items() if value}
260
261
262def add_weighted_vector(target: Dict[str, float], vector: Dict[str, float], weight: float) -> None:

Callers 3

vectorize_textFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected