Skip to content

Langchain pgvector database sessions remain in idle mode #28347

Closed as not planned
@nitual1

Description

@nitual1

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

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

engine = create_async_engine(self.__CONNECTION_STRING)
try:
store = PGVector(
embeddings = embeddings,
collection_name = collection,
connection = engine,
use_jsonb = True,
)
except Exception as e:
raise e

Error Message and Stack Trace (if applicable)

Once I reach the maximum number of possible concurrent sessions in pgAdmin I get an error message telling me I reached the max level of open sessions. I have used the timeout parameters of PostgreSQL to close these sessions automatically (idle_in_transaction_session_timeout and idle_session_timeout), but normally they should get closed from the PGVector library.

Description

I am using PGVector library from langchain_postgres.vectorstores and create_async_engine from sqlalchemy.ext.asyncio to retrieve embeddings from a PostgreSQL database.

I observed that for each retrieval from db, I get many sessions that become idle but never disappear from pgAdmin interface:
SS_IssuePGVector

I am using pgAdmin 4 8.2 version, PostgreSQL 16.2-1.

System Info

System Information

OS: Windows
OS Version: 10.0.20348
Python Version: 3.12.4 (tags/v3.12.4:8e8a4ba, Jun 6 2024, 19:30:16) [MSC v.1940 64 bit (AMD64)]

Package Information

langchain_core: 0.3.15
langchain: 0.3.7
langchain_community: 0.3.5
langsmith: 0.1.137
langchain_chroma: 0.1.4
langchain_experimental: 0.3.3
langchain_openai: 0.2.5
langchain_postgres: 0.0.12
langchain_text_splitters: 0.3.2
langgraph: 0.2.46

Optional packages not installed

langserve

Other Dependencies

aiohttp: 3.10.10
async-timeout: Installed. No version info available.
chromadb: 0.5.17
dataclasses-json: 0.6.7
fastapi: 0.115.4
httpx: 0.27.2
httpx-sse: 0.4.0
jsonpatch: 1.33
langgraph-checkpoint: 2.0.3
langgraph-sdk: 0.1.35
numpy: 1.26.4
openai: 1.54.0
orjson: 3.10.10
packaging: 24.1
pgvector: 0.2.5
psycopg: 3.2.3
psycopg-pool: 3.2.3
pydantic: 2.9.2
pydantic-settings: 2.6.0
PyYAML: 6.0.2
requests: 2.32.3
requests-toolbelt: 1.0.0
SQLAlchemy: 2.0.35
sqlalchemy: 2.0.35
tenacity: 9.0.0
tiktoken: 0.8.0
typing-extensions: 4.12.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    investigateFlagged for investigation.Ɑ: vector storeRelated to vector store module

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions