Skip to content

Conversation

@giles17
Copy link
Contributor

@giles17 giles17 commented Dec 2, 2025

Motivation and Context

Adds extraction method to sample

Description

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? If yes, add "[BREAKING]" prefix to the title of the PR.

Copilot AI review requested due to automatic review settings December 2, 2025 23:31
@github-actions github-actions bot changed the title Azure AI Search Citation Extraction - V2 Python: Azure AI Search Citation Extraction - V2 Dec 2, 2025
Copilot finished reviewing on behalf of giles17 December 2, 2025 23:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances the Azure AI Search sample by adding citation extraction functionality to demonstrate how to retrieve and display citation information from agent responses.

Key Changes:

  • Added extract_citations_from_response helper function to parse citations from agent responses
  • Modified the query to request detailed winter hotel information
  • Changed query_type from "simple" to "vector" mode
  • Added citation display logic to show extracted citation URLs

if citations:
for i, citation in enumerate(citations, 1):
print(f"Citation {i}:")
print(f" URL: {citation['url']}")
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

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

The extract_citations_from_response function has incomplete citation output. Currently only the URL is printed (line 94), but the function extracts title, file_id, and positions which are not displayed. This makes the citation information incomplete for users who may need these additional details.

Consider printing all extracted citation information:

print(f"Citation {i}:")
print(f"  URL: {citation['url']}")
if citation.get('title'):
    print(f"  Title: {citation['title']}")
if citation.get('file_id'):
    print(f"  File ID: {citation['file_id']}")
if citation.get('positions'):
    print(f"  Positions: {citation['positions']}")
Suggested change
print(f" URL: {citation['url']}")
print(f" URL: {citation['url']}")
if citation.get('title'):
print(f" Title: {citation['title']}")
if citation.get('file_id'):
print(f" File ID: {citation['file_id']}")
if citation.get('positions'):
print(f" Positions: {citation['positions']}")

Copilot uses AI. Check for mistakes.
"""Extract citation information from an AgentRunResponse."""
citations: list[dict[str, Any]] = []

if hasattr(response, "messages") and response.messages:
Copy link
Member

Choose a reason for hiding this comment

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

you can skip a bunch of these checks (it's a sample, so we can be a less strict on typing, to improve readability) and inverse the logic for the rest:

Suggested change
if hasattr(response, "messages") and response.messages:
from itertools import chain
if not response.messages:
return citations
for content in chain.from_iterable(message.contents for message in response.messages):
if not content.annotations:
continue
# parse the annotations

Also why not just return the citations instead of this dict?

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants