langchain-ai / langchain-postgres

LangChain abstractions backed by Postgres Backend
MIT License
66 stars 22 forks source link

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

Closed rkrkrediffmail closed 1 month ago

rkrkrediffmail commented 2 months ago

Checked other resources

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

tejeshbhalla commented 1 month ago

any idea on this

tejeshbhalla commented 1 month ago

??

evahbe commented 1 month ago

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.

eyurtsev commented 1 month ago

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