Well, I found the error to my own script. The difference between one script and the other are the following parameters in the connection to the PGVectore store:
hnsw_kwargs={
"hnsw_m": 16,
"hnsw_ef_construction": 64,
"hnsw_ef_search": 40,
"hnsw_dist_method": "vector_cosine_ops",
},
This needs to be there so that the query to database is in the same format as it was being inserted (pretty obvious, isn't it?). When I was trying to add this, I was getting an error of the kind "PGVectorStore.from_params doesn't have any hnsw_kwargs parameters", so apparently I had two different set of functions with the same name. The problem was that I was using different PGVector packages in both scripts. When I was inserting I was using the legacy PGVector import and while querying I was using the core one which doesn't accept these parameters. That's the reason why I was getting the pydantic error.