Fixed Semantic Search leaving out passages that did not fit into a search (#1167)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-05 16:02:59 +01:00
1 parent 0a178cb1a3
commit 7342c436dd
17 files changed
+1065 -111

No files matched your search

@@ -11,8 +11,8 @@ namespace AIStudio.Tests.Tools.ToolCalling;
/// </summary>
/// <remarks>
/// The model may only search the data sources offered to it, and it may only turn pages where
/// that means something: in one data source at a time, and not beyond the window the data sources
/// fetch at most. Every refusal says what would have been right, so that the model can correct
/// that means something: in one data source at a time, and not beyond what a data source can
/// return at all. Every refusal says what would have been right, so that the model can correct
/// itself with its next call.
/// </remarks>
[TestFixture]
@@ -95,17 +95,24 @@ public sealed class SemanticSearchToolRequestTests
}
[Test]
public void APageBeyondTheWindowIsRefusedWithTheLastPage()
public void APageBeyondWhatADataSourceCanReturnIsRefused()
{
var message = Refusal(() => SemanticSearchTool.ReadRequest(Arguments($$"""{"query":"travel expenses","data_source_ids":["{{HANDBOOK.Id}}"],"page":10}"""), OFFERED));
Assert.That(message, Does.Contain("at most 9").And.Contain("but was 10").And.Contain("Rephrase the query"));
// Nine pages of the data source with ten matches each, and at least one passage per page of the search:
var message = Refusal(() => SemanticSearchTool.ReadRequest(Arguments($$"""{"query":"travel expenses","data_source_ids":["{{HANDBOOK.Id}}"],"page":91}"""), OFFERED));
Assert.That(message, Does.Contain("at most 90").And.Contain("but was 91").And.Contain("Rephrase the query"));
}
[Test]
public void AnERIDataSourceHasNoFurtherPage()
public void AnERIDataSourcePagesWithinItsMatches()
{
var message = Refusal(() => SemanticSearchTool.ReadRequest(Arguments($$"""{"query":"travel expenses","data_source_ids":["{{INTRANET.Id}}"],"page":2}"""), OFFERED));
Assert.That(message, Does.Contain("at most 1").And.Contain("but was 2").And.Contain("Rephrase the query"), "A server which allows only the configured number of matches would refuse the page, and the data source would count as not searched.");
var request = SemanticSearchTool.ReadRequest(Arguments($$"""{"query":"travel expenses","data_source_ids":["{{INTRANET.Id}}"],"page":10}"""), OFFERED);
var message = Refusal(() => SemanticSearchTool.ReadRequest(Arguments($$"""{"query":"travel expenses","data_source_ids":["{{INTRANET.Id}}"],"page":11}"""), OFFERED));
using (Assert.EnterMultipleScope())
{
Assert.That(request.Page, Is.EqualTo(10), "The matches the server returns may fill several pages, one of them each at the least.");
Assert.That(message, Does.Contain("at most 10").And.Contain("but was 11"), "ERI v1 knows no offset, so there is no page beyond the configured number of matches.");
}
}
private static JsonElement Arguments(string json) => JsonSerializer.Deserialize<JsonElement>(json);