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

Method query

vicinity/vicinity.py:114–138  ·  view source on GitHub ↗

Find the nearest neighbors to some arbitrary vector. Use this to look up the nearest neighbors to a vector that is not in the vocabulary. :param vectors: The vectors to find the nearest neighbors to. :param k: The number of most similar items to retrieve. :

(
        self,
        vectors: npt.NDArray,
        k: int = 10,
    )

Source from the content-addressed store, hash-verified

112 return self.backend.arguments.metric
113
114 def query(
115 self,
116 vectors: npt.NDArray,
117 k: int = 10,
118 ) -> SimilarityResult[T]:
119 """
120 Find the nearest neighbors to some arbitrary vector.
121
122 Use this to look up the nearest neighbors to a vector that is not in the vocabulary.
123
124 :param vectors: The vectors to find the nearest neighbors to.
125 :param k: The number of most similar items to retrieve.
126 :return: For each item in the input, the num most similar items are returned in the form of
127 (NAME, DISTANCE) tuples.
128 """
129 vectors = np.asarray(vectors)
130 if np.ndim(vectors) == 1:
131 vectors = vectors[None, :]
132
133 out = []
134 for index, distances in self.backend.query(vectors, k):
135 distances.clip(min=0, out=distances)
136 out.append([(self.items[idx], dist) for idx, dist in zip(index, distances)])
137
138 return out
139
140 def query_threshold(
141 self,

Callers 5

evaluateMethod · 0.95
test_vicinity_queryFunction · 0.45
test_vicinity_insertFunction · 0.45
test_vicinity_deleteFunction · 0.45

Calls

no outgoing calls

Tested by 4

test_vicinity_queryFunction · 0.36
test_vicinity_insertFunction · 0.36
test_vicinity_deleteFunction · 0.36