Skip to content

feat: add create_extension flag to init_vectorstore_table#293

Open
Michele Catalano (ironpinguin) wants to merge 2 commits into
langchain-ai:mainfrom
mayflower:feat/create-extension-flag
Open

feat: add create_extension flag to init_vectorstore_table#293
Michele Catalano (ironpinguin) wants to merge 2 commits into
langchain-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.

@dishaprakash

Copy link
Copy Markdown
Collaborator

Michele Catalano (@ironpinguin) Thank you for opening this PR. Please add documentation related to this change in https://github.com/langchain-ai/langchain-postgres/blob/main/examples/pg_vectorstore_how_to.ipynb

@ironpinguin

Copy link
Copy Markdown
Author

Michele Catalano (Michele Catalano (@ironpinguin)) Thank you for opening this PR. Please add documentation related to this change in https://github.com/langchain-ai/langchain-postgres/blob/main/examples/pg_vectorstore_how_to.ipynb

dishaprakash I did oversee the documentation notebook. Now there is also a tip for the new option.

Document the new create_extension flag for init_vectorstore_table,
explaining when to set it to False (extension already installed or
user lacks permission to create extensions on managed databases).
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.

2 participants