langchain-ai / langchain-postgres

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

Connection error use azure embedding #43

Open cxy-gpt opened 1 month ago

cxy-gpt commented 1 month ago

code

`connection = "postgresql+psycopg://YYY:XXXX@localhost/ZZZ" collection_name = "my_docs" from langchain_postgres import PGVector from langchain_postgres.vectorstores import PGVector

vectorstore = PGVector( embeddings=embeddings, collection_name=collection_name, connection=connection, use_jsonb=True, ) db = vectorstore.from_texts( ["communication"], embeddings)`

error info db = vectorstore.from_texts( ["communication"], embeddings) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/anaconda3/lib/python3.11/site-packages/langchain_postgres/vectorstores.py", line 975, in from_texts return cls.from( ^^^^^^^^^^^ File "/usr/local/anaconda3/lib/python3.11/site-packages/langchain_postgres/vectorstores.py", line 438, in __from store = cls( ^^^^ File "/usr/local/anaconda3/lib/python3.11/site-packages/langchain_postgres/vectorstores.py", line 295, in init raise ValueError( ValueError: connection should be a connection string or an instance of sqlalchemy.engine.Engine Exception ignored in: <function PGVector.del__ at 0x7fdf7b19dda0> Traceback (most recent call last): File "/usr/local/anaconda3/lib/python3.11/site-packages/langchain_postgres/vectorstores.py", line 326, in del if isinstance(self._engine, sqlalchemy.engine.Connection): ^^^^^^^^^^^^ AttributeError: 'PGVector' object has no attribute '_engine'

evahbe commented 1 month ago

I think it is because it is not detecting correctly the 'connection_string' parameter, try checking and varying it, mostly adding/removing the "+psycopg" part, for me it kinda worked. Got some other error after, but at least not that one any more!