Skip to content

Fix: Table 'langchain_pg_collection' is already defined for this MetaData instance#209

Open
Rushi Chaudhari (0xrushi) wants to merge 5 commits intolangchain-ai:mainfrom
0xrushi:main
Open

Fix: Table 'langchain_pg_collection' is already defined for this MetaData instance#209
Rushi Chaudhari (0xrushi) wants to merge 5 commits intolangchain-ai:mainfrom
0xrushi:main

Conversation

@0xrushi
Copy link
Copy Markdown

@0xrushi Rushi Chaudhari (0xrushi) commented May 9, 2025

Possible solution for #165

Added thread locks to prevent multi table creation, optionally we can also pass extend_existing = True if required.

vector_store = PGVector(
    embeddings=OpenAIEmbeddings(),
    collection_name="test_collection",
    connection=connection_string,
    extend_existing=True,
)

Comment thread langchain_postgres/vectorstores.py Outdated
Comment thread langchain_postgres/vectorstores.py Outdated
self._engine: Optional[Engine] = None
self._async_engine: Optional[AsyncEngine] = None
self._async_init = False
self.extend_existing = extend_existing
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a private variable self._extend_existing

Rushi Chaudhari (0xrushi) and others added 2 commits May 9, 2025 20:32
Co-authored-by: Martín Gotelli Ferenaz <martingotelliferenaz@gmail.com>
@t-ionut
Copy link
Copy Markdown

Martín Gotelli Ferenaz (@MartinGotelli) I've just encountered this exact issue in my work and I'm happy to see Rushi Chaudhari (@0xrushi) has a fix in this PR.

Any chance of getting this merged soon?

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.

3 participants