added pagination for azure ai search retriever #29525
Open
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.
Description
This PR adds support for pagination in the Azure AI Search retriever. Currently, when top_k=None, the retriever only returns up to 50 results due to Azure's default limit. This change properly implements pagination to retrieve all matching documents when top_k=None, ensuring complete results.
Changes
Modified _search and _asearch methods to implement pagination using $top and $skip parameters.
Ensured top_k=None retrieves all results instead of being limited to 50.
Preserved original top_k behavior when explicitly set.
Added pagination support in both synchronous and asynchronous implementations.
Issue
Closes #27830
Implementation Notes
No changes to the public API or function signatures.
Backwards compatible—behavior remains unchanged for top_k values set explicitly.
More efficient than retrieving results in a single large batch.
Preserves all existing functionality, including metadata handling and document conversion.
Dependencies
None
Additional Notes
The implementation ensures proper pagination logic using $top and $skip.
Aligns with Azure AI Search best practices for retrieving large datasets.
Future extensions could include dynamic batch size optimization for better performance. 🚀