upgrading from 0.0.6 -> 0.0.9, getting _async_engine not found #34

Closed
opened 2026-02-16 05:16:11 -05:00 by yindo · 5 comments
Owner

Originally created by @codekiln on GitHub (Aug 6, 2024).

image

Log signature: _async_engine not found

error emerges from langchain_postgres.vectorstores.PGVector.acreate_vector_extension

I'm trying to call invoke(), so I don't really understand why it's trying to use the async version


In [3]: print_sys_info()

System Information
------------------
> OS:  Darwin
> OS Version:  Darwin Kernel Version 23.6.0: Fri Jul  5 17:53:24 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T6020
> Python Version:  3.11.9 (main, May 16 2024, 15:36:38) [Clang 15.0.0 (clang-1500.3.9.4)]

Package Information
-------------------
> langchain_core: 0.2.28
> langchain: 0.2.12
> langchain_community: 0.2.11
> langsmith: 0.1.96
> langchain_anthropic: 0.1.22
> langchain_aws: 0.1.15
> langchain_cli: 0.0.28
> langchain_openai: 0.1.20
> langchain_postgres: 0.0.9
> langchain_text_splitters: 0.2.2
> langchainhub: 0.1.20
> langgraph: 0.1.19
> langserve: 0.2.2

I'm going to downgrade back to 0.0.6 for now.

How I'm instantiating PGVector -

PGVector(
        embeddings=embeddings,
        collection_name=collection_name,
        connection=conn_string,
        use_jsonb=True,
        pre_delete_collection=pre_delete_collection,
    )

I tried updating the connection string so it used postgresql+asyncpg:// instead of postgresql+psycopg:// but got a bunch of downstream errors related to module not found, then tried adding these dependencies to pyproject.toml:

asyncpg = "^0.29.0"
greenlet = "^3.0.3"

But at this point, when using langserve I'm not totally certain how to make it instantiate the async version.

Expected Behavior

  • Upgrading patch versions doesn't change synchronous behavior in a backwards-incompatible way
  • Calling the ainvoke and other methods use the async postgres connection, calling invoke uses the sync postgres connection
  • Breaking changes are accompanied by docs in the README
  • There is way to use synchronous behavior without asynchronous behavior that is documented in the README

Actual Behavior

  • Upgrading patch versions are not backwards compatible
  • The mention of "async" in the README after 0.0.6 doesn't offer adequate context on how to configure the project for async (or not)
  • Project appears to be async by default and it's not clear if it's still possible to use it without configuring async drivers
