Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TypeError: cannot pickle '_thread.RLock' object by using dill #12

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

M117n
Copy link

@M117n M117n commented Aug 26, 2024

Description:
Problem Overview
When attempting to serialize the FAISS vectorstore object using pickle, a TypeError occurs:

TypeError: cannot pickle '_thread.RLock' object

This error arises because pickle cannot serialize objects that contain threading locks, which are present within the FAISS object. This issue prevents saving and loading the vectorstore efficiently, impacting the performance and usability of the application.

Solution
To resolve this issue, I replaced the usage of Python's built-in pickle module with the dill library, which is capable of serializing a wider range of Python objects, including those with threading locks.

Changes Made:

Imported dill and aliased it as pickle to minimize code changes:

import dill as pickle

Updated all instances where pickle was used for serialization and deserialization:

Serialization

with open(pkl_path, "wb") as f:
pickle.dump(vectorstore, f)

Deserialization

with open(pkl_path, 'rb') as file:
self.vectorstore = pickle.load(file)

Impact:
These changes allow for proper serialization and deserialization of the FAISS vectorstore, preventing the TypeError and improving the stability of the LLM reasoning process when handling large datasets or complex documents.

Please review and let me know if any further adjustments are needed. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant