mnemosine.vec.VectorStore.knn
Kind: method
Signature
python
VectorStore.knn(self, vector, top_k: int=10, metric: str='cosine')Documentation
Return the top_k nearest embeddings to vector.
Native path: vec0 k-NN query returning (node_id, distance). Fallback path: brute-force scan with _distance. Result items are ordered nearest-first.
Args:
vector (sequence of float): The query embedding.top_k (int): Number of results. Defaults to 10.metric (str):"cosine"(default),"l2"or"dot".
Returns:
list of dict: Each item hasnode_id(str) anddistance- (float). Empty when no embeddings are stored.
Raises:
VectorError: Iftop_k < 1or the vector dimension conflicts.
Example:
python
>>> db.vec.knn([1.0, 0.0, 0.0], top_k=2)
[{'node_id': '01G...', 'distance': 0.0}, ...]