Closed QBH3 closed 3 months ago
Hi @QBH3, that error occurs if you try to create a sparse vector with a dictionary (regardless of whether dimensions are set on the column).
# error
Node(embedding={1:2}).save()
# no error
Node(embedding=SparseVector({1:2}, 30522)).save()
I want to suggest to rephrase the Exception as: raise ValueError('can not be initialized from a dict')
I believe the test in https://github.com/pgvector/pgvector-python/blob/633cbd724380d445f47e405b801964c4b60fba6a/pgvector/utils/sparsevec.py#L16 might not work as intended.
When trying to save in updated Model class in django it is called via https://github.com/pgvector/pgvector-python/blob/master/pgvector/utils/sparsevec.py#L125 and does not get a dimension as an argument.
django Model class:
How the table looks like with psql:
You can see that the table has the same dimension as the Model class.
The Exception that was trown: