Skip to content

Commit f5b168f

Browse files
add image embedding to azure index (#271)
## Purpose <!-- Describe the intention of the changes being proposed. What problem does it solve or functionality does it add? --> * ... ## Does this introduce a breaking change? <!-- Mark one with an "x". --> ``` [ ] Yes [ ] No ``` ## Pull Request Type What kind of change does this Pull Request introduce? <!-- Please check the one that applies to this PR using "x". --> ``` [ ] Bugfix [ ] Feature [ ] Code style update (formatting, local variables) [ ] Refactoring (no functional changes, no api changes) [ ] Documentation content changes [ ] Other... Please describe: ``` ## How to Test * Get the code ``` git clone [repo-address] cd [repo-name] git checkout [branch-name] npm install ``` * Test the code <!-- Add steps to run the tests suite and/or manually test --> ``` ``` ## What to Check Verify that the following are valid * ... ## Other Information <!-- Add any other helpful information that may be needed here. --> --------- Co-authored-by: David Pine <[email protected]>
1 parent 9543b54 commit f5b168f

37 files changed

+739
-100
lines changed

app/backend/Extensions/ServiceCollectionExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ internal static IServiceCollection AddAzureServices(this IServiceCollection serv
2727
return sp.GetRequiredService<BlobServiceClient>().GetBlobContainerClient(azureStorageContainer);
2828
});
2929

30-
services.AddSingleton<IDocumentService, AzureDocumentService>(sp =>
30+
services.AddSingleton<ISearchService, AzureSearchService>(sp =>
3131
{
3232
var config = sp.GetRequiredService<IConfiguration>();
3333
var azureSearchServiceEndpoint = config["AzureSearchServiceEndpoint"];
@@ -39,7 +39,7 @@ internal static IServiceCollection AddAzureServices(this IServiceCollection serv
3939
var searchClient = new SearchClient(
4040
new Uri(azureSearchServiceEndpoint), azureSearchIndex, s_azureCredential);
4141

42-
return new AzureDocumentService(searchClient);
42+
return new AzureSearchService(searchClient);
4343
});
4444

4545
services.AddSingleton<DocumentAnalysisClient>(sp =>

app/backend/Services/ReadRetrieveReadChatService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ namespace MinimalApi.Services;
44

55
public class ReadRetrieveReadChatService
66
{
7-
private readonly IDocumentService _searchClient;
7+
private readonly ISearchService _searchClient;
88
private readonly IKernel _kernel;
99
private readonly IConfiguration _configuration;
1010

1111
public ReadRetrieveReadChatService(
12-
IDocumentService searchClient,
12+
ISearchService searchClient,
1313
OpenAIClient client,
1414
IConfiguration configuration)
1515
{
@@ -158,6 +158,7 @@ Return the follow-up question as a json string list.
158158
}
159159
return new ApproachResponse(
160160
DataPoints: documentContentList,
161+
Images: null,
161162
Answer: ans,
162163
Thoughts: thoughts,
163164
CitationBaseUrl: _configuration.ToCitationBaseUrl());

app/frontend/Services/ApiClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ private async Task<AnswerResult<TRequest>> PostRequestAsync<TRequest>(
125125
$"HTTP {(int)response.StatusCode} : {response.ReasonPhrase ?? "☹️ Unknown error..."}",
126126
null,
127127
[],
128+
null,
128129
"Unable to retrieve valid response from the server.");
129130

130131
return result with

app/functions/EmbedFunctions/Program.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,17 @@ uri is not null
6565
var documentClient = provider.GetRequiredService<DocumentAnalysisClient>();
6666
var logger = provider.GetRequiredService<ILogger<AzureSearchEmbedService>>();
6767

68-
return new AzureSearchEmbedService(openAIClient, embeddingModelName, searchClient, searchIndexName, searchIndexClient, documentClient, blobContainerClient, logger);
68+
return new AzureSearchEmbedService(
69+
openAIClient: openAIClient,
70+
embeddingModelName: embeddingModelName,
71+
searchClient: searchClient,
72+
searchIndexName: searchIndexName,
73+
searchIndexClient: searchIndexClient,
74+
documentAnalysisClient: documentClient,
75+
corpusContainerClient: blobContainerClient,
76+
computerVisionService: null,
77+
includeImageEmbeddingsField: false,
78+
logger: logger);
6979
});
7080
})
7181
.ConfigureFunctionsWorkerDefaults()

