Skip to content

Commit 0f29910

Browse files
authored
Merge pull request #950 from MicrosoftDocs/main
10/22 11:00 AM IST Publish
2 parents bf31bc8 + 7660708 commit 0f29910

37 files changed

+488
-229
lines changed

.openpublishing.redirection.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
"source_path_from_root": "/articles/ai-services/openai/concepts/use-your-image-data.md",
55
"redirect_url": "/azure/ai-services/openai/concepts/use-your-data",
66
"redirect_document_id": true
7+
},
8+
{
9+
"source_path_from_root": "/articles/search/search-howto-create-indexers.md",
10+
"redirect_url": "/azure/search/search-how-to-create-indexers",
11+
"redirect_document_id": false
712
}
813
]
914
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
title: 'Prompt caching with Azure OpenAI Service'
3+
titleSuffix: Azure OpenAI
4+
description: Learn how to use prompt caching with Azure OpenAI
5+
services: cognitive-services
6+
manager: nitinme
7+
ms.service: azure-ai-openai
8+
ms.topic: how-to
9+
ms.date: 10/18/2024
10+
author: mrbullwinkle
11+
ms.author: mbullwin
12+
recommendations: false
13+
---
14+
15+
# Prompt caching
16+
17+
Prompt caching allows you to reduce overall request latency and cost for longer prompts that have identical content at the beginning of the prompt. *"Prompt"* in this context is referring to the input you send to the model as part of your chat completions request. Rather than reprocess the same input tokens over and over again, the model is able to retain a temporary cache of processed input data to improve overall performance. Prompt caching has no impact on the output content returned in the model response beyond a reduction in latency and cost.
18+
19+
## Supported models
20+
21+
Currently only the following models support prompt caching with Azure OpenAI:
22+
23+
- `o1-preview-2024-09-12`
24+
- `o1-mini-2024-09-12`
25+
26+
## API support
27+
28+
Official support for prompt caching was first added in API version `2024-10-01-preview`.
29+
30+
## Getting started
31+
32+
For a request to take advantage of prompt caching the request must be both:
33+
34+
- A minimum of 1,024 tokens in length.
35+
- The first 1,024 tokens in the prompt must be identical.
36+
37+
When a match is found between a prompt and the current content of the prompt cache, it's referred to as a cache hit. Cache hits will show up as [`cached_tokens`](/azure/ai-services/openai/reference-preview#cached_tokens) under [`prompt_token_details`](/azure/ai-services/openai/reference-preview#properties-for-prompt_tokens_details) in the chat completions response.
38+
39+
```json
40+
{
41+
"created": 1729227448,
42+
"model": "o1-preview-2024-09-12",
43+
"object": "chat.completion",
44+
"service_tier": null,
45+
"system_fingerprint": "fp_50cdd5dc04",
46+
"usage": {
47+
"completion_tokens": 1518,
48+
"prompt_tokens": 1566,
49+
"total_tokens": 3084,
50+
"completion_tokens_details": {
51+
"audio_tokens": null,
52+
"reasoning_tokens": 576
53+
},
54+
"prompt_tokens_details": {
55+
"audio_tokens": null,
56+
"cached_tokens": 1408
57+
}
58+
}
59+
}
60+
```
61+
62+
After the first 1,024 tokens cache hits will occur for every 128 additional identical tokens.
63+
64+
A single character difference in the first 1,024 tokens will result in a cache miss which is characterized by a `cached_tokens` value of 0. Prompt caching is enabled by default with no additional configuration needed for supported models.
65+
66+
## What is cached?
67+
68+
The o1-series models are text only and don't support system messages, images, tool use/function calling, or structured outputs. This limits the efficacy of prompt caching for these models to the user/assistant portions of the messages array which are less likely to have an identical 1024 token prefix.
69+
70+
Once prompt caching is enabled for other supported models prompt caching will expand to support:
71+
72+
| **Caching Supported** | **Description** |
73+
|--------|--------|
74+
|**Messages** | The complete messages array: system, user, and assistant content |
75+
|**Images** | Images included in user messages, both as links or as base64-encoded data. The detail parameter must be set the same across requests.
76+
|**Tool use**| Both the messages array and tool definitions |
77+
|**Structured outputs** | Structured output schema is appended as a prefix to the system message|
78+
79+
To improve the likelihood of cache hits occurring, you should structure your requests such that repetitive content occurs at the beginning of the messages array.
80+
81+
## Can I disable prompt caching?
82+
83+
Prompt caching is enabled by default. There is no opt-out option.

