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
# Use the current user identity to authenticate with Azure OpenAI, Cognitive Search and Blob Storage (no secrets needed,
224
+
# Use the current user identity to authenticate with Azure OpenAI, AI Search and Blob Storage (no secrets needed,
225
225
# just use 'az login' locally, and managed identity when deployed on Azure). If you need to use keys, use separate AzureKeyCredential instances with the
226
226
# keys for each service
227
227
# If you encounter a blocking error during a DefaultAzureCredential resolution, you can exclude the problematic credential by using a parameter (ex. exclude_shared_token_cache_credential=True)
Copy file name to clipboardExpand all lines: app/backend/approaches/chatreadretrieveread.py
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -23,9 +23,9 @@ class ChatReadRetrieveReadApproach(Approach):
23
23
NO_RESPONSE="0"
24
24
25
25
"""
26
-
Simple retrieve-then-read implementation, using the Cognitive Search and OpenAI APIs directly. It first retrieves
27
-
top documents from search, then constructs a prompt with them, and then uses OpenAI to generate an completion
28
-
(answer) with that prompt.
26
+
A multi-step approach that first uses OpenAI to turn the user's question into a search query,
27
+
then uses Azure AI Search to retrieve relevant documents, and then sends the conversation history,
28
+
original user question, and search results to OpenAI to generate a response.
29
29
"""
30
30
system_message_chat_conversation="""Assistant helps the company employees with their healthcare plan questions, and questions about the employee handbook. Be brief in your answers.
31
31
Answer ONLY with the facts listed in the list of sources below. If there isn't enough information below, say you don't know. Do not generate answers that don't use the sources below. If asking a clarifying question to the user would help, ask the question.
@@ -43,7 +43,7 @@ class ChatReadRetrieveReadApproach(Approach):
43
43
Make sure the last question ends with ">>"."""
44
44
45
45
query_prompt_template="""Below is a history of the conversation so far, and a new question asked by the user that needs to be answered by searching in a knowledge base about employee healthcare plans and the employee handbook.
46
-
You have access to Azure Cognitive Search index with 100's of documents.
46
+
You have access to an Azure AI Search index with 100's of documents.
47
47
Generate a search query based on the conversation and the new question.
48
48
Do not include cited source filenames and document names e.g info.txt or doc.pdf in the search query terms.
49
49
Do not include any text inside [] or <<>> in the search query terms.
Copy file name to clipboardExpand all lines: docs/customization.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,18 +27,18 @@ Typically, the primary backend code you'll want to customize is the `app/backend
27
27
28
28
The chat tab uses the approach programmed in [chatreadretrieveread.py](https://github.com/Azure-Samples/azure-search-openai-demo/blob/main/app/backend/approaches/chatreadretrieveread.py).
29
29
30
-
1. It uses the ChatGPT API to turn the user question into a good search query.
31
-
2. It queries Azure Cognitive Search for search results for that query (optionally using the vector embeddings for that query).
32
-
3. It then combines the search results and original user question, and asks ChatGPT API to answer the question based on the sources. It includes the last 4K of message history as well (or however many tokens are allowed by the deployed model).
30
+
1. It uses the OpenAI ChatCompletion API to turn the user question into a good search query.
31
+
2. It queries Azure AI Search for search results for that query (optionally using the vector embeddings for that query).
32
+
3. It then combines the search results and original user question, and asks OpenAI ChatCompletion API to answer the question based on the sources. It includes the last 4K of message history as well (or however many tokens are allowed by the deployed model).
33
33
34
34
The `system_message_chat_conversation` variable is currently tailored to the sample data since it starts with "Assistant helps the company employees with their healthcare plan questions, and questions about the employee handbook." Change that to match your data.
35
35
36
36
#### Ask approach
37
37
38
38
The ask tab uses the approach programmed in [retrievethenread.py](https://github.com/Azure-Samples/azure-search-openai-demo/blob/main/app/backend/approaches/retrievethenread.py).
39
39
40
-
1. It queries Azure Cognitive Search for search results for the user question (optionally using the vector embeddings for that question).
41
-
2. It then combines the search results and user question, and asks ChatGPT API to answer the question based on the sources.
40
+
1. It queries Azure AI Search for search results for the user question (optionally using the vector embeddings for that question).
41
+
2. It then combines the search results and user question, and asks OpenAI ChatCompletion API to answer the question based on the sources.
42
42
43
43
The `system_chat_template` variable is currently tailored to the sample data since it starts with "You are an intelligent assistant helping Contoso Inc employees with their healthcare plan questions and employee handbook questions." Change that to match your data.
44
44
@@ -79,24 +79,24 @@ If you notice any answers that aren't as good as you'd like, here's a process fo
79
79
80
80
The first step is to identify where the problem is occurring. For example, if using the Chat tab, the problem could be:
81
81
82
-
1.ChatGPT is not generating a good search query based on the user question
83
-
2. Azure Cognitive Search is not returning good search results for the query
84
-
3.ChatGPT is not generating a good answer based on the search results and user question
82
+
1.OpenAI ChatCompletion API is not generating a good search query based on the user question
83
+
2. Azure AI Search is not returning good search results for the query
84
+
3.OpenAI ChatCompletion API is not generating a good answer based on the search results and user question
85
85
86
86
You can look at the "Thought process" tab in the chat app to see each of those steps,
87
87
and determine which one is the problem.
88
88
89
-
#### Improving ChatGPT results
89
+
#### Improving OpenAI ChatCompletion results
90
90
91
-
If the problem is with ChatGPT (steps 1 or 3 above), you can try changing the relevant prompt.
91
+
If the problem is with the ChatCompletion API calls (steps 1 or 3 above), you can try changing the relevant prompt.
92
92
93
-
Once you've changed the prompt, make sure you ask the same question multiple times to see if the overall quality has improved. ChatGPT can yield different results every time, even for a temperature of 0.0, but especially for a higher temperature than that (like our default of 0.7 for step 3).
93
+
Once you've changed the prompt, make sure you ask the same question multiple times to see if the overall quality has improved. The ChatCompletion API can yield different results every time, even for a temperature of 0.0, but especially for a higher temperature than that (like our default of 0.7 for step 3).
94
94
95
-
You can also try changing the ChatGPT parameters, like temperature, to see if that improves results for your domain.
95
+
You can also try changing the ChatCompletion parameters, like temperature, to see if that improves results for your domain.
96
96
97
-
#### Improving Azure Cognitive Search results
97
+
#### Improving Azure AI Search results
98
98
99
-
If the problem is with Azure Cognitive Search (step 2 above), the first step is to check what search parameters you're using. Generally, the best results are found with hybrid search (text + vectors) plus the additional semantic re-ranking step, and that's what we've enabled by default. There may be some domains where that combination isn't optimal, however.
99
+
If the problem is with Azure AI Search (step 2 above), the first step is to check what search parameters you're using. Generally, the best results are found with hybrid search (text + vectors) plus the additional semantic re-ranking step, and that's what we've enabled by default. There may be some domains where that combination isn't optimal, however.
100
100
101
101
##### Configuring parameters in the app
102
102
@@ -107,7 +107,7 @@ You can change many of the search parameters in the "Developer settings" in the
107
107
#### Configuring parameters in the Azure Portal
108
108
109
109
You may find it easier to experiment with search options with the index explorer in the Azure Portal.
110
-
Open up the Azure Cognitive Search resource, select the Indexes tab, and select the index there.
110
+
Open up the Azure AI Search resource, select the Indexes tab, and select the index there.
111
111
112
112
Then use the JSON view of the search explorer, and make sure you specify the same options you're using in the app. For example, this query represents a search with semantic ranker configured:
Copy file name to clipboardExpand all lines: docs/data_ingestion.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,14 +10,14 @@ The `scripts/prepdocs.py` script is responsible for both uploading and indexing
10
10
11
11
The script uses the following steps to index documents:
12
12
13
-
1. If it doesn't yet exist, create a new index in Azure Cognitive Search.
13
+
1. If it doesn't yet exist, create a new index in Azure AI Search.
14
14
2. Upload the PDFs to Azure Blob Storage.
15
15
3. Split the PDFs into chunks of text.
16
-
4. Upload the chunks to Azure Cognitive Search. If using vectors (the default), also compute the embeddings and upload those alongside the text.
16
+
4. Upload the chunks to Azure AI Search. If using vectors (the default), also compute the embeddings and upload those alongside the text.
17
17
18
18
### Chunking
19
19
20
-
We're often asked why we need to break up the PDFs into chunks when Azure Cognitive Search supports searching large documents.
20
+
We're often asked why we need to break up the PDFs into chunks when Azure AI Search supports searching large documents.
21
21
22
22
Chunking allows us to limit the amount of information we send to OpenAI due to token limits. By breaking up the content, it allows us to easily find potential chunks of text that we can inject into OpenAI. The method of chunking we use leverages a sliding window of text such that sentences that end one chunk will start the next. This allows us to reduce the chance of losing the context of the text.
Copy file name to clipboardExpand all lines: scripts/manageacl.py
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -174,17 +174,17 @@ async def main(args: Any):
174
174
parser.add_argument(
175
175
"--search-service",
176
176
required=True,
177
-
help="Name of the Azure Cognitive Search service where content should be indexed (must exist already)",
177
+
help="Name of the Azure AI Search service where content should be indexed (must exist already)",
178
178
)
179
179
parser.add_argument(
180
180
"--index",
181
181
required=True,
182
-
help="Name of the Azure Cognitive Search index where content should be indexed (will be created if it doesn't exist)",
182
+
help="Name of the Azure AI Search index where content should be indexed (will be created if it doesn't exist)",
183
183
)
184
184
parser.add_argument(
185
185
"--search-key",
186
186
required=False,
187
-
help="Optional. Use this Azure Cognitive Search account key instead of the current user identity to login (use az login to set current user for Azure)",
187
+
help="Optional. Use this Azure AI Search account key instead of the current user identity to login (use az login to set current user for Azure)",
188
188
)
189
189
parser.add_argument("--acl-type", required=False, choices=["oids", "groups"], help="Optional. Type of ACL")
help="Name of the Azure Cognitive Search service where content should be indexed (must exist already)",
178
+
help="Name of the Azure AI Search service where content should be indexed (must exist already)",
179
179
)
180
180
parser.add_argument(
181
181
"--index",
182
-
help="Name of the Azure Cognitive Search index where content should be indexed (will be created if it doesn't exist)",
182
+
help="Name of the Azure AI Search index where content should be indexed (will be created if it doesn't exist)",
183
183
)
184
184
parser.add_argument(
185
185
"--searchkey",
186
186
required=False,
187
-
help="Optional. Use this Azure Cognitive Search account key instead of the current user identity to login (use az login to set current user for Azure)",
187
+
help="Optional. Use this Azure AI Search account key instead of the current user identity to login (use az login to set current user for Azure)",
188
188
)
189
189
parser.add_argument(
190
190
"--searchanalyzername",
191
191
required=False,
192
192
default="en.microsoft",
193
-
help="Optional. Name of the Azure Cognitive Search analyzer to use for the content field in the index",
193
+
help="Optional. Name of the Azure AI Search analyzer to use for the content field in the index",
194
194
)
195
195
parser.add_argument("--openaihost", help="Host of the API used to compute embeddings ('azure' or 'openai')")
196
196
parser.add_argument("--openaiservice", help="Name of the Azure OpenAI service used to compute embeddings")
0 commit comments