-
Notifications
You must be signed in to change notification settings - Fork 310
Open
Description
DotProduct is currently manually calculating DotProduct.
mcp/eng/tools/ToolDescriptionEvaluator/VectorDb/VectorDB.cs
Lines 33 to 50 in 842d6be
| public class DotProduct : IDistanceMetric | |
| { | |
| public bool BiggerIsCloser => true; | |
| public float Distance(float[] a, float[] b) | |
| { | |
| if (a.Length != b.Length) | |
| throw new ArgumentException("Vector lengths must match"); | |
| float dotProduct = 0.0f; | |
| for (int i = 0; i < a.Length; i++) | |
| { | |
| dotProduct += a[i] * b[i]; | |
| } | |
| return dotProduct; | |
| } | |
| } |
TensorPrimitives provides a method for calculating Dot product.
TensorPrimitives is already used for CosineSimilarity, so it would be good to maintain consistency.
mcp/eng/tools/ToolDescriptionEvaluator/VectorDb/VectorDB.cs
Lines 20 to 31 in 842d6be
| public class CosineSimilarity : IDistanceMetric | |
| { | |
| public bool BiggerIsCloser => true; // Cosine similarity: 1 = most similar, -1 = least similar | |
| public float Distance(float[] a, float[] b) | |
| { | |
| if (a.Length != b.Length) | |
| throw new ArgumentException("Vector lengths must match"); | |
| return TensorPrimitives.CosineSimilarity(a.AsSpan(), b.AsSpan()); | |
| } | |
| } |
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Untriaged