Devr.AI icon indicating copy to clipboard operation
Devr.AI copied to clipboard

ENHANCEMENT:Weaviate client connects and disconnects causing latency issues

Open vaishcodescape opened this issue 10 months ago • 2 comments

Is there an existing issue for this?

  • [x] I have searched the existing issues

What happened?

📌 Issue Overview

The Weaviate backend client repeatedly connects and disconnects on every database operation instead of reusing a persistent connection, causing unnecessary performance overhead.

🔍 Root Cause

  • get_weaviate_client() calls await client.connect() on entry and await client.close() on exit
  • All Weaviate operations use async with get_weaviate_client(), triggering a full connect/disconnect cycle per request
  • This occurs despite having a global client instance

🚨 Actual Behavior

  • A new connection is established for every operation
  • The connection is closed immediately after use
  • No connection pooling or reuse
  • Adds ~10–50ms latency per query
  • Wastes resources and becomes a scalability bottleneck under load
@asynccontextmanager
async def get_weaviate_client():
    client = get_client()
    try:
        await client.connect()   # connects every time
        yield client
    finally:
        await client.close()     # disconnects every time

Record

  • [x] I agree to follow this project's Code of Conduct
  • [x] I want to work on this issue

vaishcodescape avatar Jan 11 '26 11:01 vaishcodescape

@smokeyScraper @chandansgowda Hey guys can you assign this issue to me ?

vaishcodescape avatar Jan 11 '26 11:01 vaishcodescape

Thanks for the detailed analysis, @vaishcodescape. I agree, the current pattern of connecting/disconnecting per request was an initial design choice to avoid holding idle connections, but it's no longer scalable given our increased traffic for indexing and recommendations.

We should definitely refactor this to initialize a global persistent connection on app startup and close it on shutdown, rather than inside the dependency context manager. This will remove the handshake latency you observed.

smokeyScraper avatar Jan 11 '26 11:01 smokeyScraper