🔓Decrypting Scores

In a full search pipeline (Scoring → Decryption → Metadata retrieval), this is the second step.

When you use the scoring API, the similarity scores are returned in encrypted form for security. To access the actual values, you must call decrypt_score on the client side. Decryption always happens locally, so there is no risk of exposing data to the server.

If you initialized your client with pyenvector.init using key_path and key_id, and set auto_key_setup=True, the secret key is already loaded into memory. In this case, you can directly call decrypt_score without specifying the key path again.

However, if you prefer not to load the secret key automatically and set auto_key_setup=False, you must explicitly provide the sec_key_path parameter when calling decrypt_score.

Example 1: With auto_key_setup=True

import pyenvector as ev

# Initialize with automatic key setup
ev.init(
    address="localhost:50049",
    key_path="keys/example",
    key_id="example",
    auto_key_setup=True
)

index = ev.Index("example_index")

# Perform scoring
encrypted_scores = index.scoring(query)

# Decrypt directly, no need to provide sec_key_path
plaintext_scores = index.decrypt_score(encrypted_scores)

print(plaintext_scores[:5])

Example 2: With auto_key_setup=False

import pyenvector as ev
from pyenvector import Cipher

# Initialize without loading keys automatically
ev.init(
    address="localhost:50049",
    key_path="keys/example",
    auto_key_setup=False
)

index = ev.Index("example_index")

# Perform scoring
encrypted_scores = index.scoring(query)

# Must explicitly provide the secret key path
plaintext_scores = ev.decrypt_score(
    encrypted_scores,
    sec_key_path="keys/example/SecKey.json"
)

print(plaintext_scores[:5])

Last updated