langchain-ai / langchain-postgres

LangChain abstractions backed by Postgres Backend
MIT License
133 stars 48 forks source link

Fix metadata deserialization in async mode for PGVector #125

Open shamspias opened 1 month ago

shamspias commented 1 month ago

Problem

When using asynchronous methods with PGVector (async_mode=True), the metadata field retrieved from the database may be of type Fragment (from asyncpg) or other non-dict types. This causes a ValidationError when the Document class expects metadata to be a dictionary.

Solution

This pull request modifies the _results_to_docs_and_scores method to ensure that metadata is correctly converted into a dictionary before creating Document instances. The method now handles different possible types of metadata and attempts to deserialize it into a dict.

Changes

Testing

Related Issues

jaimeescano commented 1 month ago

Facing this very same issue. Wondering when this commit could be merged. Big credits to @shamspias for providing the fix.

Regards

shamspias commented 1 month ago

@eyurtsev, please let me know if there is anything else I need to do. If not, please merge it.

simadimonyan commented 1 week ago

Did you fix the issue? I have related: https://github.com/langchain-ai/langchain/issues/28029

shamspias commented 5 days ago

Did you fix the issue? I have related: langchain-ai/langchain#28029

yes I did fixed the issue you can use the branch if you like to