nicknochnack / Llama2RAG

A working example of RAG using LLama 2 70b and Llama Index
352 stars 110 forks source link

For the documents, need to convert PosixPath in metadata to string #7

Open leiofrivia opened 8 months ago

leiofrivia commented 8 months ago

I run into Object of type PosixPath is not JSON serializable when I run index = VectorStoreIndex.from_documents(documents), so I had to convert PosixPath in metadata to string first. Below is the solution.

documents = loader.load(file_path=Path('./data/annualreport.pdf'), metadata=True)

# Convert PosixPath in metadata to string
for document in documents:
    if 'file_path' in document.metadata and isinstance(document.metadata['file_path'], Path):
        document.metadata['file_path'] = str(document.metadata['file_path'])

# Create an index with the converted documents
index = VectorStoreIndex.from_documents(documents)