GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Inserting binary vectors using SQLalchemy · Issue #84 · pgvector/pgvector-python

Inserting binary vectors using SQLalchemy #84

New issue
Copy link
New issue
Copy link
Closed
Closed
Inserting binary vectors using SQLalchemy#84
Copy link

Description

@JungeAlexander
JungeAlexander
opened on Jul 18, 2024
Issue body actions

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 pgvector.sqlalchemy import BIT
from sqlalchemy.orm import DeclarativeBase, Mapped, mapped_column

class Entity(DeclarativeBase):
    [...]
    embedding: Mapped[np.array] = mapped_column(BIT(2048))

I am then trying to insert embedding as a list[int] of 0s and 1s only. However, this raises the following error:

RepositoryError: An exception occurred: (psycopg.errors.DatatypeMismatch) column "embedding" is of type bit but expression is of type smallint[]
                                                             ^
HINT:  You will need to rewrite or cast the expression.

A similar approach works fine using a list[float] when inserting into an embedding of type pgvector.sqlalchemy.Vector.

My question is: which Python type do I need to cast embedding to before insertion?

Thanks for the help in advance!

Activity

  1. JungeAlexander commented on Jul 18, 2024

    @JungeAlexander
    JungeAlexander
    on Jul 18, 2024
    Author
    More actions

    Addendum: I tried to insert list[float] and list[bool] values as binary vectors but this did not work either.

  2. ankane commented on Jul 18, 2024

    @ankane
    ankane
    on Jul 18, 2024
    Member
    More actions

    Hi @JungeAlexander, it currently only accepts a bit string.

    binary_embedding = [1, 0, 1]
    ''.join([str(v) for v in binary_embedding]) # '101'
    Reacted by Alexander Junge
  3. ankane
    closed this as completedon Jul 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.