🧱Inserting CipherBlock
You can also insert pre-encrypted vectors using the Cipher class and its encrypt_multiple() method.
Make sure to normalize vectors before encryption when using inner product metric.
Example
import numpy as np
import pyenvector as ev
from pyenvector import Cipher
cipher = Cipher(dim=512)
vecs = np.random.rand(100, 512)
# Normalize before encryption
vecs = vecs / np.linalg.norm(vecs, axis=1, keepdims=True)
encrypted_vecs = cipher.encrypt_multiple(
vecs,
"item",
enc_key_path="keys/example/EncKey.json"
)
ev.init(address="localhost:50050", key_path="keys", key_id="example")
index = ev.create_index("example_index", dim=512)
index.insert(encrypted_vecs)
# Output:
# Index(
# IndexConfig(
# index_name="example_index",
# dim=512,
# key_path='keys',
# key_id='example',
# ),
# num_entities=100,
# cipher=<pyenvector.crypto.cipher.Cipher object at 0x7f1776199d60>
#)Last updated

