From ddc8ab8791000ee89072c4e55938b769be139f12 Mon Sep 17 00:00:00 2001 From: Marco Minerva Date: Tue, 1 Jul 2025 16:21:25 +0200 Subject: [PATCH] Enhance documentation and update DocumentChunk model Updated `copilot-instructions.md` to include new guidelines for Markdown documentation and testing practices. Modified the `DocumentChunk` record in `DocumentChunk.cs` to add `PageNumber` and `IndexOnPage` properties. Adjusted `GetChunksAsync` and `GetChunkEmbeddingAsync` methods in `DocumentService.cs` to accommodate the new properties. --- .github/copilot-instructions.md | 6 +++++- SqlDatabaseVectorSearch/Models/DocumentChunk.cs | 2 +- SqlDatabaseVectorSearch/Services/DocumentService.cs | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index db62f9d..8a7fce7 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -4,7 +4,7 @@ - Always use the latest version C#, currently C# 13 features. - Write code that is clean, maintainable, and easy to understand. - Only add comments rarely to explain why a non-intuitive solution was used. The code should be self-explanatory otherwise. -- Don't add the UTF-8 BOM to files unless they have non-ASCII characters +- Don't add the UTF-8 BOM to files unless they have non-ASCII characters. - Never change global.json unless explicitly asked to. - Never change package.json or package-lock.json files unless explicitly asked to. - Never change NuGet.config files unless explicitly asked to. @@ -69,6 +69,10 @@ - Include code examples in documentation where appropriate. - Overriding members should inherit the XML documentation from the base type via `/// `. +## Markdown +- Use Markdown for documentation files (e.g., README.md). +- Use triple backticks for code blocks, JSON snippets and bash commands, specifying the language (e.g., ```csharp, ```json and ```bash). + ## Testing - When adding new unit tests, strongly prefer to add them to existing test code files rather than creating new code files. diff --git a/SqlDatabaseVectorSearch/Models/DocumentChunk.cs b/SqlDatabaseVectorSearch/Models/DocumentChunk.cs index 3753352..d1076f6 100644 --- a/SqlDatabaseVectorSearch/Models/DocumentChunk.cs +++ b/SqlDatabaseVectorSearch/Models/DocumentChunk.cs @@ -1,3 +1,3 @@ namespace SqlDatabaseVectorSearch.Models; -public record class DocumentChunk(Guid Id, int Index, string Content, float[]? Embedding = null); +public record class DocumentChunk(Guid Id, int Index, string Content, int? PageNumber, int IndexOnPage, float[]? Embedding = null); diff --git a/SqlDatabaseVectorSearch/Services/DocumentService.cs b/SqlDatabaseVectorSearch/Services/DocumentService.cs index 1955255..a8aca12 100644 --- a/SqlDatabaseVectorSearch/Services/DocumentService.cs +++ b/SqlDatabaseVectorSearch/Services/DocumentService.cs @@ -19,7 +19,7 @@ public class DocumentService(ApplicationDbContext dbContext) public async Task> GetChunksAsync(Guid documentId, CancellationToken cancellationToken = default) { var documentChunks = await dbContext.DocumentChunks.Where(c => c.DocumentId == documentId).OrderBy(c => c.Index) - .Select(c => new DocumentChunk(c.Id, c.Index, c.Content, null)) + .Select(c => new DocumentChunk(c.Id, c.Index, c.Content, c.PageNumber, c.IndexOnPage, null)) .ToListAsync(cancellationToken); return documentChunks; @@ -28,7 +28,7 @@ public class DocumentService(ApplicationDbContext dbContext) public async Task GetChunkEmbeddingAsync(Guid documentId, Guid documentChunkId, CancellationToken cancellationToken = default) { var documentChunk = await dbContext.DocumentChunks.Where(c => c.Id == documentChunkId && c.DocumentId == documentId) - .Select(c => new DocumentChunk(c.Id, c.Index, c.Content, c.Embedding)) + .Select(c => new DocumentChunk(c.Id, c.Index, c.Content, c.PageNumber, c.IndexOnPage, c.Embedding)) .FirstOrDefaultAsync(cancellationToken); return documentChunk;