articles/ai-services/openai/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ items:
130130
href: ./how-to/completions.md
131131
- name: JSON mode
132132
href: ./how-to/json-mode.md
133+
- name: Prompt caching
134+
href: ./how-to/prompt-caching.md
133135
- name: Reproducible output
134136
href: ./how-to/reproducible-output.md
135137
- name: Structured outputs

articles/ai-services/speech-service/how-to-recognize-speech.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ author: eric-urban
66
manager: nitinme
77
ms.service: azure-ai-speech
88
ms.topic: how-to
9-
ms.date: 9/20/2024
9+
ms.date: 10/17/2024
1010
ms.author: eur
1111
ms.devlang: cpp
1212
ms.custom: devx-track-extended-java, devx-track-go, devx-track-js, devx-track-python

articles/ai-services/speech-service/includes/how-to/recognize-speech/cpp.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
author: eric-urban
33
ms.service: azure-ai-speech
44
ms.topic: include
5-
ms.date: 08/13/2024
5+
ms.date: 10/17/2024
66
ms.author: eur
77
---
88

@@ -215,3 +215,24 @@ auto speechRecognizer = SpeechRecognizer::FromConfig(speechConfig);
215215
Speech containers provide websocket-based query endpoint APIs that are accessed through the Speech SDK and Speech CLI. By default, the Speech SDK and Speech CLI use the public Speech service. To use the container, you need to change the initialization method. Use a container host URL instead of key and region.
216216

