Does PGVector really need SQLAlchemy URLs? If so, why not psycopg3? #76

Closed
opened 2026-02-16 05:16:27 -05:00 by yindo · 7 comments
Owner

Originally created by @khteh on GitHub (Jun 1, 2025).

When I use postgresql scheme, I hit this error:

  File "/usr/src/Python/rag-agent/src/Infrastructure/VectorStore.py", line 87, in __init__
    self.vector_store = PGVector(
                        ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        embeddings = self._embeddings,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
        async_mode = True
        ^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/langchain_postgres/vectorstores.py", line 434, in __init__
    self._async_engine = create_async_engine(
                         ~~~~~~~~~~~~~~~~~~~^
        connection, **(engine_args or {})
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/sqlalchemy/ext/asyncio/engine.py", line 120, in create_async_engine
    sync_engine = _create_engine(url, **kw)
  File "<string>", line 2, in create_engine
  File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned
    return fn(*args, **kwargs)  # type: ignore[no-any-return]
  File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/sqlalchemy/engine/create.py", line 602, in create_engine
    dbapi = dbapi_meth(**dbapi_args)
  File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 696, in import_dbapi
    import psycopg2
ModuleNotFoundError: No module named 'psycopg2'

(1) Why psycopg2 instead of psycopg3 (https://www.psycopg.org/psycopg3/docs/basic/install.html)?

(2) Does it actually need SQLAlchemy URLs since it is PGVector? Why not directly using the postgresql scheme?

Originally created by @khteh on GitHub (Jun 1, 2025). When I use `postgresql` scheme, I hit this error: ``` File "/usr/src/Python/rag-agent/src/Infrastructure/VectorStore.py", line 87, in __init__ self.vector_store = PGVector( ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ embeddings = self._embeddings, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<3 lines>... async_mode = True ^^^^^^^^^^^^^^^^^ ) ^ File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/langchain_postgres/vectorstores.py", line 434, in __init__ self._async_engine = create_async_engine( ~~~~~~~~~~~~~~~~~~~^ connection, **(engine_args or {}) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ^ File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/sqlalchemy/ext/asyncio/engine.py", line 120, in create_async_engine sync_engine = _create_engine(url, **kw) File "<string>", line 2, in create_engine File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/sqlalchemy/util/deprecations.py", line 281, in warned return fn(*args, **kwargs) # type: ignore[no-any-return] File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/sqlalchemy/engine/create.py", line 602, in create_engine dbapi = dbapi_meth(**dbapi_args) File "/home/khteh/.local/share/virtualenvs/rag-agent-YeW3dxEa/lib/python3.13/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 696, in import_dbapi import psycopg2 ModuleNotFoundError: No module named 'psycopg2' ``` (1) Why `psycopg2` instead of `psycopg3` (https://www.psycopg.org/psycopg3/docs/basic/install.html)? (2) Does it actually need SQLAlchemy URLs since it is `PG`Vector? Why not directly using the `postgresql` scheme?
yindo closed this issue 2026-02-16 05:16:27 -05:00
Author
Owner

@averikitsch commented on GitHub (Jul 2, 2025):

Hi @khteh can you provide the code snippet you are trying to run? Thanks!

@averikitsch commented on GitHub (Jul 2, 2025): Hi @khteh can you provide the code snippet you are trying to run? Thanks!
Author
Owner
@khteh commented on GitHub (Jul 3, 2025): https://github.com/khteh/rag-agent/blob/master/src/Infrastructure/VectorStore.py
Author
Owner

@averikitsch commented on GitHub (Jul 10, 2025):

I am unable to reproduce the issue. What version of the library are you using?

@averikitsch commented on GitHub (Jul 10, 2025): I am unable to reproduce the issue. What version of the library are you using?
Author
Owner

@khteh commented on GitHub (Jul 11, 2025):

You need to modify the code to use config.POSTGRESQL_DATABASE_URI to reproduce it.

langchain-postgres==0.0.15
@khteh commented on GitHub (Jul 11, 2025): You need to modify the code to use `config.POSTGRESQL_DATABASE_URI` to reproduce it. ``` langchain-postgres==0.0.15 ```
Author
Owner

@averikitsch commented on GitHub (Jul 11, 2025):

Your URI is incorrect. Please update to use postgresql+psycopg://. More info can be found https://github.com/langchain-ai/langchain-postgres/blob/main/examples/vectorstore.ipynb.

@averikitsch commented on GitHub (Jul 11, 2025): Your URI is incorrect. Please update to use `postgresql+psycopg://`. More info can be found https://github.com/langchain-ai/langchain-postgres/blob/main/examples/vectorstore.ipynb.
Author
Owner

@khteh commented on GitHub (Jul 11, 2025):

Isn't this back to square one? Can you please read the title of this issue again!?!

@khteh commented on GitHub (Jul 11, 2025): Isn't this back to square one? Can you please read the title of this issue again!?!
Author
Owner

@averikitsch commented on GitHub (Jul 28, 2025):

@khteh
Yes, you need a SQLAlchemy URL since the underlying package relies on SQLAlchemy. postgresql+psycopg:// uses pscyopg3.

@averikitsch commented on GitHub (Jul 28, 2025): @khteh Yes, you need a SQLAlchemy URL since the underlying package relies on SQLAlchemy. `postgresql+psycopg://` uses pscyopg3.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchain-postgres#76