Originally created by @codekiln on GitHub (Aug 6, 2024). ![image](https://github.com/user-attachments/assets/d782d63d-e98d-4199-af56-6df2241a4b19) Log signature: `_async_engine not found` error emerges from `langchain_postgres.vectorstores.PGVector.acreate_vector_extension` I'm trying to call `invoke()`, so I don't really understand why it's trying to use the async version ``` In [3]: print_sys_info() System Information ------------------ > OS: Darwin > OS Version: Darwin Kernel Version 23.6.0: Fri Jul 5 17:53:24 PDT 2024; root:xnu-10063.141.1~2/RELEASE_ARM64_T6020 > Python Version: 3.11.9 (main, May 16 2024, 15:36:38) [Clang 15.0.0 (clang-1500.3.9.4)] Package Information ------------------- > langchain_core: 0.2.28 > langchain: 0.2.12 > langchain_community: 0.2.11 > langsmith: 0.1.96 > langchain_anthropic: 0.1.22 > langchain_aws: 0.1.15 > langchain_cli: 0.0.28 > langchain_openai: 0.1.20 > langchain_postgres: 0.0.9 > langchain_text_splitters: 0.2.2 > langchainhub: 0.1.20 > langgraph: 0.1.19 > langserve: 0.2.2 ``` I'm going to downgrade back to 0.0.6 for now. How I'm instantiating PGVector - ```python PGVector( embeddings=embeddings, collection_name=collection_name, connection=conn_string, use_jsonb=True, pre_delete_collection=pre_delete_collection, ) ``` I tried updating the connection string so it used `postgresql+asyncpg://` instead of `postgresql+psycopg://` but got a bunch of downstream errors related to module not found, then tried adding these dependencies to pyproject.toml: ``` asyncpg = "^0.29.0" greenlet = "^3.0.3" ``` But at this point, when using langserve I'm not totally certain how to make it instantiate the async version. ## Expected Behavior * Upgrading patch versions doesn't change synchronous behavior in a backwards-incompatible way * Calling the `ainvoke` and other methods use the async postgres connection, calling `invoke` uses the sync postgres connection * Breaking changes are accompanied by docs in the README * There is way to use synchronous behavior without asynchronous behavior that is documented in the README ## Actual Behavior * Upgrading patch versions are not backwards compatible * The mention of "async" in the README after 0.0.6 doesn't offer adequate context on how to configure the project for async (or not) * Project appears to be async by default and it's not clear if it's still possible to use it without configuring async drivers
yindo closed this issue 2026-02-16 05:16:11 -05:00
Author
Owner

@Simon-Stone commented on GitHub (Aug 6, 2024):

Ran into the same issue when trying to deploy a chain containing a PGVector vectorstore using LangServe. Downgrading to 0.0.6 helped.

@Simon-Stone commented on GitHub (Aug 6, 2024): Ran into the same issue when trying to deploy a chain containing a PGVector vectorstore using LangServe. Downgrading to 0.0.6 helped.
Author
Owner

@Benjaminrivard commented on GitHub (Aug 21, 2024):

Hi,

If you actually want to use the async methods with latest version (0.0.9), you could use the following snippet, which uses create_async_engine (I got it from PR https://github.com/langchain-ai/langchain-postgres/pull/64)

from langchain_postgres import PGVector
from sqlalchemy.ext.asyncio import create_async_engine

connection_str = "postgresql+psycopg://[...]"
[...]
engine = create_async_engine(connection)

vectorstore = PGVector(
    embeddings=embeddings,
    collection_name=collection_name,
    connection=engine,
    use_jsonb=True,
)

Best,
Benjamin

@Benjaminrivard commented on GitHub (Aug 21, 2024): Hi, If you actually want to use the async methods with latest version (0.0.9), you could use the following snippet, which uses `create_async_engine` (I got it from PR https://github.com/langchain-ai/langchain-postgres/pull/64) ```python from langchain_postgres import PGVector from sqlalchemy.ext.asyncio import create_async_engine connection_str = "postgresql+psycopg://[...]" [...] engine = create_async_engine(connection) vectorstore = PGVector( embeddings=embeddings, collection_name=collection_name, connection=engine, use_jsonb=True, ) ``` Best, Benjamin
Author
Owner

@eyurtsev commented on GitHub (Sep 12, 2024):

LangServe is async by default. So if you're using langserve you should be creating an async engine. This is not a bug in the library -- just bad documentation

@eyurtsev commented on GitHub (Sep 12, 2024): LangServe is async by default. So if you're using langserve you should be creating an async engine. This is not a bug in the library -- just bad documentation
Author
Owner

@zeusari commented on GitHub (Apr 25, 2025):

Hi,

If you actually want to use the async methods with latest version (0.0.9), you could use the following snippet, which uses create_async_engine (I got it from PR #64)

from langchain_postgres import PGVector
from sqlalchemy.ext.asyncio import create_async_engine

connection_str = "postgresql+psycopg://[...]"
[...]
engine = create_async_engine(connection)

vectorstore = PGVector(
embeddings=embeddings,
collection_name=collection_name,
connection=engine,
use_jsonb=True,
)
Best, Benjamin

While running this in Windows I encountered this exception.

raise e.InterfaceError(
sqlalchemy.exc.InterfaceError: (psycopg.InterfaceError) Psycopg cannot use the 'ProactorEventLoop' to run in async mode. Please use a compatible event loop, for instance by setting 'asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())'

Adding the correct EventLoopPolicy help resolving this. If it helps other below is the code snippet.

if sys.platform == "win32":
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) 

Found the solution here:
here

@zeusari commented on GitHub (Apr 25, 2025): > Hi, > > If you actually want to use the async methods with latest version (0.0.9), you could use the following snippet, which uses `create_async_engine` (I got it from PR [#64](https://github.com/langchain-ai/langchain-postgres/pull/64)) > > from langchain_postgres import PGVector > from sqlalchemy.ext.asyncio import create_async_engine > > connection_str = "postgresql+psycopg://[...]" > [...] > engine = create_async_engine(connection) > > vectorstore = PGVector( > embeddings=embeddings, > collection_name=collection_name, > connection=engine, > use_jsonb=True, > ) > Best, Benjamin While running this in Windows I encountered this exception. ``` raise e.InterfaceError( sqlalchemy.exc.InterfaceError: (psycopg.InterfaceError) Psycopg cannot use the 'ProactorEventLoop' to run in async mode. Please use a compatible event loop, for instance by setting 'asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())' ``` Adding the correct EventLoopPolicy help resolving this. If it helps other below is the code snippet. ``` if sys.platform == "win32": asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy()) ``` Found the solution here: [here](https://stackoverflow.com/questions/71219607/psycopg3-unable-to-connect-async)
Author
Owner

@pavlix98 commented on GitHub (Oct 3, 2025):

Using the latest version (0.0.15), I am still encountering the same problem. A Google search brought me here.

After analyzing the source code, it seems we now have a better option for using PGVector in an async environment—by simply enabling async mode:

from langchain_postgres import PGVector

connection_str = "postgresql+psycopg://[...]"

vectorstore = PGVector(
    embeddings=embeddings,
    collection_name=collection_name,
    connection=connection_str,
    async_mode=True,
)

I still think it would be helpful to have an error message that describes the issue more clearly, instead of just:

Error: AssertionError('_async_engine not found')
Please fix your mistakes.

@pavlix98 commented on GitHub (Oct 3, 2025): Using the latest version (0.0.15), I am still encountering the same problem. A Google search brought me here. After analyzing the source code, it seems we now have a better option for using PGVector in an async environment—by simply enabling async mode: ````python from langchain_postgres import PGVector connection_str = "postgresql+psycopg://[...]" vectorstore = PGVector( embeddings=embeddings, collection_name=collection_name, connection=connection_str, async_mode=True, ) ```` I still think it would be helpful to have an error message that describes the issue more clearly, instead of just: > Error: AssertionError('_async_engine not found') Please fix your mistakes.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langchain-postgres#34