Skip to content

feat: add create_extension flag to init_vectorstore_table#293

Open
Michele Catalano (ironpinguin) wants to merge 1 commit intolangchain-ai:mainfrom
mayflower:feat/create-extension-flag
Open

feat: add create_extension flag to init_vectorstore_table#293
Michele Catalano (ironpinguin) wants to merge 1 commit intolangchain-ai:mainfrom
mayflower:feat/create-extension-flag

Conversation

@ironpinguin
Copy link
Copy Markdown

Summary

Add a create_extension parameter (default True) to _ainit_vectorstore_table,
ainit_vectorstore_table, and init_vectorstore_table. When set to False, the
CREATE EXTENSION IF NOT EXISTS vector statement is skipped.

Motivation

Some deployments use managed databases (e.g. AlloyDB, Cloud SQL) where the pgvector
extension is pre-installed, or the database user lacks CREATE EXTENSION privileges.
Forcing the extension creation on every table init causes unnecessary permission errors.

Changes

  • langchain_postgres/v2/engine.py: added create_extension: bool = True parameter
    to the three init_vectorstore_table variants; wrapped the CREATE EXTENSION call
    in a conditional block.
  • tests/unit_tests/v2/test_engine.py: added test_init_table_no_create_extension
    for both async and sync paths.

Usage Example

# Skip extension creation (extension already installed or insufficient privileges)
await engine.ainit_vectorstore_table(
    table_name="my_table",
    vector_size=768,
    create_extension=False,
)

Breaking Changes

None. The new parameter defaults to True, preserving existing behavior.

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.

1 participant