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.
This commit is contained in:
Marco Minerva
2025-07-01 16:21:25 +02:00
parent b971b6bf05
commit ddc8ab8791
3 changed files with 8 additions and 4 deletions
+5 -1
View File
@@ -4,7 +4,7 @@
- Always use the latest version C#, currently C# 13 features. - Always use the latest version C#, currently C# 13 features.
- Write code that is clean, maintainable, and easy to understand. - 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. - 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 global.json unless explicitly asked to.
- Never change package.json or package-lock.json files 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. - Never change NuGet.config files unless explicitly asked to.
@@ -69,6 +69,10 @@
- Include code examples in documentation where appropriate. - Include code examples in documentation where appropriate.
- Overriding members should inherit the XML documentation from the base type via `/// <inheritdoc />`. - Overriding members should inherit the XML documentation from the base type via `/// <inheritdoc />`.
## 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 ## Testing
- When adding new unit tests, strongly prefer to add them to existing test code files rather than creating new code files. - When adding new unit tests, strongly prefer to add them to existing test code files rather than creating new code files.
@@ -1,3 +1,3 @@
namespace SqlDatabaseVectorSearch.Models; 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);
@@ -19,7 +19,7 @@ public class DocumentService(ApplicationDbContext dbContext)
public async Task<IEnumerable<DocumentChunk>> GetChunksAsync(Guid documentId, CancellationToken cancellationToken = default) public async Task<IEnumerable<DocumentChunk>> GetChunksAsync(Guid documentId, CancellationToken cancellationToken = default)
{ {
var documentChunks = await dbContext.DocumentChunks.Where(c => c.DocumentId == documentId).OrderBy(c => c.Index) 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); .ToListAsync(cancellationToken);
return documentChunks; return documentChunks;
@@ -28,7 +28,7 @@ public class DocumentService(ApplicationDbContext dbContext)
public async Task<DocumentChunk?> GetChunkEmbeddingAsync(Guid documentId, Guid documentChunkId, CancellationToken cancellationToken = default) public async Task<DocumentChunk?> GetChunkEmbeddingAsync(Guid documentId, Guid documentChunkId, CancellationToken cancellationToken = default)
{ {
var documentChunk = await dbContext.DocumentChunks.Where(c => c.Id == documentChunkId && c.DocumentId == documentId) 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); .FirstOrDefaultAsync(cancellationToken);
return documentChunk; return documentChunk;