Skip to content

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

@leiofrivia

Description

@leiofrivia

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions