Title: Inserting binary vectors using SQLalchemy · Issue #84 · pgvector/pgvector-python · GitHub
Open Graph Title: Inserting binary vectors using SQLalchemy · Issue #84 · pgvector/pgvector-python
X Title: Inserting binary vectors using SQLalchemy · Issue #84 · pgvector/pgvector-python
Description: Hello, Thanks for the work on this, @ankane and team! It's amazing to see more vector types and distance metrics being added continuously :) I am trying to insert a binary vector using SQLalchemy and my code looks like this: from pgvecto...
Open Graph Description: Hello, Thanks for the work on this, @ankane and team! It's amazing to see more vector types and distance metrics being added continuously :) I am trying to insert a binary vector using SQLalchemy a...
X Description: Hello, Thanks for the work on this, @ankane and team! It's amazing to see more vector types and distance metrics being added continuously :) I am trying to insert a binary vector using SQLalche...
Opengraph URL: https://github.com/pgvector/pgvector-python/issues/84
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inserting binary vectors using SQLalchemy","articleBody":"Hello,\r\n\r\nThanks for the work on this, @ankane and team! It's amazing to see more vector types and distance metrics being added continuously :) I am trying to insert a binary vector using SQLalchemy and my code looks like this:\r\n\r\n```python\r\nfrom pgvector.sqlalchemy import BIT\r\nfrom sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column\r\n\r\nclass Entity(DeclarativeBase):\r\n [...]\r\n embedding: Mapped[np.array] = mapped_column(BIT(2048))\r\n```\r\n\r\nI am then trying to insert `embedding` as a `list[int]` of 0s and 1s only. However, this raises the following error:\r\n\r\n```\r\nRepositoryError: An exception occurred: (psycopg.errors.DatatypeMismatch) column \"embedding\" is of type bit but expression is of type smallint[]\r\n ^\r\nHINT: You will need to rewrite or cast the expression.\r\n```\r\n\r\nA similar approach works fine using a `list[float]` when inserting into an embedding of type `pgvector.sqlalchemy.Vector`.\r\n\r\n**My question is:** which Python type do I need to cast `embedding` to before insertion?\r\n\r\nThanks for the help in advance!","author":{"url":"https://github.com/JungeAlexander","@type":"Person","name":"JungeAlexander"},"datePublished":"2024-07-18T17:45:08.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/84/pgvector-python/issues/84"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8fb7ca1e-c6e2-eab4-7052-588895a11df6 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B1A6:2D5C0D:CC09BE:11CCC82:6970BD88 |
| html-safe-nonce | 7c3c8e0a4b9e5ea7d709cf13bb0599bf583b2de6a920246d1dec81bbe251f416 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMUE2OjJENUMwRDpDQzA5QkU6MTFDQ0M4Mjo2OTcwQkQ4OCIsInZpc2l0b3JfaWQiOiI2OTU0NDQ5Mzk3MjE1MTgyMjE2IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | fb594ab6b407c7d777a68050ce982ec69a273ec293a7def0f791e86327360b4e |
| hovercard-subject-tag | issue:2417007733 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/pgvector/pgvector-python/84/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5dc44f9a4f6b72f8ed5e455b726be1eb0ac0cb334b7b2497bf88203d3f801700/pgvector/pgvector-python/issues/84 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5dc44f9a4f6b72f8ed5e455b726be1eb0ac0cb334b7b2497bf88203d3f801700/pgvector/pgvector-python/issues/84 |
| og:image:alt | Hello, Thanks for the work on this, @ankane and team! It's amazing to see more vector types and distance metrics being added continuously :) I am trying to insert a binary vector using SQLalchemy a... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JungeAlexander |
| hostname | github.com |
| expected-hostname | github.com |
| None | 8e0be80373b724b033cdf8a7b1f78bf5fb6a5d7a2182a9a403aa30894606e390 |
| turbo-cache-control | no-preview |
| go-import | github.com/pgvector/pgvector-python git https://github.com/pgvector/pgvector-python.git |
| octolytics-dimension-user_id | 98363230 |
| octolytics-dimension-user_login | pgvector |
| octolytics-dimension-repository_id | 376300726 |
| octolytics-dimension-repository_nwo | pgvector/pgvector-python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 376300726 |
| octolytics-dimension-repository_network_root_nwo | pgvector/pgvector-python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 84d9d5bf3b01412ea10f7c2429cbfc735ccce9ce |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width