langchain icon indicating copy to clipboard operation
langchain copied to clipboard

cannot pickle '_thread.RLock' object

Open sambantham-p opened this issue 2 years ago • 3 comments

Traceback (most recent call last): File "D:\news agent\venv\Lib\site-packages\streamlit\runtime\scriptrunner\script_runner.py", line 534, in _run_script exec(code, module.dict) File "D:\news agent\main.py", line 31, in final = qa.qaretriever(question,urls) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\news agent\qaretriever.py", line 35, in qaretriever pickle.dump(vector_index, f) TypeError: cannot pickle '_thread.RLock' object

sambantham-p avatar Nov 14 '23 07:11 sambantham-p

did you solve this ?

cabdelahad avatar Dec 18 '23 10:12 cabdelahad

Hi, Were you able to solve this issue?

HariPrasanth avatar May 23 '24 11:05 HariPrasanth

The answer is : We will have to use vectorstore methods only to dump into a file and retrieve it instead of using pickle

Just replaced the code

with open(file_path, "wb") as f:
    pickle.dump(vectorstore_openai, f)

With this line vectorstore_openai.save_local("vectorstore")

And

replace this code vectorstore = pickle.load(f) with vectorstore = FAISS.load_local("vectorstore", OpenAIEmbeddings(), allow_dangerous_deserialization=True)

HariPrasanth avatar May 24 '24 06:05 HariPrasanth