Skip to content

Commit

Permalink
Merge branch 'hotfix/0.9.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
alkampfergit committed Jul 22, 2024
2 parents 4b71b04 + 596f1a8 commit 9770f68
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 32 deletions.
10 changes: 5 additions & 5 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Alkampfer.KernelMemory.Extensions.Interfaces" Version="0.8.0" />
<PackageVersion Include="Elastic.Clients.Elasticsearch" Version="8.13.10" />
<PackageVersion Include="Microsoft.KernelMemory.Abstractions" Version="0.65.240620.1" />
<PackageVersion Include="Elastic.Clients.Elasticsearch" Version="8.14.6" />
<PackageVersion Include="Microsoft.KernelMemory.Abstractions" Version="0.68.240716.1" />
<PackageVersion Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
<PackageVersion Include="Microsoft.KernelMemory.Core" Version="0.65.240620.1" />
<PackageVersion Include="Microsoft.KernelMemory.Core" Version="0.68.240716.1" />
</ItemGroup>
<!-- Test related assemblies -->
<ItemGroup>
<PackageVersion Include="coverlet.msbuild" Version="6.0.2" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageVersion Include="xunit" Version="2.8.1" />
<PackageVersion Include="xunit" Version="2.9.0" />
<PackageVersion Include="xunit.abstractions" Version="2.0.3" />
<PackageVersion Include="Xunit.DependencyInjection" Version="9.3.0" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.1" />
<PackageVersion Include="xunit.runner.visualstudio" Version="2.8.2" />
<PackageVersion Include="coverlet.collector" Version="6.0.2" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ public int CountTokens(string text)
return text.Length;
}

public IReadOnlyList<string> GetTokens(string text)
{
return text.Select(c => c.ToString()).ToArray();
}

public Task<Embedding> GenerateEmbeddingAsync(string text, CancellationToken cancellationToken = default)
{
var hash = text.GetHashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,22 @@ public async Task Can_Create_index_with_mapping()
var tagTemplate = mapping.DynamicTemplates.Single(d => d.Keys.Contains("tags"));
var tagTemplateKey = tagTemplate["tags"];
Assert.NotNull(tagTemplateKey);
Assert.Equal("tag_*", tagTemplateKey.Match);
Assert.Equal("tag_*", tagTemplateKey.Match!.First());

Assert.True(tagTemplateKey.TryGet<TextProperty>(out var tagmapping));

var tagmapping = (TextProperty?)tagTemplateKey.Mapping;
Assert.NotNull(tagmapping);
Assert.Equal("standard", tagmapping.Analyzer);
Assert.Single(tagmapping.Fields!);

//var nalcField = (TextProperty?) tagmapping.Fields!["na"];
//Assert.NotNull(nalcField);
//Assert.Equal("nalc", nalcField.Analyzer);
var nalcField = (KeywordProperty?)tagmapping.Fields!["keyword"];
Assert.NotNull(nalcField);

//verify mapping of the payload properties prefixed with txt
var txtTemplate = mapping.DynamicTemplates.Single(d => d.Keys.Contains("txt"));
var txtTemplateKey = txtTemplate["txt"];
Assert.NotNull(txtTemplateKey);
Assert.Equal("txt_*", txtTemplateKey.Match);
Assert.Equal("txt_*", txtTemplateKey.Match!.First());
}

[Fact]
Expand Down
36 changes: 16 additions & 20 deletions src/KernelMemory.ElasticSearch/ElasticSearchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,12 @@ private ICollection<IDictionary<string, DynamicTemplate>> GetDynamicTemplates()
{
var dt = new List<IDictionary<string, DynamicTemplate>>();
var tags = new Dictionary<string, DynamicTemplate>();
tags["tags"] = new DynamicTemplate
var tagsDynamicMapping = DynamicTemplate.Mapping(new TextProperty
{
Match = "tag_*",
Mapping = new TextProperty
{
Analyzer = "standard",
Index = true,
Store = true,
Fields = new Properties() {
Analyzer = "standard",
Index = true,
Store = true,
Fields = new Properties() {
{ "keyword", new KeywordProperty() },
//{ "na", new TextProperty()
// {

Check warning on line 116 in src/KernelMemory.ElasticSearch/ElasticSearchHelper.cs

View workflow job for this annotation

GitHub Actions / Build and analyze

Remove this commented out code. (https://rules.sonarsource.com/csharp/RSPEC-125)
Expand All @@ -126,28 +123,27 @@ private ICollection<IDictionary<string, DynamicTemplate>> GetDynamicTemplates()
// }
//}
}
},
};
});
tagsDynamicMapping.Match = ["tag_*"];
tags["tags"] = tagsDynamicMapping;
dt.Add(tags);

var txtProp = new Dictionary<string, DynamicTemplate>();
txtProp["txt"] = new DynamicTemplate
var txtDynamicMapping = DynamicTemplate.Mapping(new TextProperty
{
Match = "txt_*",
Mapping = new TextProperty
{
Analyzer = "standard",
Index = true,
Store = true,
Fields = new Properties() {
Analyzer = "standard",
Index = true,
Store = true,
Fields = new Properties() {
//{ "keyword", new KeywordProperty() },
{ "english", new TextProperty() {
Analyzer = "english"
}
}
}
},
};
});
txtDynamicMapping.Match = ["txt_*"];
txtProp["txt"] = txtDynamicMapping;
dt.Add(txtProp);
return dt;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Elastic.Clients.Elasticsearch.QueryDsl;
using Elastic.Clients.Elasticsearch;
using Elastic.Clients.Elasticsearch.QueryDsl;
using Microsoft.KernelMemory;
using System;
using System.Collections.Generic;
Expand Down

0 comments on commit 9770f68

Please sign in to comment.