Tell whoever asked for a page what the search could not cover

This commit is contained in:
Thorsten Sommer committed 2026-09-24 15:33:50 +02:00
1 parent 92339479d0
commit 90db777ad5
6 files changed
+168 -31

No files matched your search

@@ -85,7 +85,7 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
_ => string.Empty
};
return await this.RetrieveDataAsync(latestUserPrompt, lastUserPrompt.ToERIContentType, thread, this.MaxMatches, token);
return await this.RetrieveDataAsync(latestUserPrompt, lastUserPrompt.ToERIContentType, thread, this.MaxMatches, token) ?? [];
}
/// <inheritdoc />
@@ -103,11 +103,15 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
// returns fewer matches than asked for ends the paging early, which errs on the safe side.
//
var contexts = await this.RetrieveDataAsync(query, ContentType.TEXT, thread, window, token);
if (contexts is null)
return RetrievalPage.EMPTY with { Gaps = [RetrievalGap.NOT_SEARCHED] };
var (pageContexts, hasMore) = RetrievalPaging.Cut(contexts, page, this.MaxMatches);
return new RetrievalPage(pageContexts, hasMore);
}
private async Task<IReadOnlyList<IRetrievalContext>> RetrieveDataAsync(string latestUserPrompt, ContentType latestUserPromptType, ChatThread thread, int maxMatches, CancellationToken token)
/// <returns>What the ERI server found, or null when it could not be searched.</returns>
private async Task<IReadOnlyList<IRetrievalContext>?> RetrieveDataAsync(string latestUserPrompt, ContentType latestUserPromptType, ChatThread thread, int maxMatches, CancellationToken token)
{
// Important: Do not dispose the RustService here, as it is a singleton.
var rustService = Program.SERVICE_PROVIDER.GetRequiredService<RustService>();
@@ -175,11 +179,11 @@ public readonly record struct DataSourceERI_V1 : IERIDataSource
}
logger.LogWarning($"Was not able to retrieve data from the ERI data source '{this.Name}'. Message: {retrievalResponse.Message}");
return [];
return null;
}
logger.LogWarning($"Was not able to authenticate with the ERI data source '{this.Name}'. Message: {authResponse.Message}");
return [];
return null;
}
public static bool TryParseConfiguration(int idx, LuaTable table, Guid configPluginId, out DataSourceERI_V1 dataSource)
@@ -43,12 +43,16 @@ public interface IDataSource : IConfigurationObject
/// lets the model work it out from the conversation, and search as often as it takes. The first
/// page holds what the retrieval above finds for the same text. How the pages are cut is
/// described in RetrievalPaging.
///
/// Since the user did not write the query, the user is not told about problems with it. They
/// arrive in RetrievalPage.Gaps instead, together with everything else which kept the search
/// from covering the whole data source.
/// </remarks>
/// <param name="query">What to search for.</param>
/// <param name="page">The page to retrieve, from 1 up to RetrievalPaging.GetLastPage for MaxMatches.</param>
/// <param name="thread">The chat thread.</param>
/// <param name="token">The cancellation token.</param>
/// <returns>The retrieved data contexts of this page, and whether the next page is worth asking for.</returns>
/// <returns>The retrieved data contexts of this page, whether the next page is worth asking for, and what the search could not cover.</returns>
/// <exception cref="ArgumentOutOfRangeException">The page is below 1 or beyond the last page.</exception>
public Task<RetrievalPage> RetrieveDataAsync(string query, int page, ChatThread thread, CancellationToken token = default);
}