From f474d8fe82303fdd9c1452b76bf210e4a23c5b89 Mon Sep 17 00:00:00 2001 From: Marco Minerva Date: Fri, 24 Jul 2026 17:38:12 +0200 Subject: [PATCH] Add Response ctor overload, agent Ids, and metadata fields - Added a new Response constructor overload for simpler instantiation with conversationId, streamState, and optional tokenUsageResponse. - Updated AddAIAgent registrations for "ReformulationAgent" and "RagAgent" to set Id to the lower-cased key. - Modified VectorSearchService to use the new Response constructor, omitting now-optional parameters. - Enhanced ContextProvider: TextSearchResult now includes a RawRepresentation property with chunk metadata (Id, DocumentId, PageNumber, IndexOnPage, Content). --- SqlDatabaseVectorSearch/Models/Response.cs | 5 +++++ SqlDatabaseVectorSearch/Program.cs | 2 ++ SqlDatabaseVectorSearch/Services/VectorSearchService.cs | 3 ++- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/SqlDatabaseVectorSearch/Models/Response.cs b/SqlDatabaseVectorSearch/Models/Response.cs index 3aed02f..a80b2ec 100644 --- a/SqlDatabaseVectorSearch/Models/Response.cs +++ b/SqlDatabaseVectorSearch/Models/Response.cs @@ -7,4 +7,9 @@ public record class Response(Guid ConversationId, string? OriginalQuestion, stri : this(conversationId, null, null, token, streamState, tokenUsageResponse) { } + + public Response(Guid conversationId, StreamState streamState, TokenUsageResponse? tokenUsageResponse = null) + : this(conversationId, null, null, null, streamState, tokenUsageResponse) + { + } } \ No newline at end of file diff --git a/SqlDatabaseVectorSearch/Program.cs b/SqlDatabaseVectorSearch/Program.cs index e88cd6c..7217fe8 100644 --- a/SqlDatabaseVectorSearch/Program.cs +++ b/SqlDatabaseVectorSearch/Program.cs @@ -117,6 +117,7 @@ builder.Services.AddAIAgent("ReformulationAgent", (services, key) => return chatClient.AsAIAgent(new ChatClientAgentOptions() { + Id = key.ToLowerInvariant(), Name = key, ChatOptions = new() { @@ -209,6 +210,7 @@ builder.Services.AddAIAgent("RagAgent", (services, key) => return chatClient.AsAIAgent(new ChatClientAgentOptions { + Id = key.ToLowerInvariant(), Name = key, ChatOptions = new() { diff --git a/SqlDatabaseVectorSearch/Services/VectorSearchService.cs b/SqlDatabaseVectorSearch/Services/VectorSearchService.cs index 1668fe7..2c19f40 100644 --- a/SqlDatabaseVectorSearch/Services/VectorSearchService.cs +++ b/SqlDatabaseVectorSearch/Services/VectorSearchService.cs @@ -84,7 +84,7 @@ public partial class VectorSearchService([FromKeyedServices("EmbeddingWorkflow") await sessionStore.SaveSessionAsync(ragAgent, question.ConversationId.ToString(), session, cancellationToken); var response = updates.ToAgentResponse(); - yield return new(question.ConversationId, null, null, response.Text, StreamState.End, new TokenUsageResponse(null, response.Usage)); + yield return new(question.ConversationId, StreamState.End, new TokenUsageResponse(null, response.Usage)); } } @@ -105,6 +105,7 @@ public class ContextProvider(ApplicationDbContext dbContext, IEmbeddingGenerator SourceLink = c.Id.ToString().ToLowerInvariant(), SourceName = c.Document.Name, Text = c.Content, + RawRepresentation = new { c.Id, c.DocumentId, c.PageNumber, c.IndexOnPage, c.Content } }) .ToListAsync(cancellationToken);