fix(providers): use async elasticsearch client in retrieve() (fixes #82)#195
Merged
himanshu231204 merged 1 commit intoJul 19, 2026
Merged
Conversation
…enAgentHQ#82) The retriever constructed a synchronous Elasticsearch client but called self._client.search(...) without await from an async def retrieve(), blocking the event loop during network I/O. Mirrors the fix shape from OpenAgentHQ#182 (pgvector): swap the sync client for the library's async client and await the I/O call. Unlike pgvector, AsyncElasticsearch's constructor performs no I/O, so no lazy-connection deferral is needed. - Use AsyncElasticsearch instead of Elasticsearch. - await self._client.search(...) in retrieve(). - Add close() to terminate the async client. Adds tests/unit/test_providers/test_elasticsearch_retriever.py (4 tests, elasticsearch async surface mocked via sys.modules patch, no real Elasticsearch cluster required). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
🎉 Congratulations @Nitjsefnie! Your pull request has been successfully merged into main. 🚀 Thank you for contributing to OpenAgentHQ and helping improve the project. We truly appreciate your contribution and hope to see you back with more amazing PRs! Happy Open Sourcing! ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Same shape as the merged #182 pgvector fix, applied to the elasticsearch retriever:
Elasticsearch→AsyncElasticsearch,await self._client.search(...), plus anasync close(). One deliberate divergence from #182, verified against the API rather than assumed:AsyncElasticsearch()'s constructor performs no I/O (same as the sync client), so #182's lazy_ensure_connection()deferral isn't needed here.Tests mirror
test_pgvector_retriever.py's idiom (lazy import →patch.dict(sys.modules)fake, no importorskip needed): async-client-used-and-awaited for both query modes, typed construction error, andclose()termination. All four fail on unfixed source — the fake module deliberately exports onlyAsyncElasticsearch, so the old sync import breaks exactly as the bug predicts — and pass with the fix.Suite: 909 passed +4 new; the single pre-existing
TestBERTScore::test_identicalfloat-precision failure is present on clean main and untouched. Ruff clean on both changed files (the two pre-existing findings on unrelated lines ofelasticsearch.pyare present on main).The issue's note about the same pattern in qdrant/pinecone/weaviate/chroma is real but deliberately out of scope here — happy to sweep those as a follow-up if you'd like the same treatment.
Generated by Claude Fable 5 (brief, review), Claude Sonnet 4.6 (implementation)