MCPcopy Create free account
hub / github.com/cosdata/cosdata / calculate

Method calculate

src/models/types.rs:474–498  ·  view source on GitHub ↗
(
        &self,
        x: &VectorData,
        y: &VectorData,
        is_indexing: bool,
    )

Source from the content-addressed store, hash-verified

472impl DistanceFunction for DistanceMetric {
473 type Item = MetricResult;
474 fn calculate(
475 &self,
476 x: &VectorData,
477 y: &VectorData,
478 is_indexing: bool,
479 ) -> Result<Self::Item, DistanceError> {
480 match self {
481 Self::Cosine => {
482 let value = CosineSimilarity(0.0).calculate(x, y, is_indexing)?;
483 Ok(MetricResult::CosineSimilarity(value))
484 }
485 Self::Euclidean => {
486 let value = EuclideanDistance(0.0).calculate(x, y, is_indexing)?;
487 Ok(MetricResult::EuclideanDistance(value))
488 }
489 Self::Hamming => {
490 let value = HammingDistance(0.0).calculate(x, y, is_indexing)?;
491 Ok(MetricResult::HammingDistance(value))
492 }
493 Self::DotProduct => {
494 let value = DotProductDistance(0.0).calculate(x, y, is_indexing)?;
495 Ok(MetricResult::DotProductDistance(value))
496 }
497 }
498 }
499}
500
501#[derive(Debug, Clone, Serialize, Deserialize)]

Callers 4

ann_searchFunction · 0.45
index_embeddingFunction · 0.45
traverse_find_nearestFunction · 0.45
delete_embeddingFunction · 0.45

Calls 4

CosineSimilarityClass · 0.85
EuclideanDistanceClass · 0.85
HammingDistanceClass · 0.85
DotProductDistanceClass · 0.85

Tested by

no test coverage detected