Skip to content

Commit c41a59c

Browse files
AI Chat Web template fixes for Azure AI Search (#6429)
* AI Chat Web template fixes for Azure AI Search * Update snapshots
1 parent 5444639 commit c41a59c

File tree

8 files changed

+16
-16
lines changed

8 files changed

+16
-16
lines changed

src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/Services/IngestedDocument.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ public class IngestedDocument
2121
public required string DocumentVersion { get; set; }
2222

2323
// The vector is not used but required for some vector databases
24-
[VectorStoreRecordVector(1, DistanceFunction = DistanceFunction.CosineSimilarity)]
25-
public ReadOnlyMemory<float> Vector { get; set; } = new ReadOnlyMemory<float>([0]);
24+
[VectorStoreRecordVector(2, DistanceFunction = DistanceFunction.CosineSimilarity)]
25+
public ReadOnlyMemory<float> Vector { get; set; } = new ReadOnlyMemory<float>([0, 0]);
2626
}

src/ProjectTemplates/Microsoft.Extensions.AI.Templates/src/ChatWithCustomData/ChatWithCustomData-CSharp.Web/Services/Ingestion/PDFDirectorySource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public Task<IEnumerable<IngestedDocument>> GetNewOrModifiedDocumentsAsync(IReadO
3030
#if (UseQdrant)
3131
results.Add(new() { Key = Guid.CreateVersion7(), SourceId = SourceId, DocumentId = sourceFileId, DocumentVersion = sourceFileVersion });
3232
#else
33-
results.Add(new() { Key = $"{SourceId}_{sourceFileId}", SourceId = SourceId, DocumentId = sourceFileId, DocumentVersion = sourceFileVersion });
33+
results.Add(new() { Key = Guid.CreateVersion7().ToString(), SourceId = SourceId, DocumentId = sourceFileId, DocumentVersion = sourceFileVersion });
3434
#endif
3535
}
3636
}
@@ -58,7 +58,7 @@ public async Task<IEnumerable<IngestedChunk>> CreateChunksForDocumentAsync(IEmbe
5858
#if (UseQdrant)
5959
Key = Guid.CreateVersion7(),
6060
#else
61-
Key = $"{Path.GetFileNameWithoutExtension(document.DocumentId)}_{pair.First.PageNumber}_{pair.First.IndexOnPage}",
61+
Key = Guid.CreateVersion7().ToString(),
6262
#endif
6363
DocumentId = document.DocumentId,
6464
PageNumber = pair.First.PageNumber,

test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.Basic.verified/aichatweb/Services/IngestedDocument.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public class IngestedDocument
1717
public required string DocumentVersion { get; set; }
1818

1919
// The vector is not used but required for some vector databases
20-
[VectorStoreRecordVector(1, DistanceFunction = DistanceFunction.CosineSimilarity)]
21-
public ReadOnlyMemory<float> Vector { get; set; } = new ReadOnlyMemory<float>([0]);
20+
[VectorStoreRecordVector(2, DistanceFunction = DistanceFunction.CosineSimilarity)]
21+
public ReadOnlyMemory<float> Vector { get; set; } = new ReadOnlyMemory<float>([0, 0]);
2222
}

test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.Basic.verified/aichatweb/Services/Ingestion/PDFDirectorySource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Task<IEnumerable<IngestedDocument>> GetNewOrModifiedDocumentsAsync(IReadO
2727
var existingDocumentVersion = existingDocumentsById.TryGetValue(sourceFileId, out var existingDocument) ? existingDocument.DocumentVersion : null;
2828
if (existingDocumentVersion != sourceFileVersion)
2929
{
30-
results.Add(new() { Key = $"{SourceId}_{sourceFileId}", SourceId = SourceId, DocumentId = sourceFileId, DocumentVersion = sourceFileVersion });
30+
results.Add(new() { Key = Guid.CreateVersion7().ToString(), SourceId = SourceId, DocumentId = sourceFileId, DocumentVersion = sourceFileVersion });
3131
}
3232
}
3333

