Skip to content

Commit 68a68e8

Browse files
Bold Create AgentVinothSF5015
andcommitted
Use unique chunk ids and verify stored rows
Co-authored-by: VinothSF5015 <197725877+VinothSF5015@users.noreply.github.com>
1 parent 4a80afd commit 68a68e8

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

  • Document_Chunking1_New/AgentRAGWithAzure 1/AgentRAGWithAzure/Services

‎Document_Chunking1_New/AgentRAGWithAzure 1/AgentRAGWithAzure/Services/RagService.cs‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ await GenerateEmbeddingAsync(
280280
records.Add(
281281
new LocalChunkRecord
282282
{
283-
Id = chunk.ChunkId,
283+
// The chunker's ChunkId may repeat across documents, which made
284+
// ON CONFLICT (id) overwrite other rows. Make it unique per file.
285+
Id = $"{Guid.NewGuid():N}",
284286

285287
// Use the filename consistently for delete and insert.
286288
SourceName = safeFileName,
@@ -680,6 +682,20 @@ DO UPDATE SET
680682
await insertCommand.ExecuteNonQueryAsync();
681683
}
682684

685+
await using NpgsqlCommand countCommand = new(
686+
"SELECT count(*) FROM rag_chunks WHERE lower(source_name) = lower($1);",
687+
connection,
688+
transaction);
689+
countCommand.Parameters.AddWithValue(sourceName);
690+
long stored = Convert.ToInt64(await countCommand.ExecuteScalarAsync());
691+
Console.WriteLine($"rag_chunks now holds {stored} rows for '{sourceName}'.");
692+
693+
if (stored != records.Count)
694+
{
695+
throw new InvalidOperationException(
696+
$"Expected {records.Count} chunks in the database for '{sourceName}' but found {stored}.");
697+
}
698+
683699
await transaction.CommitAsync();
684700
}
685701
catch

0 commit comments

Comments
 (0)