Skip to content

Commit

Permalink
Upgrade to .NET 8.0 GA bits - all packages (Azure-Samples#243)
Browse files Browse the repository at this point in the history
- Remove unused `Directory.Build.props`
- Upgrade to .NET 8.0 GA bits and other packages
- Correct Azure Search usage (APIs renamed)
- Remove unused `using`
- Fix formatting

Closes Azure-Samples#239
  • Loading branch information
IEvangelist committed Dec 5, 2023
1 parent c5706e3 commit b99fd24
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 78 deletions.
56 changes: 28 additions & 28 deletions app/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,43 @@
<ItemGroup>
<PackageVersion Include="Azure.AI.FormRecognizer" Version="4.1.0" />
<PackageVersion Include="Azure.AI.OpenAI" Version="1.0.0-beta.8" />
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageVersion Include="Azure.Identity" Version="1.10.2" />
<PackageVersion Include="Azure.Search.Documents" Version="11.5.0-beta.5" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.18.0" />
<PackageVersion Include="Azure.Storage.Files.Shares" Version="12.16.0" />
<PackageVersion Include="Azure.Storage.Queues" Version="12.16.0" />
<PackageVersion Include="Blazor.LocalStorage.WebAssembly" Version="8.0.0-rc.2.23480.2" />
<PackageVersion Include="Blazor.SessionStorage.WebAssembly" Version="8.0.0-rc.2.23480.2" />
<PackageVersion Include="Blazor.SpeechRecognition.WebAssembly" Version="8.0.0-rc.2.23480.2" />
<PackageVersion Include="Blazor.SpeechSynthesis.WebAssembly" Version="8.0.0-rc.2.23480.2" />
<PackageVersion Include="bunit" Version="1.24.10" />
<PackageVersion Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.0" />
<PackageVersion Include="Azure.Identity" Version="1.10.4" />
<PackageVersion Include="Azure.Search.Documents" Version="11.5.1" />
<PackageVersion Include="Azure.Storage.Blobs" Version="12.19.1" />
<PackageVersion Include="Azure.Storage.Files.Shares" Version="12.17.1" />
<PackageVersion Include="Azure.Storage.Queues" Version="12.17.1" />
<PackageVersion Include="Blazor.LocalStorage.WebAssembly" Version="8.0.0" />
<PackageVersion Include="Blazor.SessionStorage.WebAssembly" Version="8.0.0" />
<PackageVersion Include="Blazor.SpeechRecognition.WebAssembly" Version="8.0.0" />
<PackageVersion Include="Blazor.SpeechSynthesis.WebAssembly" Version="8.0.0" />
<PackageVersion Include="bunit" Version="1.25.3" />
<PackageVersion Include="coverlet.collector" Version="6.0.0" />
<PackageVersion Include="Markdig" Version="0.33.0" />
<PackageVersion Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0-beta3" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0-rc.2.23480.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.0-rc.2.23480.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0-rc.2.23480.2" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly.Server" Version="8.0.0" />
<PackageVersion Include="Microsoft.AspNetCore.Components.WebAssembly" Version="8.0.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="6.2.0" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.15.1" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker" Version="1.19.0" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.7.0" />
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.0-rc.2.23480.2" />
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0-rc.2.23479.6" />
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0-rc.2.23479.6" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0-rc.2.23479.6" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0-rc.2.23479.6" />
<PackageVersion Include="Microsoft.ML" Version="2.0.1" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.2" />
<PackageVersion Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
<PackageVersion Include="Microsoft.Extensions.Azure" Version="1.7.1" />
<PackageVersion Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.FileSystemGlobbing" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Http" Version="8.0.0" />
<PackageVersion Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
<PackageVersion Include="Microsoft.ML" Version="3.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.SemanticKernel" Version="0.24.230918.1-preview" />
<PackageVersion Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageVersion Include="MudBlazor" Version="6.11.0" />
<PackageVersion Include="MudBlazor" Version="6.11.1" />
<PackageVersion Include="PdfSharpCore" Version="1.3.62" />
<PackageVersion Include="Pinecone.NET" Version="1.3.0" />
<PackageVersion Include="Pinecone.NET" Version="1.3.2" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageVersion Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.3" />
<PackageVersion Include="xunit" Version="2.5.2" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.5.4" />
<PackageVersion Include="xunit" Version="2.6.2" />
</ItemGroup>
</Project>
1 change: 0 additions & 1 deletion app/app.sln
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
.editorconfig = .editorconfig
..\.gitignore = ..\.gitignore
..\.github\workflows\azure-dev.yml = ..\.github\workflows\azure-dev.yml
Directory.Build.props = Directory.Build.props
Directory.Packages.props = Directory.Packages.props
..\.github\workflows\dotnet-build.yml = ..\.github\workflows\dotnet-build.yml
..\LICENSE = ..\LICENSE
Expand Down
27 changes: 16 additions & 11 deletions app/backend/Extensions/SearchClientExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,22 @@ internal static class SearchClientExtensions
var useSemanticRanker = overrides?.SemanticRanker ?? false;
var useSemanticCaptions = overrides?.SemanticCaptions ?? false;

SearchOptions searchOption = useSemanticRanker
SearchOptions searchOptions = useSemanticRanker
? new SearchOptions
{
Filter = filter,
QueryType = SearchQueryType.Semantic,
QueryLanguage = "en-us",
QuerySpeller = "lexicon",
SemanticConfigurationName = "default",
SemanticSearch = new()
{
SemanticConfigurationName = "default",
QueryCaption = new(useSemanticCaptions
? QueryCaptionType.Extractive
: QueryCaptionType.None),
},
// TODO: Find if these options are assignable
//QueryLanguage = "en-us",
//QuerySpeller = "lexicon",
Size = top,
QueryCaption = useSemanticCaptions ? QueryCaptionType.Extractive : QueryCaptionType.None,
}
: new SearchOptions
{
Expand All @@ -38,19 +44,18 @@ internal static class SearchClientExtensions
if (embedding != null && overrides?.RetrievalMode != "Text")
{
var k = useSemanticRanker ? 50 : top;
var vectorQuery = new RawVectorQuery
var vectorQuery = new VectorizedQuery(embedding)
{
// if semantic ranker is enabled, we need to set the rank to a large number to get more
// candidates for semantic reranking
KNearestNeighborsCount = useSemanticRanker ? 50 : top,
Vector = embedding,
};
vectorQuery.Fields.Add("embedding");
searchOption.VectorQueries.Add(vectorQuery);
searchOptions.VectorSearch.Queries.Add(vectorQuery);
}

var searchResultResponse = await searchClient.SearchAsync<SearchDocument>(
query, searchOption, cancellationToken);
query, searchOptions, cancellationToken);
if (searchResultResponse.Value is null)
{
throw new InvalidOperationException("fail to get search result");
Expand All @@ -77,7 +82,7 @@ internal static class SearchClientExtensions
{
if (useSemanticCaptions)
{
var docs = doc.Captions.Select(c => c.Text);
var docs = doc.SemanticSearch.Captions.Select(c => c.Text);
contentValue = string.Join(" . ", docs);
}
else
Expand All @@ -98,6 +103,6 @@ internal static class SearchClientExtensions
}
}

return sb.ToArray();
return [.. sb];
}
}
1 change: 0 additions & 1 deletion app/backend/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

global using System.Diagnostics;
global using System.Runtime.CompilerServices;
global using System.Text;
global using System.Text.Json;
global using Azure.AI.FormRecognizer.DocumentAnalysis;
global using Azure.AI.OpenAI;
Expand Down
1 change: 0 additions & 1 deletion app/functions/EmbedFunctions/Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using Azure.AI.OpenAI;
using Microsoft.Extensions.DependencyInjection;

var host = new HostBuilder()
.ConfigureServices(services =>
Expand Down
55 changes: 25 additions & 30 deletions app/functions/EmbedFunctions/Services/AzureSearchEmbedService.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using Azure.AI.OpenAI;
using Google.Protobuf.WellKnownTypes;
using Microsoft.Extensions.Options;

namespace EmbedFunctions.Services;

Expand Down Expand Up @@ -61,48 +59,45 @@ public async Task CreateSearchIndexAsync(string searchIndexName)
VectorSearch = new()
{
Algorithms =
{
new HnswVectorSearchAlgorithmConfiguration(vectorSearchConfigName)
},
{
new HnswAlgorithmConfiguration(vectorSearchConfigName)
},
Profiles =
{
new VectorSearchProfile(vectorSearchProfile, vectorSearchConfigName)
}
{
new VectorSearchProfile(vectorSearchProfile, vectorSearchConfigName)
}
},
Fields =
{
new SimpleField("id", SearchFieldDataType.String) { IsKey = true },
new SearchableField("content") { AnalyzerName = LexicalAnalyzerName.EnMicrosoft },
new SimpleField("category", SearchFieldDataType.String) { IsFacetable = true },
new SimpleField("sourcepage", SearchFieldDataType.String) { IsFacetable = true },
new SimpleField("sourcefile", SearchFieldDataType.String) { IsFacetable = true },
new SearchField("embedding", SearchFieldDataType.Collection(SearchFieldDataType.Single))
{
VectorSearchDimensions = 1536,
IsSearchable = true,
VectorSearchProfile = vectorSearchProfile,
}
},
SemanticSettings = new SemanticSettings
new SimpleField("id", SearchFieldDataType.String) { IsKey = true },
new SearchableField("content") { AnalyzerName = LexicalAnalyzerName.EnMicrosoft },
new SimpleField("category", SearchFieldDataType.String) { IsFacetable = true },
new SimpleField("sourcepage", SearchFieldDataType.String) { IsFacetable = true },
new SimpleField("sourcefile", SearchFieldDataType.String) { IsFacetable = true },
new SearchField("embedding", SearchFieldDataType.Collection(SearchFieldDataType.Single))
{
VectorSearchDimensions = 1536,
IsSearchable = true,
VectorSearchProfileName = vectorSearchProfile,
}
},
SemanticSearch = new()
{
Configurations =
{
new SemanticConfiguration("default", new PrioritizedFields
{
ContentFields =
new SemanticConfiguration("default", new()
{
new SemanticField
ContentFields =
{
FieldName = "content"
new SemanticField("content")
}
}
})
}
})
}
}
};

