MCPcopy Create free account
hub / github.com/MinishLab/vicinity / from_vectors

Method from_vectors

vicinity/backends/basic.py:118–130  ·  view source on GitHub ↗

Create a new instance from vectors.

(cls, vectors: npt.NDArray, metric: str | Metric = "cosine", **kwargs: Any)

Source from the content-addressed store, hash-verified

116
117 @classmethod
118 def from_vectors(cls, vectors: npt.NDArray, metric: str | Metric = "cosine", **kwargs: Any) -> BasicBackend:
119 """Create a new instance from vectors."""
120 metric_enum = Metric.from_string(metric)
121 if metric_enum not in cls.supported_metrics:
122 raise ValueError(f"Metric '{metric_enum.value}' is not supported by BasicBackend.")
123
124 arguments = BasicArgs(metric=metric_enum)
125 if metric_enum == Metric.COSINE:
126 return CosineBasicBackend(vectors, arguments)
127 elif metric_enum == Metric.EUCLIDEAN:
128 return EuclideanBasicBackend(vectors, arguments)
129 else:
130 raise ValueError(f"Unsupported metric: {metric}")
131
132 @classmethod
133 def load(cls, path: Path) -> BasicBackend:

Callers

nothing calls this directly

Calls 4

BasicArgsClass · 0.85
CosineBasicBackendClass · 0.85
from_stringMethod · 0.80

Tested by

no test coverage detected