Skip to content

feat: add run_async to CacheChecker#11271

Merged
julian-risch merged 6 commits intodeepset-ai:mainfrom
Aftabbs:feat/cache-checker-run-async
May 8, 2026
Merged

feat: add run_async to CacheChecker#11271
julian-risch merged 6 commits intodeepset-ai:mainfrom
Aftabbs:feat/cache-checker-run-async

Conversation

@Aftabbs
Copy link
Copy Markdown
Contributor

@Aftabbs Aftabbs commented May 7, 2026

Summary

  • Adds CacheChecker.run_async() method that mirrors run() but uses filter_documents_async on the document store
  • Enables CacheChecker to participate in AsyncPipeline without blocking the event loop
  • Follows the same pattern used by FilterRetriever.run_async (including the # type: ignore[attr-defined] comment since filter_documents_async is not in the DocumentStore protocol but exists in all concrete implementations)

Changes

  • haystack/components/caching/cache_checker.py — added run_async method
  • test/components/caching/test_cache_checker_async.py — new test file with 4 async tests covering hits, misses, all-hits, all-misses, and filter syntax verification

Test plan

  • python -m pytest test/components/caching/ -v passes (11 tests, all green)
  • Async tests cover the same scenarios as the existing sync tests

Related

CacheChecker was the only caching component and one of the few document-store-backed components still missing run_async. This brings it in line with FilterRetriever, AutoMergingRetriever, and SentenceWindowRetriever.

Adds an async counterpart to `CacheChecker.run()` that calls
`filter_documents_async` on the document store for each cache item,
enabling `CacheChecker` to be used in `AsyncPipeline` without blocking
the event loop.

Follows the same pattern used by `FilterRetriever.run_async`.
@Aftabbs Aftabbs requested a review from a team as a code owner May 7, 2026 03:08
@Aftabbs Aftabbs requested review from julian-risch and removed request for a team May 7, 2026 03:08
@vercel
Copy link
Copy Markdown

vercel Bot commented May 7, 2026

@Aftabbs is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels May 7, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/caching
  cache_checker.py
  haystack/components/generators/chat
  azure_responses.py 224
  openai_responses.py 268, 493-494
Project Total  

This report was generated by python-coverage-comment-action

@julian-risch
Copy link
Copy Markdown
Member

Hi @Aftabbs thank you for opening this PR. There is a format error in releasenotes/notes/add-run-async-for-CacheChecker-a42fa8062c33466b.yaml:4: Found single backticks. Use double backticks (code) for inline code.
Could you please fix that?

for item in items:
filters = {"field": self.cache_field, "operator": "==", "value": item}
# 'ignore' since filter_documents_async is not defined in the Protocol but exists in the implementations
found = await self.document_store.filter_documents_async(filters=filters) # type: ignore[attr-defined]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are similarly simply assuming in other parts of the code base that there is an implementation of filter_documents_async, for example here:

# Ignoring type error because DocumentStore protocol doesn't define filter_documents_async

In other parts of the code base (DocumentWriter), we raise an error:

if not hasattr(self.document_store, "write_documents_async"):
    raise TypeError(f"Document store {type(self.document_store).__name__} does not provide async support.")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An alternative would be to use a fallback:
If document_store has callable filter_documents_async: await it.
Else: await asyncio.to_thread(document_store.filter_documents, filters=filters).

@julian-risch
Copy link
Copy Markdown
Member

Looks good to me now. @Aftabbs Thank you for opening this pull request! I applied smaller changes directly and will merge the PR now.

@julian-risch julian-risch enabled auto-merge (squash) May 8, 2026 11:35
@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Preview May 8, 2026 1:36pm

Request Review

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@julian-risch julian-risch merged commit aa3bd1d into deepset-ai:main May 8, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants