Update README.md

encrypt embeddings
This commit is contained in:
Sefik Ilkin Serengil 2025-04-18 12:47:32 +01:00 committed by GitHub
parent a288e030c6
commit 7bded0875b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -312,7 +312,7 @@ Conversely, if your task involves facial recognition on small to moderate-sized
**Encrypt Embeddings** - [`Demo with PHE`](https://youtu.be/8VCu39jFZ7k), [`Tutorial for PHE`](https://sefiks.com/2025/03/04/vector-similarity-search-with-partially-homomorphic-encryption-in-python/), [`Demo with FHE`](https://youtu.be/njjw0PEhH00), [`Tutorial for FHE`](https://sefiks.com/2021/12/01/homomorphic-facial-recognition-with-tenseal/)
Even though vector embeddings are not reversible to original images, they still contain sensitive information such as fingerprints, making their security critical. Encrypting embeddings is essential for higher security applications to prevent adversarial attacks that could manipulate or extract sensitive information. Traditional encryption methods like AES are very safe but limited in securely utilizing cloud computational power for distance calculations. Herein, [homomorphic encryption](https://youtu.be/3ejI0zNPMEQ), allowing calculations on encrypted data, offers a robust alternative.
Even though vector embeddings are not reversible to original images, they still contain sensitive information similar to fingerprints, making their security critical. Encrypting embeddings is essential for higher security applications to prevent adversarial attacks that could manipulate or extract sensitive information. Traditional encryption methods like AES are very safe but limited in securely utilizing cloud computational power for distance calculations. Herein, [homomorphic encryption](https://youtu.be/3ejI0zNPMEQ), allowing calculations on encrypted data without private key, offers a robust alternative for cloud.
```python
from lightphe import LightPHE
@ -337,8 +337,12 @@ calculated_similarity = cs.decrypt(encrypted_cosine_similarity)[0]
print("same person" if calculated_similarity >= 1 - threshold else "different persons")
```
<p align="center"><img src="https://raw.githubusercontent.com/serengil/deepface/refs/heads/master/icon/encrypt-embeddings.jpg" width="80%" height="80%"></p>
In this scheme, we leverage the computational power of the cloud to compute encrypted cosine similarity. However, the cloud has no knowledge of the actual calculations it performs. That's the **magic** of homomorphic encryption! Only the secret key holder on the on-premises side can decrypt the encrypted cosine similarity and determine whether the pair represents the same person or different individuals. Check out [`LightPHE`](https://github.com/serengil/LightPHE) library to find out more about partially homomorphic encryption.
As an alternative to partially homomorphic encryption, you can also choose to use fully homomorphic encryption. In this case, you'll compute the dot product between encrypted embeddings, rather than between encrypted and plain embeddings. To learn more about fully homomorphic encryption, check out the [`CipherFace`](https://github.com/serengil/cipherface) library. However, keep in mind that FHE is significantly more computationally expensive than PHE.
### Extended Applications
DeepFace can also be used for fun and insightful applications such as