Skip to content

feat: allow Client and create_client with prebuilt SQLAlchemy Engine (#111) - #121

Open
givemehat wants to merge 1 commit into
supabase:mainfrom
givemehat:feat/client-custom-engine
Open

givemehat wants to merge 1 commit into
supabase:mainfrom
givemehat:feat/client-custom-engine

Conversation

@givemehat

Copy link
Copy Markdown

Description

Closes #111.

Currently, vecs.Client and vecs.create_client only accept a raw PostgreSQL connection string:

def create_client(connection_string: str) -> Client: ...

In cloud-deployed environments (e.g. Google Cloud SQL with google-cloud-sql-connector, AWS RDS with IAM authentication, or applications using pre-configured SQLAlchemy connection pools / custom creators), the database connection cannot be initialized via a static connection string alone.

This PR adds support for initializing Client and create_client with an existing SQLAlchemy Engine:

# Example with custom creator / cloud connector
engine = create_engine("postgresql+pg8000://", creator=getconn, future=True)
client = vecs.create_client(engine=engine)

Key Changes

  • Backwards-Compatible Client.__init__: Accepts connection_string: Optional[str] = None or keyword-only engine: Optional[Engine] = None. Enforces that exactly one of connection_string or engine is provided.
  • create_client: Updated signature to create_client(connection_string: Optional[str] = None, *, engine: Optional[Engine] = None) -> Client.
  • Typing: Uses TYPE_CHECKING for Engine to keep imports clean.
  • Comprehensive Unit Tests:
    • test_client_with_engine: Tests collection creation and listing with prebuilt engine.
    • test_create_client_with_engine: Tests vecs.create_client(engine=engine).
    • test_client_init_validation: Asserts ValueError is raised when neither or both parameters are passed.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow vecs Client creation with prebuild SQLAlchemy Engine or with creator method

1 participant