🔎Basic Search
The simplest way is to call the search API directly, which performs all three steps of a full search in a single call:
Scoring – compute similarity scores in ciphertext
Decryption – decrypt the score vector locally on the client
Metadata retrieval – request the top-k metadata entries mapped to the scores
Note: Decryption is always performed on the client side with the secret key. This ensures true end-to-end encryption, meaning sensitive data is never exposed to the server.
import pyenvector as ev
import numpy as np
# Prepare normalized data
vecs = np.random.rand(100, 512)
vecs = vecs / np.linalg.norm(vecs, axis=1, keepdims=True)
# Initialize and insert
ev.init(address="localhost:50049", key_path="keys", key_id="example")
index = ev.create_index("example_index", dim=512)
metadata = [f"metadata_{i}" for i in range(100)]
index.insert(vecs, metadata)
# Perform search with a single query
search_index = ev.Index("example_index")
query = vecs[0]
result = search_index.search(query, top_k=2, output_fields=["metadata"])[0]
print(result)
# [{'id': 1, 'score': 0.9999, 'metadata': 'metadata_0'},
# {'id': 59, 'score': 0.7888, 'metadata': 'metadata_58'}]Multi-query Search
You can also search with multiple queries at once by providing a 2D numpy array. The results will be returned as a list, where each element corresponds to the result set of one query.
# Multi-query example
queries = vecs[:3] # Take 3 queries
results = search_index.search(queries, top_k=2, output_fields=["metadata"])
for i, r in enumerate(results):
print(f"Query {i} results:", r)
# Output:
# Query 0 results: [{'id': 1, 'score': 0.9999, 'metadata': 'metadata_0'}, ...]
# Query 1 results: [{'id': 42, 'score': 0.8123, 'metadata': 'metadata_41'}, ...]
# Query 2 results: [{'id': 59, 'score': 0.7888, 'metadata': 'metadata_58'}, ...]Last updated

