The de-serialization relies loading a pickle file [closed]
Asked Answered
C

1

8

I got this error loading embeddings with FAISS:

The de-serialization relies loading a pickle file. Pickle files can be modified to deliver a malicious payload that results in execution of arbitrary code on your machine.You will need to set `allow_dangerous_deserialization` to `True` to enable deserialization. If you do this, make sure that you trust the source of the data. For example, if you are loading a file that you created, and no that no one else has modified the file, then this is safe to do. Do not set this to `True` if you are loading a file from an untrusted source (e.g., some random site on the internet.).

Example code:

from langchain.vectorstores import FAISS

And the line that triggers the error:

vectordb = FAISS.load_local(
    cfg.DB_FAISS_PATH,
    embeddings
)
Cheops answered 7/3, 2024 at 9:35 Comment(0)
B
23

Use following import

from langchain_community.vectorstores import FAISS

and

new_db = FAISS.load_local("faiss_index", embeddings,allow_dangerous_deserialization=True)

should fix this. This is a feature to prevent any dangerous executions by default from a .pkl file

Brianabriand answered 7/3, 2024 at 15:36 Comment(2)
Nice one! Just getting into LLMs, you saved me ton of work with this solution. Keep it up!Dagenham
Is there a way to load a local FAISS index without relying on .pkl files?Valera

© 2022 - 2025 — McMap. All rights reserved.