Skip to content

Commit b4b882b

Browse files
Copilotowndev
andcommitted
Update Azure AI documentation to reflect citation changes
Co-authored-by: owndev <69784886+owndev@users.noreply.github.com>
1 parent 99920c5 commit b4b882b

2 files changed

Lines changed: 99 additions & 129 deletions

File tree

docs/azure-ai-citations.md

Lines changed: 73 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,31 @@ This document describes the native OpenWebUI citation support in the Azure AI Fo
44

55
## Overview
66

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:
88

99
- **Citation cards** with source information and relevance scores
1010
- **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
1314

1415
## Features
1516

16-
### Dual Citation Modes
17+
### Automatic Citation Support
1718

18-
The pipeline supports two modes for displaying citations:
19+
When Azure AI Search is configured, the pipeline automatically:
1920

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
2425

2526
### Configuration Options
2627

2728
| Environment Variable | Default | Description |
2829
|---------------------|---------|-------------|
29-
| `AZURE_AI_OPENWEBUI_CITATIONS` | `true` | Enable native OpenWebUI citation events |
30-
| `AZURE_AI_ENHANCE_CITATIONS` | `true` | Enable markdown/HTML citation display (collapsible sections) |
30+
| `AZURE_AI_DATA_SOURCES` | `""` | JSON configuration for Azure AI Search (required for citations) |
31+
| `AZURE_AI_INCLUDE_SEARCH_SCORES` | `true` | Enable relevance score extraction from Azure Search |
3132

3233
### How It Works
3334

@@ -36,16 +37,17 @@ Both modes can be enabled simultaneously or independently via configuration.
3637
When Azure AI Search returns citations in a streaming response:
3738

3839
1. The pipeline detects citations in the SSE (Server-Sent Events) stream
39-
2. **If `AZURE_AI_OPENWEBUI_CITATIONS` is enabled**: Citation events are emitted immediately via `__event_emitter__`
40-
3. **If `AZURE_AI_ENHANCE_CITATIONS` is enabled**: A formatted markdown/HTML citation section is appended at the end of the stream
40+
2. `[docX]` references in each chunk are converted to markdown links with document URLs
41+
3. After the stream ends, citation events are emitted via `__event_emitter__`
42+
4. Citations are filtered to only include documents referenced in the response
4143

4244
#### Non-Streaming Responses
4345

4446
When Azure AI Search returns citations in a non-streaming response:
4547

46-
1. The pipeline extracts citations from the response
47-
2. **If `AZURE_AI_OPENWEBUI_CITATIONS` is enabled**: Individual citation events are emitted via `__event_emitter__` for each source
48-
3. **If `AZURE_AI_ENHANCE_CITATIONS` is enabled**: The response content is enhanced with a formatted citation section
48+
1. The pipeline extracts citations from the response context
49+
2. `[docX]` references in the content are converted to markdown links
50+
3. Individual citation events are emitted via `__event_emitter__` for each referenced source
4951

5052
## Citation Format
5153

@@ -91,74 +93,71 @@ Azure AI Search returns citations in this format:
9193

9294
The pipeline automatically converts Azure citations to OpenWebUI format.
9395

94-
## Usage Examples
96+
## Usage
9597

96-
### Basic Setup with Native Citations
98+
### Basic Setup
9799

98-
```python
99-
# Enable native OpenWebUI citations (default)
100-
AZURE_AI_OPENWEBUI_CITATIONS=true
100+
Configure Azure AI Search to enable citation support:
101101

102-
# Optionally disable markdown/HTML citations if you only want native citations
103-
AZURE_AI_ENHANCE_CITATIONS=false
102+
```bash
103+
# Azure AI Search configuration (required for citations)
104+
AZURE_AI_DATA_SOURCES='[{"type":"azure_search","parameters":{"endpoint":"https://YOUR-SEARCH-SERVICE.search.windows.net","index_name":"YOUR-INDEX-NAME","authentication":{"type":"api_key","key":"YOUR-SEARCH-API-KEY"}}}]'
105+
106+
# Enable relevance scores (default: true)
107+
AZURE_AI_INCLUDE_SEARCH_SCORES=true
104108
```
105109

106-
### Both Citation Modes Enabled (Default)
110+
### Clickable Document Links
107111

108-
```python
109-
# 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).
112120
```
113121

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.
117123

118-
### Only Markdown/HTML Citations (Legacy)
124+
### Relevance Scores
119125

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
125133

126134
## Implementation Details
127135

128136
### Helper Functions
129137

130-
The pipeline includes three new helper functions:
138+
The pipeline includes these helper functions for citation processing:
131139

132140
1. **`_extract_citations_from_response()`**: Extracts citations from Azure responses
133141
2. **`_normalize_citation_for_openwebui()`**: Converts Azure citations to OpenWebUI format
134142
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
135147

136148
### Title Fallback Logic
137149

138150
The pipeline uses intelligent title fallback:
139151

140152
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
144155

145156
This ensures every citation has a meaningful display name.
146157

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
157159

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.
162161

163162
## Troubleshooting
164163

@@ -167,34 +166,37 @@ The implementation maintains full backward compatibility:
167166
**Problem**: Citations don't appear in the OpenWebUI frontend
168167

169168
**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
174173

175-
### Citation Cards vs. Markdown Section
174+
### Relevance Scores Showing 0%
176175

177-
**Problem**: Seeing both citation cards and markdown section
176+
**Problem**: All citation cards show 0% relevance
178177

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
184182

185-
### Missing Citation Metadata
183+
### Links Not Working
186184

187-
**Problem**: Some citation fields (URL, filepath, score) are missing
185+
**Problem**: `[docX]` references are not clickable
188186

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
190191

191192
## References
192193

193194
- [OpenWebUI Pipelines Citation Feature Discussion](https://github.com/open-webui/pipelines/issues/229)
194195
- [OpenWebUI Event Emitter Documentation](https://docs.openwebui.com/features/plugin/development/events)
195196
- [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)
196198

197199
## Version History
198200

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
202+
- **v2.5.x**: Dual citation modes (OpenWebUI events + markdown/HTML)

docs/azure-ai-integration.md

Lines changed: 26 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ AZURE_AI_ENDPOINT="https://<deployment>.openai.azure.com/openai/deployments/<mod
6060
# Complete JSON configuration for Azure Search - copy exactly and replace placeholder values
6161
AZURE_AI_DATA_SOURCES='[{"type":"azure_search","parameters":{"endpoint":"https://<your-search-service>.search.windows.net","index_name":"<your-index-name>","authentication":{"type":"api_key","key":"<your-search-api-key>"}}}]'
6262

63-
# 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
6566
```
6667

6768
### Azure AI Search / RAG Integration
@@ -155,73 +156,40 @@ For advanced use cases, you can include additional parameters:
155156
- **Missing API key**: Ensure your Azure Search API key has proper permissions
156157
- **Index not found**: Verify your index name matches exactly (case-sensitive)
157158

158-
#### Enhanced Citation Display
159+
#### Native OpenWebUI Citation Support
159160

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:
161162

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
163167

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**
186169

187-
```html
170+
```markdown
171+
# Original Azure AI response
188172
**Docker container actions** are a type of GitHub Actions [doc1]...
189173

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+
```
205177

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:**
210179

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
212185

213-
</details>
214-
```
186+
**Relevance Score Selection:**
215187

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`
217191

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).
225193

226194
> [!TIP]
227195
> 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

Comments
 (0)