Fixed Semantic Search with external data sources (ERI servers) (#1090)

Co-authored-by: Thorsten Sommer <SommerEngineering@users.noreply.github.com>
This commit is contained in:
Peer HogeterpandThorsten Sommer authored and GitHub committed 2026-10-20 16:24:55 +02:00
1 parent 0f5b041729
commit f6e48e95f3
30 files changed
+1370 -141

No files matched your search

@@ -24,6 +24,9 @@ public static class IRetrievalContextExtensions
{
contextBuilder.AppendLine($"Data source name: {retrievalContext.DataSourceName}");
contextBuilder.AppendLine($"Content category: {retrievalContext.Category}");
if(!string.IsNullOrWhiteSpace(retrievalContext.SourceCategory))
contextBuilder.AppendLine($"Source category: {retrievalContext.SourceCategory.ReplaceLineEndings(" ").Trim()}");
contextBuilder.AppendLine($"Content type: {retrievalContext.Type}");
contextBuilder.AppendLine($"Content path: {retrievalContext.Path}");
@@ -38,6 +41,22 @@ public static class IRetrievalContextExtensions
contextBuilder.AppendLine($"- {link}");
}
/// <summary>
/// Writes what the AI is told about an image which matched, in place of the image itself.
/// </summary>
/// <remarks>
/// The image is not passed on. Written as base64 text, it is nothing a model can look at, and
/// a single image would take more room than all other passages together: Semantic Search
/// left it out for its size, and the classic RAG process sent it along with every message.
/// The description above still tells where the image is, so the model can point the user to it.
/// </remarks>
/// <param name="contextBuilder">The builder to write into, after the description of the context.</param>
internal static void AppendImageMatch(StringBuilder contextBuilder)
{
contextBuilder.AppendLine();
contextBuilder.AppendLine("Matched image content: an image matched here, but it is not shown to you. Do not guess what it shows. When it matters for the answer, tell the user that an image matched, and where to find it, using the path and the links above.");
}
/// <summary>
/// Writes what the AI is told about several retrieval contexts, filtered for prompt injections.
/// </summary>
@@ -126,20 +145,9 @@ public static class IRetrievalContextExtensions
await FilterWhatWeHaveSoFar();
break;
case RetrievalImageContext imageContext:
//
// Filtering happens before the image is appended, and only covers the text
// around it. Base64 image data is not prose, and running it through the filter
// would have it treated as one enormous encoded carrier.
//
case RetrievalImageContext:
AppendImageMatch(contextBuilder);
await FilterWhatWeHaveSoFar();
contextBuilder.AppendLine();
contextBuilder.AppendLine("Matched image content as base64-encoded data:");
contextBuilder.AppendLine("````");
contextBuilder.AppendLine(await imageContext.TryAsBase64(token) is (success: true, { } base64Image)
? base64Image
: string.Empty);
contextBuilder.AppendLine("````");
break;
default: