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

Class CosineBasicBackend

vicinity/backends/basic.py:212–228  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

210
211
212class CosineBasicBackend(BasicBackend):
213 def __init__(self, vectors: npt.NDArray, arguments: BasicArgs) -> None:
214 """Initialize the cosine basic backend."""
215 super().__init__(vectors=vectors, arguments=arguments)
216 self._vectors = normalize_or_copy(self._vectors)
217
218 def _dist(self, x: npt.NDArray) -> npt.NDArray:
219 """Compute cosine distance."""
220 x_norm = normalize(x)
221 sim = x_norm.dot(self._vectors.T)
222 return 1 - sim
223
224 def insert(self, vectors: npt.NDArray) -> None:
225 """Insert vectors into the vector space."""
226 # Normalize the new vectors
227 _norm_vectors = normalize_or_copy(vectors)
228 self._vectors = np.vstack([self._vectors, _norm_vectors])
229
230
231class EuclideanBasicBackend(BasicBackend):

Callers 2

from_vectorsMethod · 0.85
loadMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…