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

Method cosine_similarity

skills/embedding/scripts/embed.py:548–556  ·  view source on GitHub ↗
(self, vector1: List[float], vector2: List[float])

Source from the content-addressed store, hash-verified

546 return [embedding if embedding is not None else [0.0] * self.dimensions for embedding in results]
547
548 def cosine_similarity(self, vector1: List[float], vector2: List[float]) -> float:
549 dot_product = sum(a * b for a, b in zip(vector1, vector2))
550 norm1 = sum(a * a for a in vector1) ** 0.5
551 norm2 = sum(b * b for b in vector2) ** 0.5
552
553 if norm1 == 0 or norm2 == 0:
554 return 0.0
555
556 return dot_product / (norm1 * norm2)
557
558
559_default_service: Optional[EmbeddingService] = None

Callers 3

cosine_similarityFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected