Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,61 @@ public KernelMemoryTests(IConfiguration cfg, ITestOutputHelper output)

public IKernelMemory KernelMemory { get; }

[Fact]
[Trait("Category", "Elasticsearch")]
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "<Pending>")]
public async Task ItSupportsLimitsAndMinRelevanceScoreAsync()
{
string indexName = nameof(this.ItSupportsLimitsAndMinRelevanceScoreAsync);
this.Output.WriteLine($"Index name: {indexName}");

const string Id = "ItSupportsLimitsAndMinRelevance-file7-Silicon-Carbon.txt";

this.Output.WriteLine("Uploading document");
await this.KernelMemory.ImportDocumentAsync(
new Document(Id)
.AddFile(TestsHelper.SKWikipediaSciliconFileName),
index: indexName,
steps: Constants.PipelineWithoutSummary);

while (!await this.KernelMemory.IsDocumentReadyAsync(documentId: Id, index: indexName))
{
this.Output.WriteLine("Waiting for memory ingestion to complete...");
await Task.Delay(TimeSpan.FromSeconds(2));
}

//no minRelevance or limit:
var results = await this.KernelMemory.SearchAsync("What is Silicon?", index: indexName, null, null, minRelevance: 0, limit: -1);

Assert.True((results.Results.Count > 0));
var partitions = results.Results[0].Partitions;
var maxRelevance = partitions.Max(p => p.Relevance);
var minRelevance = partitions.Min(p => p.Relevance);

this.Output.WriteLine($"{partitions.Count}, Max Relevance: {maxRelevance}, Min Relevance: {minRelevance}");
Assert.True((partitions.Count > 5));
Assert.True((minRelevance < 0.82));

//limit 5:
results = await this.KernelMemory.SearchAsync("What is Silicon?", index: indexName, null, null, minRelevance: 0, limit: 5);
partitions = results.Results[0].Partitions;
maxRelevance = partitions.Max(p => p.Relevance);
minRelevance = partitions.Min(p => p.Relevance);
Assert.True((partitions.Count == 5));

//relevance 0.82:
results = await this.KernelMemory.SearchAsync("What is Silicon?", index: indexName, null, null, minRelevance: 0.82, limit: 10);
partitions = results.Results[0].Partitions;
maxRelevance = partitions.Max(p => p.Relevance);
minRelevance = partitions.Min(p => p.Relevance);
Assert.True((minRelevance > 0.82));

await this.KernelMemory.DeleteDocumentAsync(Id, index: indexName);

this.Output.WriteLine("Deleting index");
await this.KernelMemory.DeleteIndexAsync(indexName);
}

[Fact]
[Trait("Category", "Elasticsearch")]
[SuppressMessage("Reliability", "CA2007:Consider calling ConfigureAwait on the awaited task", Justification = "<Pending>")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ internal static class TestsHelper
public const string LoremIpsumFileName = "Data/file3-lorem-ipsum.docx";
public const string NASANewsFileName = "data/file5-NASA-news.pdf";
public const string SKReadmeFileName = "Data/file4-SK-Readme.pdf";
public const string SKWikipediaSciliconFileName = "Data/file7-Wikipedia-Silicon.txt";

/// <summary>
/// Deletes all indices that are created by all test methods of the given class.
Expand Down
Loading
Loading