Skip to content

fix(providers): use async elasticsearch client in retrieve() (fixes #82)#195

Merged
himanshu231204 merged 1 commit into
OpenAgentHQ:mainfrom
Nitjsefnie:fix/82-async-elasticsearch
Jul 19, 2026
Merged

fix(providers): use async elasticsearch client in retrieve() (fixes #82)#195
himanshu231204 merged 1 commit into
OpenAgentHQ:mainfrom
Nitjsefnie:fix/82-async-elasticsearch

Conversation

@Nitjsefnie

Copy link
Copy Markdown
Contributor

Same shape as the merged #182 pgvector fix, applied to the elasticsearch retriever: ElasticsearchAsyncElasticsearch, await self._client.search(...), plus an async 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, and close() termination. All four fail on unfixed source — the fake module deliberately exports only AsyncElasticsearch, 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_identical float-precision failure is present on clean main and untouched. Ruff clean on both changed files (the two pre-existing findings on unrelated lines of elasticsearch.py are 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)

…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>
@himanshu231204
himanshu231204 merged commit 16a87f2 into OpenAgentHQ:main Jul 19, 2026
9 checks passed
@github-actions

Copy link
Copy Markdown

🎉 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! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants