Create a new instance from vectors.
(cls, vectors: npt.NDArray, metric: str | Metric = "cosine", **kwargs: Any)
| 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: |
nothing calls this directly
no test coverage detected