3

I want to pickle/save my VectorStore index in LangChain. Below is my code:

import pickle
from langchain.document_loaders import PyPDFLoader
from langchain.indexes import VectorstoreIndexCreator

# Load the PDF file
pdf_path = "Los Angeles County, CA Code of Ordinances.pdf"
loader = PyPDFLoader(pdf_path)

# Create the index
index = VectorstoreIndexCreator().from_loaders([loader])

# Serialize and save the loader and index objects
with open("data.pickle", "wb") as f:
    pickle.dump((loader, index), f)

# To load the objects from the file:
with open("data.pickle", "rb") as f:
    loader, index = pickle.load(f)

but when I run it I get this error:

~/LangChain-exploredoc-explore$ python pickle_file.py
Using embedded DuckDB without persistence: data will be transient
Traceback (most recent call last):
  File "/home/runner/LangChain-exploredoc-explore/pickle_file.py", line 14, in <module>
    pickle.dump((index), f)
TypeError: cannot pickle 'duckdb.DuckDBPyConnection' object
L12345
  • 31
  • 2

0 Answers0