@@ -51,7 +51,7 @@ public async Task<IEnumerable<IngestedChunk>> CreateChunksForDocumentAsync(IEmbe
5151

5252
return paragraphs.Zip(embeddings).Select((pair, index) => new IngestedChunk
5353
{
54-
Key = $"{Path.GetFileNameWithoutExtension(document.DocumentId)}_{pair.First.PageNumber}_{pair.First.IndexOnPage}",
54+
Key = Guid.CreateVersion7().ToString(),
5555
DocumentId = document.DocumentId,
5656
PageNumber = pair.First.PageNumber,
5757
Text = pair.First.Text,

test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.BasicAspire.verified/aichatweb/aichatweb.Web/Services/IngestedDocument.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public class IngestedDocument
1717
public required string DocumentVersion { get; set; }
1818

1919
// The vector is not used but required for some vector databases
20-
[VectorStoreRecordVector(1, DistanceFunction = DistanceFunction.CosineSimilarity)]
21-
public ReadOnlyMemory<float> Vector { get; set; } = new ReadOnlyMemory<float>([0]);
20+
[VectorStoreRecordVector(2, DistanceFunction = DistanceFunction.CosineSimilarity)]
21+
public ReadOnlyMemory<float> Vector { get; set; } = new ReadOnlyMemory<float>([0, 0]);
2222
}

test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.BasicAspire.verified/aichatweb/aichatweb.Web/Services/Ingestion/PDFDirectorySource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Task<IEnumerable<IngestedDocument>> GetNewOrModifiedDocumentsAsync(IReadO
2727
var existingDocumentVersion = existingDocumentsById.TryGetValue(sourceFileId, out var existingDocument) ? existingDocument.DocumentVersion : null;
2828
if (existingDocumentVersion != sourceFileVersion)
2929
{
30-
results.Add(new() { Key = $"{SourceId}_{sourceFileId}", SourceId = SourceId, DocumentId = sourceFileId, DocumentVersion = sourceFileVersion });
30+
results.Add(new() { Key = Guid.CreateVersion7().ToString(), SourceId = SourceId, DocumentId = sourceFileId, DocumentVersion = sourceFileVersion });
3131
}
3232
}
3333

@@ -51,7 +51,7 @@ public async Task<IEnumerable<IngestedChunk>> CreateChunksForDocumentAsync(IEmbe
5151

5252
return paragraphs.Zip(embeddings).Select((pair, index) => new IngestedChunk
5353
{
54-
Key = $"{Path.GetFileNameWithoutExtension(document.DocumentId)}_{pair.First.PageNumber}_{pair.First.IndexOnPage}",
54+
Key = Guid.CreateVersion7().ToString(),
5555
DocumentId = document.DocumentId,
5656
PageNumber = pair.First.PageNumber,
5757
Text = pair.First.Text,

test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.OpenAI_AzureAISearch.verified/aichatweb/Services/IngestedDocument.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ public class IngestedDocument
1717
public required string DocumentVersion { get; set; }
1818

1919
// The vector is not used but required for some vector databases
20-
[VectorStoreRecordVector(1, DistanceFunction = DistanceFunction.CosineSimilarity)]
21-
public ReadOnlyMemory<float> Vector { get; set; } = new ReadOnlyMemory<float>([0]);
20+
[VectorStoreRecordVector(2, DistanceFunction = DistanceFunction.CosineSimilarity)]
21+
public ReadOnlyMemory<float> Vector { get; set; } = new ReadOnlyMemory<float>([0, 0]);
2222
}

test/ProjectTemplates/Microsoft.Extensions.AI.Templates.IntegrationTests/Snapshots/aichatweb.OpenAI_AzureAISearch.verified/aichatweb/Services/Ingestion/PDFDirectorySource.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public Task<IEnumerable<IngestedDocument>> GetNewOrModifiedDocumentsAsync(IReadO
2727
var existingDocumentVersion = existingDocumentsById.TryGetValue(sourceFileId, out var existingDocument) ? existingDocument.DocumentVersion : null;
2828
if (existingDocumentVersion != sourceFileVersion)
2929
{
30-
results.Add(new() { Key = $"{SourceId}_{sourceFileId}", SourceId = SourceId, DocumentId = sourceFileId, DocumentVersion = sourceFileVersion });
30+
results.Add(new() { Key = Guid.CreateVersion7().ToString(), SourceId = SourceId, DocumentId = sourceFileId, DocumentVersion = sourceFileVersion });
3131
}
3232
}
3333

@@ -51,7 +51,7 @@ public async Task<IEnumerable<IngestedChunk>> CreateChunksForDocumentAsync(IEmbe
5151

5252
return paragraphs.Zip(embeddings).Select((pair, index) => new IngestedChunk
5353
{
54-
Key = $"{Path.GetFileNameWithoutExtension(document.DocumentId)}_{pair.First.PageNumber}_{pair.First.IndexOnPage}",
54+
Key = Guid.CreateVersion7().ToString(),
5555
DocumentId = document.DocumentId,
5656
PageNumber = pair.First.PageNumber,
5757
Text = pair.First.Text,

0 commit comments

Comments
 (0)