Skip to content

Commit 6f368d8

Browse files
committed
Added filter example
1 parent 579160c commit 6f368d8

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
114 KB
Loading

articles/search/tutorial-rag-build-solution-query.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,30 @@ Results from the first query`"how much of earth is covered by water"` should loo
123123

124124
:::image type="content" source="media/tutorial-rag-solution/chat-results-1.png" alt-text="Screenshot of an LLM response to a simple question using a single match from search results.":::
125125

126-
### Changing the inputs
126+
It's common for LLMs to return different answers, even if the prompt and queries are unchanged. Your result might look very different from the example.
127+
128+
> [!NOTE]
129+
> In testing this tutorial, we saw a variety of responses, some more relevant than others. A few times, repeating the same request caused a deterioration in the response, most likely due to confusion in the chat history, possibly with the model registering the repeated requests as dissatisfaction with the generated answer. Managing chat history is out of scope for this tutorial, but including it in your application code should mitigate or even eliminate this behavior.
130+
131+
## Add a filter
132+
133+
Recall that you created a `locations` field using applied AI, populated with places recognized by the Entity Recognition skill. The field definition for locations includes the `filterable` attribute. Let's repeat the previous request, but this time adding a filter that selects on the term *ice* in the locations field.
134+
135+
Replace the search_results definition with the following example that includes a filter:
136+
137+
```python
138+
search_results = search_client.search(
139+
search_text=query,
140+
top=10,
141+
filter="search.ismatch('ice*', 'locations', 'full', 'any')",
142+
select="title, chunk, locations"
143+
```
144+
145+
Results from the filtered query should now look similar to the following response.
146+
147+
:::image type="content" source="media/tutorial-rag-solution/chat-results-filter.png" alt-text="Screenshot of an LLM response after a filter is added.":::
148+
149+
## Change the inputs
127150

128151
Increasing or decreasing the number of inputs to the LLM can have a large effect on the response. Try running the same query again after setting `top=3`. When you increase the inputs, the model returns different results each time, even if the query doesn't change.
129152

@@ -133,7 +156,7 @@ Here's one example of what the model returns after increasing the inputs to 3.
133156

134157
Because the model is bound to just the grounding data, the answer becomes more expansive as you increase size of the input. You can use relevance tuning to potentially generate more focused answers.
135158

136-
### Changing the prompt
159+
## Change the prompt
137160

138161
You can also change the prompt to control the format of the output, tone, and whether you want the model to supplement the answer with its own training data by changing the prompt.
139162

0 commit comments

Comments
 (0)