Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
leiofrivia opened this issue Dec 16, 2023 · 0 comments
Open

Comments

@leiofrivia
Copy link

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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant