我想在 LangChain 中选择/保存我的 VectorStore 索引。下面是我的代码:
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)
但是当我运行它时出现这个错误:
~/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