logger?.LogInformation(
"Creating '{searchIndexName}' search index", searchIndexName);
"Creating '{searchIndexName}' search index", searchIndexName);

await searchIndexClient.CreateIndexAsync(index);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Copyright (c) Microsoft. All rights reserved.

using System.IO;

namespace EmbedFunctions.Services;

public sealed class EmbeddingAggregateService(
Expand Down
3 changes: 0 additions & 3 deletions app/prepdocs/PrepareDocs/GlobalUsings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
global using System.CommandLine.Invocation;
global using System.CommandLine.Parsing;
global using System.Linq;
global using System.Net;
global using System.Text;
global using System.Text.RegularExpressions;
global using Azure;
global using Azure.AI.FormRecognizer.DocumentAnalysis;
global using Azure.Identity;
global using Azure.Search.Documents;
global using Azure.Search.Documents.Indexes;
global using Azure.Search.Documents.Indexes.Models;
global using Azure.Search.Documents.Models;
global using Azure.Storage.Blobs;
global using Azure.Storage.Blobs.Models;
Expand Down
1 change: 0 additions & 1 deletion app/prepdocs/PrepareDocs/Program.Clients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


using EmbedFunctions.Services;
using Microsoft.Extensions.Logging;

internal static partial class Program
{
Expand Down

0 comments on commit b99fd24

Please sign in to comment.