217217
For more information about containers, see Host URLs in [Install and run Speech containers with Docker](../../../speech-container-howto.md#host-urls).
218+
219+
220+
## Semantic segmentation
221+
222+
Semantic segmentation is a speech recognition segmentation strategy that's designed to mitigate issues associated with silence-based segmentation:
223+
- Under-segmentation: When users speak for a long time without pauses, they can see a long sequence of text without breaks ("wall of text"), which severely degrades their readability experience.
224+
- Over-segmentation: When a user pauses for a short time, the silence detection mechanism can segment incorrectly.
225+
226+
Instead of relying on silence timeouts, semantic segmentation segments and returns final results when it detects sentence-ending punctuation (such as '.' or '?'). This improves the user experience with higher-quality, semantically complete segments and prevents long intermediate results.
227+
228+
To use semantic segmentation, you need to set the following property on the `SpeechConfig` instance used to create a `SpeechRecognizer`:
229+
230+
```cpp
231+
speechConfig->SetProperty(PropertyId::Speech_SegmentationStrategy, "Semantic");
232+
```
233+
234+
Some of the limitations of semantic segmentation are as follows:
235+
- You need the Speech SDK version 1.41 or later to use semantic segmentation.
236+
- Semantic segmentation is only intended for use in [continuous recognition](#continuous-recognition). This includes scenarios such as transcription and captioning. It shouldn't be used in the single recognition and dictation mode.
237+
- Semantic segmentation isn't available for all languages and locales. Currently, semantic segmentation is only available for English (en) locales such as en-US, en-GB, en-IN, and en-AU.
238+
- Semantic segmentation doesn't yet support confidence scores and NBest lists. As such, we don't recommend semantic segmentation if you're using confidence scores or NBest lists.

articles/ai-services/speech-service/includes/how-to/recognize-speech/csharp.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
author: eric-urban
33
ms.service: azure-ai-speech
44
ms.topic: include
5-
ms.date: 08/13/2024
5+
ms.date: 10/17/2024
66
ms.author: eur
77
ms.custom: devx-track-csharp
88
---
@@ -330,3 +330,23 @@ speechConfig.SetProperty(PropertyId.Speech_SegmentationSilenceTimeoutMs, "300");
330330
```csharp
331331
speechConfig.SetProperty(PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs, "10000");
332332
```
333+
334+
## Semantic segmentation
335+
336+
Semantic segmentation is a speech recognition segmentation strategy that's designed to mitigate issues associated with [silence-based segmentation](#change-how-silence-is-handled):
337+
- Under-segmentation: When users speak for a long time without pauses, they can see a long sequence of text without breaks ("wall of text"), which severely degrades their readability experience.
338+
- Over-segmentation: When a user pauses for a short time, the silence detection mechanism can segment incorrectly.
339+
340+
Instead of relying on silence timeouts, semantic segmentation segments and returns final results when it detects sentence-ending punctuation (such as '.' or '?'). This improves the user experience with higher-quality, semantically complete segments and prevents long intermediate results.
341+
342+
To use semantic segmentation, you need to set the following property on the `SpeechConfig` instance used to create a `SpeechRecognizer`:
343+
344+
```csharp
345+
speechConfig.SetProperty(PropertyId.Speech_SegmentationStrategy, "Semantic");
346+
```
347+
348+
Some of the limitations of semantic segmentation are as follows:
349+
- You need the Speech SDK version 1.41 or later to use semantic segmentation.
350+
- Semantic segmentation is only intended for use in [continuous recognition](#use-continuous-recognition). This includes scenarios such as transcription and captioning. It shouldn't be used in the single recognition and dictation mode.
351+
- Semantic segmentation isn't available for all languages and locales. Currently, semantic segmentation is only available for English (en) locales such as en-US, en-GB, en-IN, and en-AU.
352+
- Semantic segmentation doesn't yet support confidence scores and NBest lists. As such, we don't recommend semantic segmentation if you're using confidence scores or NBest lists.

articles/ai-services/speech-service/includes/how-to/recognize-speech/java.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
author: eric-urban
33
ms.service: azure-ai-speech
44
ms.topic: include
5-
ms.date: 08/13/2024
5+
ms.date: 10/17/2024
66
ms.custom: devx-track-java
77
ms.author: eur
88
---
@@ -233,3 +233,23 @@ SpeechRecognizer speechRecognizer = new SpeechRecognizer(speechConfig);
233233
Speech containers provide websocket-based query endpoint APIs that are accessed through the Speech SDK and Speech CLI. By default, the Speech SDK and Speech CLI use the public Speech service. To use the container, you need to change the initialization method. Use a container host URL instead of key and region.
234234

235235
For more information about containers, see Host URLs in [Install and run Speech containers with Docker](../../../speech-container-howto.md#host-urls).
236+
237+
## Semantic segmentation
238+
239+
Semantic segmentation is a speech recognition segmentation strategy that's designed to mitigate issues associated with silence-based segmentation:
240+
- Under-segmentation: When users speak for a long time without pauses, they can see a long sequence of text without breaks ("wall of text"), which severely degrades their readability experience.
241+
- Over-segmentation: When a user pauses for a short time, the silence detection mechanism can segment incorrectly.
242+
243+
Instead of relying on silence timeouts, semantic segmentation segments and returns final results when it detects sentence-ending punctuation (such as '.' or '?'). This improves the user experience with higher-quality, semantically complete segments and prevents long intermediate results.
244+
245+
To use semantic segmentation, you need to set the following property on the `SpeechConfig` instance used to create a `SpeechRecognizer`:
246+
247+
```java
248+
speechConfig.SetProperty(PropertyId.Speech_SegmentationStrategy, "Semantic");
249+
```
250+
251+
Some of the limitations of semantic segmentation are as follows:
252+
- You need the Speech SDK version 1.41 or later to use semantic segmentation.
253+
- Semantic segmentation is only intended for use in [continuous recognition](#use-continuous-recognition). This includes scenarios such as transcription and captioning. It shouldn't be used in the single recognition and dictation mode.
254+
- Semantic segmentation isn't available for all languages and locales. Currently, semantic segmentation is only available for English (en) locales such as en-US, en-GB, en-IN, and en-AU.
255+
- Semantic segmentation doesn't yet support confidence scores and NBest lists. As such, we don't recommend semantic segmentation if you're using confidence scores or NBest lists.

articles/ai-services/speech-service/includes/how-to/recognize-speech/python.md

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
author: eric-urban
33
ms.service: azure-ai-speech
44
ms.topic: include
5-
ms.date: 08/13/2024
5+
ms.date: 10/17/2024
66
ms.author: eur
77
---
88

@@ -180,3 +180,24 @@ speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
180180
Speech containers provide websocket-based query endpoint APIs that are accessed through the Speech SDK and Speech CLI. By default, the Speech SDK and Speech CLI use the public Speech service. To use the container, you need to change the initialization method. Use a container host URL instead of key and region.
181181

182182
For more information about containers, see Host URLs in [Install and run Speech containers with Docker](../../../speech-container-howto.md#host-urls).
183+
184+
185+
## Semantic segmentation
186+
187+
Semantic segmentation is a speech recognition segmentation strategy that's designed to mitigate issues associated with silence-based segmentation:
188+
- Under-segmentation: When users speak for a long time without pauses, they can see a long sequence of text without breaks ("wall of text"), which severely degrades their readability experience.
189+
- Over-segmentation: When a user pauses for a short time, the silence detection mechanism can segment incorrectly.
190+
191+
Instead of relying on silence timeouts, semantic segmentation segments and returns final results when it detects sentence-ending punctuation (such as '.' or '?'). This improves the user experience with higher-quality, semantically complete segments and prevents long intermediate results.
192+
193+
To use semantic segmentation, you need to set the following property on the `SpeechConfig` instance used to create a `SpeechRecognizer`:
194+
195+
```python
196+
speech_config.set_property(speechsdk.PropertyId.Speech_SegmentationStrategy, "Semantic")
197+
```
198+
199+
Some of the limitations of semantic segmentation are as follows:
200+
- You need the Speech SDK version 1.41 or later to use semantic segmentation.
201+
- Semantic segmentation is only intended for use in [continuous recognition](#use-continuous-recognition). This includes scenarios such as transcription and captioning. It shouldn't be used in the single recognition and dictation mode.
202+
- Semantic segmentation isn't available for all languages and locales. Currently, semantic segmentation is only available for English (en) locales such as en-US, en-GB, en-IN, and en-AU.
203+
- Semantic segmentation doesn't yet support confidence scores and NBest lists. As such, we don't recommend semantic segmentation if you're using confidence scores or NBest lists.

articles/ai-services/speech-service/includes/quickstarts/keyword-recognition/swift.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ ms.author: eur
2121
## Use a keyword model with the Speech SDK
2222

2323
See the [sample on GitHub](https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/b4257370e1d799f0b8b64be9bf2a34cad8b1a251/samples/objective-c/ios/speech-samples/speech-samples/ViewController.m#L585) for using your Custom Keyword model with the Objective C SDK. Although we don't currently have a Swift sample for parity, the concepts are similar.
24+
25+
> [!NOTE]
26+
> If you are going to use keyword recognition in your Swift application on iOS, note that new keyword models created in Speech Studio will require using either the Speech SDK xcframework bundle from [https://aka.ms/csspeech/iosbinaryembedded](https://aka.ms/csspeech/iosbinaryembedded) or the `MicrosoftCognitiveServicesSpeechEmbedded-iOS` pod in your project.

articles/ai-services/speech-service/includes/quickstarts/platform/cpp-requirements.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ The Speech SDK for C++ only supports the following distributions on the x64, ARM
2121

2222
- Ubuntu 20.04/22.04/24.04
2323
- Debian 11/12
24+
- Amazon Linux 2023
25+
- Azure Linux 3.0
2426

2527
[!INCLUDE [Linux distributions](linux-distributions.md)]
2628

0 commit comments

Comments
 (0)