mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2026-11-04 10:48:23 +00:00
Avoided needless Semantic Search calls when no data source can be searched (#1108)
This commit is contained in:
1 parent
8d9b15bd5f
commit
d26139936a
8 files changed
+92
-33
No files matched your search
@@ -2,6 +2,7 @@ using AIStudio.Settings;
|
||||
using AIStudio.Settings.DataModel;
|
||||
using AIStudio.Tools;
|
||||
using AIStudio.Tools.RAG.RAGProcesses;
|
||||
using AIStudio.Tools.ToolCallingSystem.ToolCallingImplementations.SemanticSearch;
|
||||
|
||||
namespace AIStudio.Tests.Tools;
|
||||
|
||||
@@ -12,11 +13,13 @@ namespace AIStudio.Tests.Tools;
|
||||
/// Such a data source is never searched. Without a word about it, the model would take its silence
|
||||
/// for finding nothing and answer from its own knowledge. Semantic Search names it in the
|
||||
/// description of its tool, the classic process next to the passages it found, and both name the
|
||||
/// same data sources of the chat.
|
||||
/// same data sources of the chat. When Semantic Search has nothing to search, its tool stays out,
|
||||
/// and the classic process writes the note into the system prompt while it steps back.
|
||||
/// </remarks>
|
||||
[TestFixture]
|
||||
public sealed class ClassicRagUnreachableTests
|
||||
{
|
||||
private static readonly IDataSource HANDBOOK = new DataSourceLocalDirectory { Num = 1, Id = "11111111-1111-1111-1111-111111111111", Name = "Handbook", MaxMatches = 10 };
|
||||
private static readonly IDataSource INTRANET = new DataSourceERI_V1 { Num = 3, Id = "33333333-3333-3333-3333-333333333333", Name = "Intranet", MaxMatches = 10 };
|
||||
private static readonly IDataSource WIKI = new DataSourceERI_V1 { Num = 4, Id = "44444444-4444-4444-4444-444444444444", Name = "Wiki", MaxMatches = 10 };
|
||||
|
||||
@@ -77,5 +80,27 @@ public sealed class ClassicRagUnreachableTests
|
||||
Assert.That(Checked([silent]).GetUnreachableOfTheChat(new DataSourceOptions { AutomaticDataSourceSelection = true }), Is.Empty, "It would add nothing even when its server answers.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithoutSearchableDataSourcesTheSystemPromptNamesTheUnreachableOnes()
|
||||
{
|
||||
var note = AISrcSelWithRetCtxVal.NoteWithoutSearchableDataSources(new OfferedDataSources([], [INTRANET]));
|
||||
|
||||
Assert.That(note, Does.Contain("- name='Intranet'"), "Semantic Search stays out of the request, so nothing else tells the model what is missing.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WhileTheModelCanSearchTheSystemPromptStaysAsItWas()
|
||||
{
|
||||
var note = AISrcSelWithRetCtxVal.NoteWithoutSearchableDataSources(new OfferedDataSources([HANDBOOK], [INTRANET]));
|
||||
|
||||
Assert.That(note, Is.Empty, "The description of the tool names the unreachable data sources already.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithoutAnyDataSourceTheSystemPromptStaysAsItWas()
|
||||
{
|
||||
Assert.That(AISrcSelWithRetCtxVal.NoteWithoutSearchableDataSources(OfferedDataSources.NONE), Is.Empty);
|
||||
}
|
||||
|
||||
private static AllowedSelectedDataSources Checked(IReadOnlyList<IDataSource> unreachable) => new([], [], [], [], unreachable);
|
||||
}
|
||||
@@ -100,19 +100,6 @@ public sealed class SemanticSearchToolDescriptionTests
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnlyUnreachableDataSourcesStillMakeAFunction()
|
||||
{
|
||||
var function = DescribeWithUnreachable([], [INTRANET]);
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(function.DescriptionForLLM, Does.Contain("None of the data sources of this chat can be searched right now."));
|
||||
Assert.That(function.DescriptionForLLM, Does.Contain("- name='Intranet'"));
|
||||
Assert.That(function.DescriptionForLLM, Does.Not.Contain("The data sources you may search"));
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void WithoutUnreachableDataSourcesTheDescriptionStaysAsBefore()
|
||||
{
|
||||
|
||||
@@ -55,6 +55,19 @@ public sealed class SemanticSearchToolUnreachableTests
|
||||
Assert.That(offered.IsEmpty, Is.True, "A data source configured to return no matches is not offered when it answers, either.");
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void OnlyUnreachableDataSourcesKeepTheToolOut()
|
||||
{
|
||||
var options = new DataSourceOptions { AutomaticDataSourceSelection = false, PreselectedDataSourceIds = [INTRANET.Id] };
|
||||
var offered = SemanticSearchTool.SelectOffered(options, Checked([HANDBOOK], [], [INTRANET]));
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
Assert.That(offered.IsSearchable, Is.False, "The model would search all the same, and every such call costs a round of the answer for nothing.");
|
||||
Assert.That(offered.Unreachable, Is.EqualTo(new[] { INTRANET }), "The model still has to learn what is missing, then through the system prompt.");
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ASearchOfAllDataSourcesReportsTheUnreachableOnes()
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user