Add other input types for SQLAlchemy BIT model by jackrua · Pull Request #137 · pgvector/pgvector-python · GitHub
Skip to content

Add other input types for SQLAlchemy BIT model#137

Open
jackrua wants to merge 10 commits into
pgvector:masterfrom
jackrua:feature/other_inputs_for_sqlalchemy_bit
Open

Add other input types for SQLAlchemy BIT model#137
jackrua wants to merge 10 commits into
pgvector:masterfrom
jackrua:feature/other_inputs_for_sqlalchemy_bit

Conversation

@jackrua

@jackrua jackrua commented Jul 17, 2025

Copy link
Copy Markdown
Contributor

Hi,

First of all, thank you for the great library @ankane!

I'm opening this PR to address some issues that have been raised by users (#84, #110 and #112), that is to input types other than string in the BIT SQLAlchemy model (also when using the asyncpg dialect). In brief with this PR, given:

class Item(Base):
    id = mapped_column(Integer, primary_key=True)
    binary_embedding = mapped_column(BIT(3))

You can add it to your database using whatever input you like (and this will be transformed following the logic already present in the init of the Bit class):

with Session(engine) as session: 
   session.add(Item(id = 1, 
   binary_embedding = [True, False, True])) # or [1, 0, 1], or np.array([1, 0, 1]) 

@jackrua jackrua changed the title Add other input types for SQLAlchemy models Add other input types for SQLAlchemy BIT model Jul 17, 2025
ankane added a commit that referenced this pull request Sep 2, 2025
Co-authored-by: Giacomo rua <giacomo.rua@outlook.com>
@ankane

ankane commented Sep 2, 2025

Copy link
Copy Markdown
Member

@jackrua

jackrua commented Sep 22, 2025

Copy link
Copy Markdown
Contributor Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants