You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/azure-ai-citations.md
+73-71Lines changed: 73 additions & 71 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,30 +4,31 @@ This document describes the native OpenWebUI citation support in the Azure AI Fo
4
4
5
5
## Overview
6
6
7
-
The Azure AI Foundry Pipeline now supports **native OpenWebUI citations** for Azure AI Search (RAG) responses. This feature enables the OpenWebUI frontend to display:
7
+
The Azure AI Foundry Pipeline supports **native OpenWebUI citations** for Azure AI Search (RAG) responses. This feature is **automatically enabled** when you configure Azure AI Search data sources (`AZURE_AI_DATA_SOURCES`). The OpenWebUI frontend will display:
8
8
9
9
-**Citation cards** with source information and relevance scores
10
10
-**Source previews** with content snippets
11
-
-**Relevance percentage** displayed on citation cards
12
-
-**Interactive citation UI** with clickable sources
11
+
-**Relevance percentage** displayed on citation cards (requires `AZURE_AI_INCLUDE_SEARCH_SCORES=true`)
12
+
-**Clickable `[docX]` references** that link directly to document URLs
13
+
-**Interactive citation UI** with expandable source details
13
14
14
15
## Features
15
16
16
-
### Dual Citation Modes
17
+
### Automatic Citation Support
17
18
18
-
The pipeline supports two modes for displaying citations:
19
+
When Azure AI Search is configured, the pipeline automatically:
19
20
20
-
1.**Native OpenWebUI Citations** (new): Structured citation events emitted via `__event_emitter__` for frontend consumption
21
-
2.**Markdown/HTML Citations** (existing): Collapsible HTML details with formatted citation information
22
-
23
-
Both modes can be enabled simultaneously or independently via configuration.
21
+
1.Emits citation events via `__event_emitter__` for the OpenWebUI frontend
22
+
2.Converts `[docX]` references in the response to clickable markdown links
23
+
3. Filters citations to only show documents actually referenced in the response
24
+
4. Extracts relevance scores from Azure Search when available
# Enable both native and markdown/HTML citations (default)
110
-
AZURE_AI_OPENWEBUI_CITATIONS=true
111
-
AZURE_AI_ENHANCE_CITATIONS=true
112
+
The pipeline automatically converts `[docX]` references to clickable markdown links:
113
+
114
+
```markdown
115
+
# Input from Azure AI
116
+
The answer can be found in [doc1] and [doc2].
117
+
118
+
# Output (converted by pipeline)
119
+
The answer can be found in [[doc1]](https://example.com/doc1.pdf) and [[doc2]](https://example.com/doc2.pdf).
112
120
```
113
121
114
-
This configuration provides:
115
-
- Native citation cards in the OpenWebUI frontend
116
-
- Markdown/HTML citation section as fallback for non-supported clients
122
+
This works for both streaming and non-streaming responses.
117
123
118
-
### Only Markdown/HTML Citations (Legacy)
124
+
### Relevance Scores
119
125
120
-
```python
121
-
# Disable native citations, use only markdown/HTML
122
-
AZURE_AI_OPENWEBUI_CITATIONS=false
123
-
AZURE_AI_ENHANCE_CITATIONS=true
124
-
```
126
+
When `AZURE_AI_INCLUDE_SEARCH_SCORES=true` (default), the pipeline:
127
+
128
+
1. Automatically adds `include_contexts: ["citations", "all_retrieved_documents"]` to Azure Search requests
129
+
2. Extracts scores based on the `filter_reason` field:
130
+
-`filter_reason="rerank"` → uses `rerank_score`
131
+
-`filter_reason="score"` or not present → uses `original_search_score`
132
+
3. Displays the score as a percentage on citation cards
125
133
126
134
## Implementation Details
127
135
128
136
### Helper Functions
129
137
130
-
The pipeline includes three new helper functions:
138
+
The pipeline includes these helper functions for citation processing:
131
139
132
140
1.**`_extract_citations_from_response()`**: Extracts citations from Azure responses
133
141
2.**`_normalize_citation_for_openwebui()`**: Converts Azure citations to OpenWebUI format
134
142
3.**`_emit_openwebui_citation_events()`**: Emits citation events via `__event_emitter__`
143
+
4.**`_merge_score_data()`**: Matches citations with score data from `all_retrieved_documents`
144
+
5.**`_build_citation_urls_map()`**: Builds mapping of citation indices to URLs
145
+
6.**`_format_citation_link()`**: Creates markdown links for `[docX]` references
146
+
7.**`_convert_doc_refs_to_links()`**: Converts all `[docX]` references in content to markdown links
135
147
136
148
### Title Fallback Logic
137
149
138
150
The pipeline uses intelligent title fallback:
139
151
140
152
1. Use `title` field if available
141
-
2. Fallback to `filepath` if title is empty
142
-
3. Fallback to `url` if both title and filepath are empty
143
-
4. Fallback to `"Unknown Document"` if all are empty
153
+
2. Fallback to filename extracted from `filepath` or `url`
154
+
3. Fallback to `"Unknown Document"` if all are empty
144
155
145
156
This ensures every citation has a meaningful display name.
146
157
147
-
### Streaming Citation Emission
148
-
149
-
Citations are emitted **as soon as they are detected** in the stream, ensuring:
150
-
- Low latency for citation display
151
-
- Frontend can start rendering citations while content is still streaming
152
-
- No waiting for the complete response
153
-
154
-
### Backward Compatibility
155
-
156
-
The implementation maintains full backward compatibility:
158
+
### Citation Filtering
157
159
158
-
- Existing markdown/HTML citation display continues to work
159
-
- No breaking changes to the API
160
-
- Both citation modes can be enabled simultaneously
161
-
- Default configuration enables both modes
160
+
Citations are filtered to only show documents that are actually referenced in the response content. For example, if Azure returns 5 citations but the response only references `[doc1]` and `[doc3]`, only those 2 citations will appear in the UI.
162
161
163
162
## Troubleshooting
164
163
@@ -167,34 +166,37 @@ The implementation maintains full backward compatibility:
167
166
**Problem**: Citations don't appear in the OpenWebUI frontend
168
167
169
168
**Solutions**:
170
-
1.Verify `AZURE_AI_OPENWEBUI_CITATIONS=true`is set
171
-
2.Check that Azure AI Search is properly configured (`AZURE_AI_DATA_SOURCES`)
172
-
3.Ensure you're using an Azure OpenAI endpoint (not a generic Azure AI endpoint)
173
-
4. Check browser console for errors
169
+
1.Check that Azure AI Search is properly configured (`AZURE_AI_DATA_SOURCES`)
170
+
2.Ensure you're using an Azure OpenAI endpoint (not a generic Azure AI endpoint)
171
+
3.Verify the response contains `[docX]` references
172
+
4. Check browser console and server logs for errors
174
173
175
-
### Citation Cards vs. Markdown Section
174
+
### Relevance Scores Showing 0%
176
175
177
-
**Problem**: Seeing both citation cards and markdown section
176
+
**Problem**: All citation cards show 0% relevance
178
177
179
-
**Solution**: This is the default behavior. To show only citation cards:
180
-
```bash
181
-
AZURE_AI_OPENWEBUI_CITATIONS=true
182
-
AZURE_AI_ENHANCE_CITATIONS=false
183
-
```
178
+
**Solutions**:
179
+
1. Verify `AZURE_AI_INCLUDE_SEARCH_SCORES=true` is set
180
+
2. Check that your Azure Search index supports scoring
181
+
3. Enable DEBUG logging to see the raw score values from Azure
184
182
185
-
### Missing Citation Metadata
183
+
### Links Not Working
186
184
187
-
**Problem**: Some citation fields (URL, filepath, score) are missing
185
+
**Problem**: `[docX]` references are not clickable
188
186
189
-
**Solution**: These fields are optional. Azure AI Search may not return all fields depending on your index configuration. The pipeline gracefully handles missing fields.
187
+
**Solutions**:
188
+
1. Ensure citations have valid `url` or `filepath` fields
189
+
2. Check that the document URL is accessible
190
+
3. Verify the markdown link format is being generated correctly
-[Azure AI Search Documentation](https://learn.microsoft.com/en-us/azure/search/)
197
+
-[Azure On Your Data API Reference](https://learn.microsoft.com/en-us/azure/ai-foundry/openai/references/on-your-data)
196
198
197
199
## Version History
198
200
199
-
-**v2.6.0**: Added native OpenWebUI citations support
200
-
-**v2.5.x**: Markdown/HTML citation display only
201
+
-**v2.6.0**: Major refactor - removed `AZURE_AI_ENHANCE_CITATIONS` and `AZURE_AI_OPENWEBUI_CITATIONS` valves; citation support is now always enabled when `AZURE_AI_DATA_SOURCES` is configured; added clickable `[docX]` markdown links; improved score extraction using `filter_reason` field
# Enable enhanced citation display for better readability (default: true)
64
-
AZURE_AI_ENHANCE_CITATIONS=true
63
+
# Enable relevance score extraction from Azure Search (default: true)
64
+
# When enabled, automatically adds include_contexts to get original_search_score and rerank_score
65
+
AZURE_AI_INCLUDE_SEARCH_SCORES=true
65
66
```
66
67
67
68
### Azure AI Search / RAG Integration
@@ -155,73 +156,40 @@ For advanced use cases, you can include additional parameters:
155
156
-**Missing API key**: Ensure your Azure Search API key has proper permissions
156
157
-**Index not found**: Verify your index name matches exactly (case-sensitive)
157
158
158
-
#### Enhanced Citation Display
159
+
#### Native OpenWebUI Citation Support
159
160
160
-
The pipeline automatically enhances Azure AI Search responses to make citations and source documents more accessible and readable. When Azure AI Search is configured, the pipeline transforms the raw citation data into a user-friendly format.
161
+
The pipeline automatically provides native OpenWebUI citation support for Azure AI Search responses. When Azure AI Search is configured, the pipeline:
161
162
162
-
**Original Azure AI Response:**
163
+
1.**Emits citation events** via `__event_emitter__` for the OpenWebUI frontend to display interactive citation cards
164
+
2.**Converts `[docX]` references** to clickable markdown links that link directly to document URLs
165
+
3.**Extracts relevance scores** when `AZURE_AI_INCLUDE_SEARCH_SCORES=true`
166
+
4.**Filters citations** to only show documents actually referenced in the response
163
167
164
-
```json
165
-
{
166
-
"choices": [
167
-
{
168
-
"message": {
169
-
"content": "**Docker container actions** are a type of GitHub Actions [doc1]...",
170
-
"context": {
171
-
"citations": [
172
-
{
173
-
"content": "environment variable. The token can be used to authenticate...",
174
-
"title": "README.md",
175
-
"chunk_id": "0"
176
-
}
177
-
]
178
-
}
179
-
}
180
-
}
181
-
]
182
-
}
183
-
```
184
-
185
-
**Enhanced Response with Collapsible Citations:**
168
+
**Example: Clickable Document Links**
186
169
187
-
```html
170
+
```markdown
171
+
# Original Azure AI response
188
172
**Docker container actions** are a type of GitHub Actions [doc1]...
189
173
190
-
<details>
191
-
<summary>📚 Sources and References</summary>
192
-
193
-
<details>
194
-
<summary>[doc1] - README.md</summary>
195
-
196
-
📁 **File:** `README.md`
197
-
📄 **Chunk ID:** 0
198
-
**Content:**
199
-
> environment variable. The token can be used to authenticate the workflow when accessing GitHub resources...
200
-
201
-
</details>
202
-
203
-
<details>
204
-
<summary>[doc2] - Documentation.md</summary>
174
+
# Enhanced response (with clickable links)
175
+
**Docker container actions** are a type of GitHub Actions [[doc1]](https://example.com/README.md)...
176
+
```
205
177
206
-
📁 **File:** `Documentation.md`
207
-
📄 **Chunk ID:** 1
208
-
**Content:**
209
-
> Docker container actions contain all their dependencies in the container and are therefore very consistent...
178
+
**Citation Card Features:**
210
179
211
-
</details>
180
+
-**Source information** with `[docX]` prefix for easy identification
181
+
-**Relevance percentage** displayed on citation cards (requires `AZURE_AI_INCLUDE_SEARCH_SCORES=true`)
182
+
-**Document preview** with content snippets
183
+
-**Clickable links** to source documents when URLs are available
184
+
-**Streaming support** with links converted inline as content streams
212
185
213
-
</details>
214
-
```
186
+
**Relevance Score Selection:**
215
187
216
-
**Enhanced Citation Features:**
188
+
The pipeline uses the `filter_reason` field from Azure Search to select the appropriate score:
189
+
-`filter_reason="rerank"` → uses `rerank_score`
190
+
-`filter_reason="score"` or not present → uses `original_search_score`
217
191
218
-
-**Collapsible interface** with expandable sections for clean presentation
219
-
-**Two-level organization** - main sources section and individual document details
220
-
-**Complete content display** - full document content, not just previews
221
-
-**Document references** with clear [doc1], [doc2] labels for easy cross-referencing
222
-
-**Source metadata** including file paths, URLs, and chunk IDs for precise tracking
223
-
-**Streaming support** with citations properly formatted for both streaming and non-streaming responses
224
-
-**Space efficient** - collapsed by default to avoid overwhelming the main response
192
+
For more details, see the [Azure AI Citations Documentation](azure-ai-citations.md).
225
193
226
194
> [!TIP]
227
195
> To use **Azure OpenAI** and other **Azure AI** models **simultaneously**, you can use the following URL: `https://<your project>.services.ai.azure.com/models/chat/completions?api-version=2024-05-01-preview`
0 commit comments