app/functions/EmbedFunctions/Services/EmbeddingAggregateService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal async Task EmbedBlobAsync(Stream blobStream, string blobName)
1414
var embeddingType = GetEmbeddingType();
1515
var embedService = embedServiceFactory.GetEmbedService(embeddingType);
1616

17-
var result = await embedService.EmbedBlobAsync(blobStream, blobName);
17+
var result = await embedService.EmbedPDFBlobAsync(blobStream, blobName);
1818

1919
var status = result switch
2020
{

app/functions/EmbedFunctions/Services/IEmbedService.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3+
34
namespace EmbedFunctions.Services;
45

56
internal sealed class MilvusEmbedService : IEmbedService
67
{
7-
public Task<bool> EmbedBlobAsync(Stream blobStream, string blobName) => throw new NotImplementedException();
8+
public Task CreateSearchIndexAsync(string searchIndexName, CancellationToken ct = default)
9+
{
10+
throw new NotImplementedException();
11+
}
12+
13+
public Task<bool> EmbedImageBlobAsync(Stream imageStream, string imageName, CancellationToken ct = default)
14+
{
15+
throw new NotImplementedException();
16+
}
17+
18+
public Task<bool> EmbedPDFBlobAsync(Stream blobStream, string blobName) => throw new NotImplementedException();
19+
20+
public Task EnsureSearchIndexAsync(string searchIndexName, CancellationToken ct = default)
21+
{
22+
throw new NotImplementedException();
23+
}
824
}
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3+
34
namespace EmbedFunctions.Services;
45

56
internal sealed class PineconeEmbedService : IEmbedService
67
{
7-
public Task<bool> EmbedBlobAsync(Stream blobStream, string blobName) => throw new NotImplementedException(
8+
public Task CreateSearchIndexAsync(string searchIndexName, CancellationToken ct = default)
9+
{
10+
throw new NotImplementedException();
11+
}
12+
13+
public Task<bool> EmbedImageBlobAsync(Stream imageStream, string imageName, CancellationToken ct = default)
14+
{
15+
throw new NotImplementedException();
16+
}
17+
18+
public Task<bool> EmbedPDFBlobAsync(Stream blobStream, string blobName) => throw new NotImplementedException(
819
"Pinecone embedding isn't implemented.");
20+
21+
public Task EnsureSearchIndexAsync(string searchIndexName, CancellationToken ct = default)
22+
{
23+
throw new NotImplementedException();
24+
}
925
}
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
11
// Copyright (c) Microsoft. All rights reserved.
22

3+
34
namespace EmbedFunctions.Services;
45

56
internal sealed class QdrantEmbedService : IEmbedService
67
{
7-
public Task<bool> EmbedBlobAsync(Stream blobStream, string blobName) => throw new NotImplementedException();
8+
public Task CreateSearchIndexAsync(string searchIndexName, CancellationToken ct = default)
9+
{
10+
throw new NotImplementedException();
11+
}
12+
13+
public Task<bool> EmbedImageBlobAsync(Stream imageStream, string imageName, CancellationToken ct = default)
14+
{
15+
throw new NotImplementedException();
16+
}
17+
18+
public Task<bool> EmbedPDFBlobAsync(Stream blobStream, string blobName) => throw new NotImplementedException();
19+
20+
public Task EnsureSearchIndexAsync(string searchIndexName, CancellationToken ct = default)
21+
{
22+
throw new NotImplementedException();
23+
}
824
}

app/prepdocs/PrepareDocs/AppOptions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ internal record class AppOptions(
1616
bool Remove,
1717
bool RemoveAll,
1818
string? FormRecognizerServiceEndpoint,
19+
string? ComputerVisionServiceEndpoint,
1920
bool Verbose,
2021
IConsole Console) : AppConsole(Console);
2122

0 commit comments

Comments
 (0)