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

[peewee] using Model.get_or_create() doesn't work with pgvector #31

Closed
ricardofunke opened this issue Sep 15, 2023 · 2 comments
Closed

Comments

@ricardofunke
Copy link

Hello!

I'm trying to use the peewee method .get_or_create() in place of .create() but I'm getting the following error:

{...}
  File "/myprj/venv/lib/python3.11/site-packages/pgvector/peewee/__init__.py", line 16, in db_value
    return to_db(value)
           ^^^^^^^^^^^^
  File "/myprj/venv/lib/python3.11/site-packages/pgvector/utils/__init__.py", line 37, in to_db
    return '[' + ','.join([str(float(v)) for v in value]) + ']'
                          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'float' object is not iterable

Can you help to find out whether is this a bug or something I'm doing wrong?

Thanks!

@ankane
Copy link
Member

ankane commented Sep 15, 2023

Hi @ricardofunke, it should work if you use a NumPy array instead of a list:

Item.get_or_create(embedding=np.array([4, 5, 6]))

I don't see a way to make it work with lists at the moment.

@ankane
Copy link
Member

ankane commented Sep 25, 2023

It looks like AsIs(value) and Item.embedding.to_value(value) work as well, but think that might be the best we can do for now.

@ankane ankane closed this as completed Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants