Error while upgrading psycopg2 to psycopg with "from langchain_postgres import PGVector" and "langchain_postgres.vectorstores import PGVector" #11

Closed
opened 2026-02-16 05:16:03 -05:00 by yindo · 4 comments
Owner

Originally created by @rkrkrediffmail on GitHub (May 2, 2024).

Checked other resources

  • I added a very descriptive title to this issue.
  • I searched the LangChain documentation with the integrated search.
  • I used the GitHub search to find a similar question and didn't find it.
  • I am sure that this is a bug in LangChain rather than my code.
  • The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).

Example Code

#!/usr/bin/python3
import os
import psycopg
from psycopg import sql
from langchain_postgres import PGVector
from langchain_postgres.vectorstores import PGVector
#from langchain.vectorstores.pgvector import PGVector
#from langchain.vectorstores.pgvector import DistanceStrategy
from langchain_openai import AzureOpenAIEmbeddings
from langchain_openai import AzureChatOpenAI

Error Message and Stack Trace (if applicable)

Exception ignored in: <function PGVector.del at 0x7fa9436f2a70>
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/langchain_postgres/vectorstores.py", line 326, in del
if isinstance(self._engine, sqlalchemy.engine.Connection):
AttributeError: 'PGVector' object has no attribute '_engine'
this is the error: PGVector.init() got an unexpected keyword argument 'connection_string'

Description

I have a RAG bot on AzureOpenAI. It has been working fine. However, after i upgraded my python=3.10 and openai>1.0, i upgraded the langchain modules as well. i had replaced the pgvector to "from langchain_postgres import PGVector"
With the above upgrades and i tried creating new embeddings with "text-embedding-3-large" i get the following error.

Exception ignored in: <function PGVector.del at 0x7fa9436f2a70>
Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/langchain_postgres/vectorstores.py", line 326, in del
if isinstance(self._engine, sqlalchemy.engine.Connection):
AttributeError: 'PGVector' object has no attribute '_engine'
this is the error: PGVector.init() got an unexpected keyword argument 'connection_string'

i entirely removed the langchain_pg_collection and langchain_pg_embedding as the vector size was different (1536 to 3072)

System Info

langchain==0.1.16
langchain-community==0.0.34
langchain-core==0.1.46
langchain-mistralai==0.0.4
langchain-openai==0.1.3
langchain-postgres==0.0.3
langchain-text-splitters==0.0.1
pgvector==0.2.5
psycopg==3.1.18
psycopg-binary==3.1.18
psycopg-pool==3.2.1

Originally created by @rkrkrediffmail on GitHub (May 2, 2024). ### Checked other resources - [X] I added a very descriptive title to this issue. - [X] I searched the LangChain documentation with the integrated search. - [X] I used the GitHub search to find a similar question and didn't find it. - [X] I am sure that this is a bug in LangChain rather than my code. - [X] The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package). ### Example Code #!/usr/bin/python3 import os import psycopg from psycopg import sql from langchain_postgres import PGVector from langchain_postgres.vectorstores import PGVector #from langchain.vectorstores.pgvector import PGVector #from langchain.vectorstores.pgvector import DistanceStrategy from langchain_openai import AzureOpenAIEmbeddings from langchain_openai import AzureChatOpenAI ### Error Message and Stack Trace (if applicable) Exception ignored in: <function PGVector.__del__ at 0x7fa9436f2a70> Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/langchain_postgres/vectorstores.py", line 326, in __del__ if isinstance(self._engine, sqlalchemy.engine.Connection): AttributeError: 'PGVector' object has no attribute '_engine' this is the error: PGVector.__init__() got an unexpected keyword argument 'connection_string' ### Description I have a RAG bot on AzureOpenAI. It has been working fine. However, after i upgraded my python=3.10 and openai>1.0, i upgraded the langchain modules as well. i had replaced the pgvector to "from langchain_postgres import PGVector" With the above upgrades and i tried creating new embeddings with "text-embedding-3-large" i get the following error. Exception ignored in: <function PGVector.__del__ at 0x7fa9436f2a70> Traceback (most recent call last): File "/usr/local/lib/python3.10/dist-packages/langchain_postgres/vectorstores.py", line 326, in __del__ if isinstance(self._engine, sqlalchemy.engine.Connection): AttributeError: 'PGVector' object has no attribute '_engine' this is the error: PGVector.__init__() got an unexpected keyword argument 'connection_string' i entirely removed the langchain_pg_collection and langchain_pg_embedding as the vector size was different (1536 to 3072) ### System Info langchain==0.1.16 langchain-community==0.0.34 langchain-core==0.1.46 langchain-mistralai==0.0.4 langchain-openai==0.1.3 langchain-postgres==0.0.3 langchain-text-splitters==0.0.1 pgvector==0.2.5 psycopg==3.1.18 psycopg-binary==3.1.18 psycopg-pool==3.2.1
yindo closed this issue 2026-02-16 05:16:03 -05:00
Author
Owner

@tejeshbhalla commented on GitHub (May 9, 2024):

any idea on this

@tejeshbhalla commented on GitHub (May 9, 2024): any idea on this
Author
Owner

@tejeshbhalla commented on GitHub (May 9, 2024):

??

@tejeshbhalla commented on GitHub (May 9, 2024): ??
Author
Owner

@evahbe commented on GitHub (May 15, 2024):

Hello @rkrkrediffmail could you share your connection string? I was playing with the "+psycopg" part of my connection string and after removing it, everything worked fine.

@evahbe commented on GitHub (May 15, 2024): Hello @rkrkrediffmail could you share your connection string? I was playing with the "+psycopg" part of my connection string and after removing it, everything worked fine.
Author
Owner

@eyurtsev commented on GitHub (May 17, 2024):

this is the error: PGVector.init() got an unexpected keyword argument 'connection_string'

Use connection not connection_string

https://github.com/langchain-ai/langchain-postgres/blob/main/examples/vectorstore.ipynb

@eyurtsev commented on GitHub (May 17, 2024): ```this is the error: PGVector.init() got an unexpected keyword argument 'connection_string'``` Use connection not connection_string https://github.com/langchain-ai/langchain-postgres/blob/main/examples/vectorstore.ipynb
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchain-postgres#11