Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix issue with elasticsearch extension to respect limit and minReleva… #935

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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,57 @@ public KernelMemoryTests(IConfiguration cfg, ITestOutputHelper output)

public IKernelMemory KernelMemory { get; }

[Fact]
[Trait("Category", "Elasticsearch")]
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.SKWikipediaSiliconFileName),
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));

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

//test min 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;
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 SKWikipediaSiliconFileName = "Data/file7-Wikipedia-Silicon.txt";

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