Skip to content

Conversation

taylorn-ai
Copy link

Purpose

As discussed in #2569, adds an optional “agentic reference hydration” feature to agentic retrieval so the app can fetch the full documents for the agent’s references (all index fields, not just the semantic fields). This enables richer source metadata (e.g., sourcefile, category, scores) and more accurate citations, while keeping the legacy behaviour as default.

Key points:

  • New env flag: ENABLE_AGENTIC_REF_HYDRATION (default false).
  • When enabled, references returned by the Knowledge Agent are hydrated via a follow-up Azure AI Search query using a composed search.in filter over unique doc_keys.
  • Preserves existing behaviour when disabled: builds Document objects from source_data embedded in references.
  • Injects the agent’s per-activity search query into each Document (via search_agent_query) for better observability.
  • Deterministic ordering:
    • Default: preserves agent order.
    • results_merge_strategy == "interleaved": sorts by reference.id (ascending) to interleave across activities.
  • Infra wiring: Bicep + parameters propagate the new flag to App Service env vars.
  • Documentation updated to describe the optional hydration behaviour and how to enable it.
  • Comprehensive tests added covering:
    • Hydrated vs non-hydrated paths
    • Interleaved sorting
    • Deduplication of duplicate doc_keys
    • Respecting top
    • Missing/empty doc_keys
    • Empty hydration results

Does this introduce a breaking change?

When developers merge from main and run the server, azd up, or azd deploy, will this produce an error?
If you're not sure, try it out on an old environment.

[ ] Yes
[x] No

Why:

  • The new behaviour is gated behind ENABLE_AGENTIC_REF_HYDRATION which defaults to false.
  • Constructors were extended with a defaulted hydrate_references: bool = False and all call sites updated accordingly.
  • Infra adds a new parameter with a default of false; existing environments deploy without change.

Does this require changes to learn.microsoft.com docs?

This repository is referenced by this tutorial
which includes deployment, settings and usage instructions. If text or screenshot need to change in the tutorial,
check the box below and notify the tutorial author. A Microsoft employee can do this for you if you're an external contributor.

[ ] Yes
[x] No

Type of change

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[x] Documentation content changes
[ ] Other... Please describe:

Code quality checklist

See CONTRIBUTING.md for more details.

  • The current tests all pass (python -m pytest).
  • I added tests that prove my fix is effective or that my feature works
  • I ran python -m pytest --cov to verify 100% coverage of added lines
  • I ran python -m mypy to check for type errors
  • I either used the pre-commit hooks or ran ruff and black manually on my code.

Taylor added 4 commits August 22, 2025 11:12
- Fix command to generate HTML report for coverage using `diff-cover` 🛠️
- Introduce ENABLE_AGENTIC_REF_HYDRATION environment variable to control reference hydration behaviour 🌱
- Update Approach classes to accept hydrate_references parameter for managing reference hydration logic 🔧
- Modify document retrieval logic to hydrate references when enabled, improving data completeness 📄
- ✨ Add support for enabling extra field hydration in agentic retrieval
- 🔧 Update infrastructure to include new parameter for hydration
- 📝 Modify documentation to reflect changes in usage instructions
- 🎉 Introduce ENABLE_AGENTIC_REF_HYDRATION environment variable for configuration
- 🧪 Implement mock search results for hydration testing in agentic retrieval
- 🔍 Create tests for agentic retrieval with and without hydration enabled
- 📜 Ensure hydrated results include additional fields from search results
@taylorn-ai
Copy link
Author

@microsoft-github-policy-service agree

@pamelafox
Copy link
Collaborator

Thank you @taylorn-ai for the great contribution! I would like @mattgotteiner from the AI Search team to review this, given his expertise with agentic retrieval.

@taylorn-ai
Copy link
Author

I ran black on the files I changed, do you want me to re-run on everything? Or do you want to do that?

@taylorn-ai
Copy link
Author

My bad, seems I didn't run black on the tests directory.

@taylorn-ai
Copy link
Author

Apologies, I thought I had updated the test snapshots. Also @pamelafox, FYI, the pre-commit hooks aren't working. I ran it manually and it changed some other files that I hadn't edited, so I left them as they were.

@pamelafox
Copy link
Collaborator

@taylorn-ai Interesting, sometimes that happens when the formatter changes its rules. I do run them locally but I might need to explicitly re-install the pre-commit hooks to see if formatter rules changes/

@taylorn-ai
Copy link
Author

Two of the tests failed due to a network issue, is that common? Seems odd. At least it's not my fault 😀

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