Skip to content

Commit

Permalink
Rename semantic search to semantic ranking
Browse files Browse the repository at this point in the history
  • Loading branch information
jelledruyts committed Nov 16, 2023
1 parent 25b1856 commit 2212d78
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## About

This project provides a very easy to use learning and experimentation playground to try out various AI-enabled search scenarios in Azure. It provides a web application front-end which uses [Azure AI Search](https://learn.microsoft.com/azure/search/search-what-is-azure-search) and [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview) to execute searches with a variety of options - ranging from simple keyword search, to semantic search, vector and hybrid search, and using generative AI to answer search queries in various ways. This allows you to quickly understand what each option does, how it affects the search results, and how various approaches compare against each other.
This project provides a very easy to use learning and experimentation playground to try out various AI-enabled search scenarios in Azure. It provides a web application front-end which uses [Azure AI Search](https://learn.microsoft.com/azure/search/search-what-is-azure-search) and [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview) to execute searches with a variety of options - ranging from simple keyword search, to semantic ranking, vector and hybrid search, and using generative AI to answer search queries in various ways. This allows you to quickly understand what each option does, how it affects the search results, and how various approaches compare against each other.

By default, a few documents are added automatically to allow you to use the application directly. You're encouraged to upload your own documents (which you can also easily do via the web app) so you can experiment with searching over your own content.

Expand Down Expand Up @@ -53,7 +53,7 @@ graph TD

When you deploy the solution, it creates an [Azure AI Search](https://learn.microsoft.com/azure/search/search-what-is-azure-search) service which indexes document content from a blob storage container. (Note that documents are assumed to be in English.)

The documents in the index are also chunked into smaller pieces, and vector embeddings are created for these chunks using a Function App based on the [Azure OpenAI Embeddings Generator power skill](https://github.com/Azure-Samples/azure-search-power-skills/tree/main/Vector/EmbeddingGenerator). This allows you to easily try out [vector and hybrid search](https://learn.microsoft.com/azure/search/vector-search-overview). With Azure AI Search on its own, the responses *always* come directly from the source data, rather than being generated by an AI model. You can optionally use [semantic search](https://learn.microsoft.com/azure/search/semantic-search-overview) which *does* use AI, not to generate content but to increase the relevancy of the results and provide semantic answers and captions.
The documents in the index are also chunked into smaller pieces, and vector embeddings are created for these chunks using a Function App based on the [Azure OpenAI Embeddings Generator power skill](https://github.com/Azure-Samples/azure-search-power-skills/tree/main/Vector/EmbeddingGenerator). This allows you to easily try out [vector and hybrid search](https://learn.microsoft.com/azure/search/vector-search-overview). With Azure AI Search on its own, the responses *always* come directly from the source data, rather than being generated by an AI model. You can optionally use [semantic ranking](https://learn.microsoft.com/azure/search/semantic-search-overview) which *does* use AI, not to generate content but to increase the relevancy of the results and provide semantic answers and captions.

The solution also deploys an [Azure OpenAI](https://learn.microsoft.com/azure/ai-services/openai/overview) service. It provides an embeddings model to generate the vector representations of the document chunks and search queries, and a GPT model to generate answers to your search queries. If you choose the option to use [Azure OpenAI "on your data"](https://learn.microsoft.com/azure/ai-services/openai/concepts/use-your-data), these AI-generated responses can be grounded in (and even limited to) the information in your Azure AI Search indexes. This option allows you to let Azure OpenAI orchestrate the [Retrieval Augmented Generation (RAG)](https://aka.ms/what-is-rag) pattern. This means your search query will first be used to retrieve the most relevant documents (or preferably *smaller chunks of those documents*) from your private data source. Those search results are then used as context in the prompt that gets sent to the AI model, along with the original search query. This allows the AI model to generate a response based on the most relevant source data, rather than the public data that was used to train the model. Next to letting Azure OpenAI orchestrate the RAG pattern, the web application can also use [Semantic Kernel](https://learn.microsoft.com/semantic-kernel/overview/) to perform that orchestration, using a prompt and other parameters you can control yourself.

Expand Down
14 changes: 7 additions & 7 deletions src/Azure.AISearch.WebApp/Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@
}
if (queryType == '@QueryType.TextSemantic' || queryType == '@QueryType.HybridSemantic') {
// Semantic search.
mermaidDiagram += 'ACS->>ACS: L2 semantic reranking of search results\n';
// Semantic ranking.
mermaidDiagram += 'ACS->>ACS: L2 semantic ranking of search results\n';
}
mermaidDiagram += 'destroy ACS\n';
mermaidDiagram += `ACS-x${sourceParticipant}: Search results\n`;
Expand Down Expand Up @@ -207,7 +207,7 @@
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="@nameof(SearchRequest.Engine)" id="searchRequest-Engine-AzureCognitiveSearch" value="@EngineType.AzureCognitiveSearch" v-model="searchRequest.engine">
<label class="form-check-label" for="searchRequest-Engine-AzureCognitiveSearch">Azure AI Search</label>
<span class="info-tip" data-bs-toggle="popover" data-bs-content="Search through content with <a href='https://learn.microsoft.com/azure/search/search-what-is-azure-search' target='_blank'>Azure AI Search</a>. You can use <a href='https://learn.microsoft.com/azure/search/search-lucene-query-architecture' target='_blank'>keyword</a> and optionally <a href='https://learn.microsoft.com/azure/search/vector-search-overview' target='_blank'>vector-based</a> queries. The responses <i>always</i> come directly from the source data, rather than being generated by an AI model. You can optionally enable <a href='https://learn.microsoft.com/azure/search/semantic-search-overview' target='_blank'>semantic search</a> which <i>does</i> use AI, not to generate content but to increase the relevancy of the results."><i class="bi bi-info-circle"></i></span>
<span class="info-tip" data-bs-toggle="popover" data-bs-content="Search through content with <a href='https://learn.microsoft.com/azure/search/search-what-is-azure-search' target='_blank'>Azure AI Search</a>. You can use <a href='https://learn.microsoft.com/azure/search/search-lucene-query-architecture' target='_blank'>keyword</a> and optionally <a href='https://learn.microsoft.com/azure/search/vector-search-overview' target='_blank'>vector-based</a> queries. The responses <i>always</i> come directly from the source data, rather than being generated by an AI model. You can optionally enable <a href='https://learn.microsoft.com/azure/search/semantic-search-overview' target='_blank'>semantic ranking</a> which <i>does</i> use AI, not to generate content but to increase the relevancy of the results."><i class="bi bi-info-circle"></i></span>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="@nameof(SearchRequest.Engine)" id="searchRequest-Engine-AzureOpenAI" value="@EngineType.AzureOpenAI" v-model="searchRequest.engine">
Expand Down Expand Up @@ -269,7 +269,7 @@
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="@nameof(SearchRequest.SearchIndex)" id="searchRequest-SearchIndex-Documents" value="@SearchIndexType.Documents" v-model="searchRequest.searchIndex">
<label class="form-check-label" for="searchRequest-SearchIndex-Documents">Documents</label>
<span class="info-tip" data-bs-toggle="popover" data-bs-content="Contains the full text content of the source data, as <a href='https://learn.microsoft.com/azure/search/search-blob-storage-integration' target='_blank'>extracted from your files in Blob storage</a>. Each file and its entire contents are stored as a single document in the search index, which can therefore be quite large. For regular keyword or semantic search that works great, but large content may cause issues with token limits, prompt size and content relevancy in AI applications."><i class="bi bi-info-circle"></i></span>
<span class="info-tip" data-bs-toggle="popover" data-bs-content="Contains the full text content of the source data, as <a href='https://learn.microsoft.com/azure/search/search-blob-storage-integration' target='_blank'>extracted from your files in Blob storage</a>. Each file and its entire contents are stored as a single document in the search index, which can therefore be quite large. For regular keyword search or using semantic ranking that works great, but large content may cause issues with token limits, prompt size and content relevancy in AI applications."><i class="bi bi-info-circle"></i></span>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="@nameof(SearchRequest.SearchIndex)" id="searchRequest-SearchIndex-Chunks" value="@SearchIndexType.Chunks" v-model="searchRequest.searchIndex">
Expand All @@ -290,7 +290,7 @@
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="@nameof(SearchRequest.QueryType)" id="searchRequest-QueryType-TextSemantic" value="@QueryType.TextSemantic" v-model="searchRequest.queryType">
<label class="form-check-label" for="searchRequest-QueryType-TextSemantic">Semantic keyword</label>
<span class="info-tip" data-bs-toggle="popover" data-bs-content="Use <a href='https://learn.microsoft.com/azure/search/semantic-search-overview' target='_blank'>semantic search</a>, which returns more relevant results by applying language understanding to initial search results. It can also return <a href='https://learn.microsoft.com/azure/search/semantic-how-to-query-request' target='_blank'>semantic captions</a> (parts of a document that best summarize the content) and even <a href='https://learn.microsoft.com/azure/search/semantic-answers' target='_blank'>semantic answers</a> (direct answers to queries that look like a question). In all cases, the responses aren't AI-generated but come directly from the source data."><i class="bi bi-info-circle"></i></span>
<span class="info-tip" data-bs-toggle="popover" data-bs-content="Use <a href='https://learn.microsoft.com/azure/search/semantic-search-overview' target='_blank'>semantic ranking</a>, which returns more relevant results by applying language understanding to initial search results. It can also return <a href='https://learn.microsoft.com/azure/search/semantic-how-to-query-request' target='_blank'>semantic captions</a> (parts of a document that best summarize the content) and even <a href='https://learn.microsoft.com/azure/search/semantic-answers' target='_blank'>semantic answers</a> (direct answers to queries that look like a question). In all cases, the responses aren't AI-generated but come directly from the source data."><i class="bi bi-info-circle"></i></span>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="@nameof(SearchRequest.QueryType)" id="searchRequest-QueryType-Vector" value="@QueryType.Vector" v-model="searchRequest.queryType" v-bind:disabled="searchRequest.searchIndex == '@SearchIndexType.Documents'">
Expand All @@ -305,7 +305,7 @@
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="@nameof(SearchRequest.QueryType)" id="searchRequest-QueryType-HybridSemantic" value="@QueryType.HybridSemantic" v-model="searchRequest.queryType" v-bind:disabled="searchRequest.searchIndex == '@SearchIndexType.Documents'">
<label class="form-check-label" for="searchRequest-QueryType-HybridSemantic">Semantic hybrid (keyword + vector)</label>
<span class="info-tip" data-bs-toggle="popover" data-bs-content="Combine the results of a <a href='https://learn.microsoft.com/azure/search/vector-search-overview' target='_blank'>vector search</a> with <a href='https://learn.microsoft.com/azure/search/semantic-search-overview' target='_blank'>semantic search</a> results into a single ranked response. Compared to standard hybrid search, this provides even more accuracy with L2 reranking using the same language models that power Bing."><i class="bi bi-info-circle"></i></span>
<span class="info-tip" data-bs-toggle="popover" data-bs-content="Combine the results of <a href='https://learn.microsoft.com/azure/search/vector-search-overview' target='_blank'>vector search</a> and <a href='https://learn.microsoft.com/azure/search/semantic-search-overview' target='_blank'>search with semantic ranking</a> into a single ranked response. Compared to standard hybrid search, this provides even more accuracy with L2 reranking using the same language models that power Bing."><i class="bi bi-info-circle"></i></span>
</div>
</div>
</div>
Expand Down Expand Up @@ -333,7 +333,7 @@
<div class="input-group">
<div class="input-group-text">
Nearest neighbors
<span class="info-tip" data-bs-toggle="popover" data-bs-content="The number of nearest neighbors to return from vector search. When using semantic search, this should be set to a high enough number in order to get sufficient candidates for semantic reranking."><i class="bi bi-info-circle"></i></span>
<span class="info-tip" data-bs-toggle="popover" data-bs-content="The number of nearest neighbors to return from vector search. When using semantic ranking, this should be set to a high enough number in order to get sufficient candidates for the reranking."><i class="bi bi-info-circle"></i></span>
</div>
<input type="number" class="form-control form-control-small" name="@nameof(SearchRequest.VectorNearestNeighborsCount)" value="@Model.SearchRequest.VectorNearestNeighborsCount" />
</div>
Expand Down
10 changes: 5 additions & 5 deletions src/Azure.AISearch.WebApp/Services/SearchScenarioProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public IList<SearchScenario> GetSearchScenarios()
{
Id = "az-cognitivesearch-documents-keyword-semantic",
DisplayName = "Azure AI Search - Documents - Keyword - Semantic",
Description = "This scenario uses Azure AI Search to perform keyword search across the original documents. It uses semantic search which returns more relevant results by applying language understanding to an initial search result.",
Description = "This scenario uses Azure AI Search to perform keyword search across the original documents. It uses semantic ranking which returns more relevant results by applying language understanding to an initial search result.",
SearchRequest = new SearchRequest
{
Engine = EngineType.AzureCognitiveSearch,
Expand All @@ -57,7 +57,7 @@ public IList<SearchScenario> GetSearchScenarios()
{
Id = "az-cognitivesearch-chunks-keyword-semantic",
DisplayName = "Azure AI Search - Chunks - Keyword - Semantic",
Description = "This scenario uses Azure AI Search to perform keyword search across the smaller chunks of the original documents. It uses semantic search which returns more relevant results by applying language understanding to an initial search result.",
Description = "This scenario uses Azure AI Search to perform keyword search across the smaller chunks of the original documents. It uses semantic ranking which returns more relevant results by applying language understanding to an initial search result.",
SearchRequest = new SearchRequest
{
Engine = EngineType.AzureCognitiveSearch,
Expand All @@ -81,7 +81,7 @@ public IList<SearchScenario> GetSearchScenarios()
{
Id = "az-cognitivesearch-chunks-hybrid-semantic",
DisplayName = "Azure AI Search - Chunks - Hybrid - Semantic",
Description = "This scenario uses Azure AI Search to perform a hybrid (keyword + vector) search across the smaller chunks of the original documents, where each chunk is represented as a vector of numbers as determined by an Azure OpenAI embeddings model. The search query itself is first vectorized using the same embeddings model, and the best matching results for the search query are determined based on merging the results of the keyword and vector searches. The keyword search uses semantic search for even more accuracy with L2 reranking using the same language models that power Bing.",
Description = "This scenario uses Azure AI Search to perform a hybrid (keyword + vector) search across the smaller chunks of the original documents, where each chunk is represented as a vector of numbers as determined by an Azure OpenAI embeddings model. The search query itself is first vectorized using the same embeddings model, and the best matching results for the search query are determined based on merging the results of the keyword and vector searches. The keyword search uses semantic ranking for even more accuracy with L2 reranking using the same language models that power Bing.",
SearchRequest = new SearchRequest
{
Engine = EngineType.AzureCognitiveSearch,
Expand Down Expand Up @@ -114,7 +114,7 @@ public IList<SearchScenario> GetSearchScenarios()
OpenAIGptDeployment = this.settings.OpenAIGptDeployment,
SystemRoleInformation = this.settings.GetDefaultSystemRoleInformation(),
SearchIndex = SearchIndexType.Chunks, // As a built-in scenario, always use the chunks index for best results
QueryType = QueryType.HybridSemantic, // As a built-in scenario, always use semantic search for best results
QueryType = QueryType.HybridSemantic, // As a built-in scenario, always use semantic ranking for best results
LimitToDataSource = true
}
},
Expand All @@ -129,7 +129,7 @@ public IList<SearchScenario> GetSearchScenarios()
OpenAIGptDeployment = this.settings.OpenAIGptDeployment,
CustomOrchestrationPrompt = this.settings.GetDefaultCustomOrchestrationPrompt(),
SearchIndex = SearchIndexType.Chunks, // As a built-in scenario, always use the chunks index for best results
QueryType = QueryType.HybridSemantic // As a built-in scenario, always use semantic search for best results
QueryType = QueryType.HybridSemantic // As a built-in scenario, always use semantic ranking for best results
}
}
};
Expand Down

0 comments on commit 2212d78

Please sign in to comment.