diff --git a/Directory.Packages.props b/Directory.Packages.props index da459a1..efaf319 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -3,16 +3,15 @@ true true - - - + + - + - \ No newline at end of file + diff --git a/Elastic.SemanticKernel.Connectors.Elasticsearch/ElasticsearchVectorStoreCollectionSearchMapping.cs b/Elastic.SemanticKernel.Connectors.Elasticsearch/ElasticsearchVectorStoreCollectionSearchMapping.cs index 6df8e82..9fe88bf 100644 --- a/Elastic.SemanticKernel.Connectors.Elasticsearch/ElasticsearchVectorStoreCollectionSearchMapping.cs +++ b/Elastic.SemanticKernel.Connectors.Elasticsearch/ElasticsearchVectorStoreCollectionSearchMapping.cs @@ -62,7 +62,7 @@ public static ICollection BuildFilter(VectorSearchFilter? basicVectorSear filterQueries.Add(Query.Terms(new TermsQuery { Field = mapping.Value!, - Term = new TermsQueryField([FieldValueFromValue(anyTagEqualToClause.Value)]) + Terms = new TermsQueryField([FieldValueFromValue(anyTagEqualToClause.Value)]) })); break; diff --git a/Elastic.SemanticKernel.Connectors.Elasticsearch/ElasticsearchVectorStoreRecordCollection.cs b/Elastic.SemanticKernel.Connectors.Elasticsearch/ElasticsearchVectorStoreRecordCollection.cs index fa284f5..7603e53 100644 --- a/Elastic.SemanticKernel.Connectors.Elasticsearch/ElasticsearchVectorStoreRecordCollection.cs +++ b/Elastic.SemanticKernel.Connectors.Elasticsearch/ElasticsearchVectorStoreRecordCollection.cs @@ -307,7 +307,7 @@ public async Task> VectorizedSearchAsync(T // Validate inputs. - if (this._propertyReader.FirstVectorPropertyName is null) + if (_propertyReader.FirstVectorPropertyName is null) { throw new InvalidOperationException("The collection does not have any vector fields, so vector search is not possible."); } diff --git a/Elastic.SemanticKernel.Connectors.Elasticsearch/MockableElasticsearchClient.cs b/Elastic.SemanticKernel.Connectors.Elasticsearch/MockableElasticsearchClient.cs index 3d46868..b1632ab 100644 --- a/Elastic.SemanticKernel.Connectors.Elasticsearch/MockableElasticsearchClient.cs +++ b/Elastic.SemanticKernel.Connectors.Elasticsearch/MockableElasticsearchClient.cs @@ -17,6 +17,8 @@ using Microsoft.SemanticKernel; +using ExistsRequest = Elastic.Clients.Elasticsearch.IndexManagement.ExistsRequest; + namespace Elastic.SemanticKernel.Connectors.Elasticsearch; #pragma warning disable CA1852 // TODO: Remove after using MockableElasticsearchClient in unit tests @@ -27,6 +29,11 @@ namespace Elastic.SemanticKernel.Connectors.Elasticsearch; /// internal class MockableElasticsearchClient { + private static readonly RequestConfiguration CustomUserAgentRequestConfiguration = new RequestConfiguration + { + UserAgent = UserAgent.Create("elasticsearch-net", typeof(IElasticsearchClientSettings), ["integration=MSSK"]) + }; + /// /// Initializes a new instance of the class. /// @@ -38,18 +45,7 @@ public MockableElasticsearchClient(ElasticsearchClient elasticsearchClient) { Verify.NotNull(elasticsearchClient); - // Create a private instance of the ElasticsearchClient based on the settings of the original instance. - - if (elasticsearchClient.ElasticsearchClientSettings is not ElasticsearchClientSettings settings) - { - throw new NotSupportedException("Unsupported Elasticsearch client instance."); - } - - // TODO: Clone Settings - - settings.UserAgent(UserAgent.Create($"{elasticsearchClient.ElasticsearchClientSettings.UserAgent}; integration=MSSK")); - - ElasticsearchClient = new ElasticsearchClient(settings); + ElasticsearchClient = elasticsearchClient; } #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable. @@ -77,7 +73,12 @@ internal MockableElasticsearchClient() public virtual async Task> ListIndicesAsync(CancellationToken cancellationToken = default) { var response = await ElasticsearchClient.Indices - .StatsAsync(cancellationToken) + .StatsAsync( + new IndicesStatsRequest + { + RequestConfiguration = CustomUserAgentRequestConfiguration + }, + cancellationToken) .ConfigureAwait(false); if (!response.IsSuccess()) @@ -102,7 +103,12 @@ public virtual async Task IndexExistsAsync( Verify.NotNull(indexName); var response = await ElasticsearchClient.Indices - .ExistsAsync(indexName, cancellationToken) + .ExistsAsync( + new ExistsRequest(indexName) + { + RequestConfiguration = CustomUserAgentRequestConfiguration + }, + cancellationToken) .ConfigureAwait(false); if (!response.IsSuccess()) @@ -129,13 +135,15 @@ public virtual async Task CreateIndexAsync( Verify.NotNull(indexName); var response = await ElasticsearchClient.Indices - .CreateAsync(new CreateIndexRequest(indexName) - { - Mappings = new TypeMapping + .CreateAsync( + new CreateIndexRequest(indexName) { - Properties = properties - } - }, + Mappings = new TypeMapping + { + Properties = properties + }, + RequestConfiguration = CustomUserAgentRequestConfiguration + }, cancellationToken) .ConfigureAwait(false); @@ -158,7 +166,12 @@ public virtual async Task DeleteIndexAsync( { Verify.NotNull(indexName); - var response = await ElasticsearchClient.Indices.DeleteAsync(indexName, cancellationToken) + var response = await ElasticsearchClient.Indices.DeleteAsync( + new DeleteIndexRequest(indexName) + { + RequestConfiguration = CustomUserAgentRequestConfiguration + }, + cancellationToken) .ConfigureAwait(false); if (!response.IsSuccess()) @@ -176,7 +189,12 @@ public virtual async Task DeleteIndexAsync( Verify.NotNull(id); var response = await ElasticsearchClient - .GetAsync(indexName, id, x => { }, cancellationToken) + .GetAsync( + new GetRequest(indexName, id) + { + RequestConfiguration = CustomUserAgentRequestConfiguration + }, + cancellationToken) .ConfigureAwait(false); if (!response.IsSuccess()) @@ -212,7 +230,12 @@ public virtual async Task IndexDocumentAsync( Verify.NotNull(document); var response = await ElasticsearchClient - .IndexAsync(document, indexName, id, cancellationToken) + .IndexAsync( + new IndexRequest(document, indexName, id) + { + RequestConfiguration = CustomUserAgentRequestConfiguration + }, + cancellationToken) .ConfigureAwait(false); if (!response.IsSuccess()) @@ -240,7 +263,12 @@ public virtual async Task DeleteDocumentAsync( Verify.NotNull(id); var response = await ElasticsearchClient - .DeleteAsync(indexName, id, cancellationToken) + .DeleteAsync( + new DeleteRequest(indexName, id) + { + RequestConfiguration = CustomUserAgentRequestConfiguration + }, + cancellationToken) .ConfigureAwait(false); if (!response.IsSuccess()) @@ -270,11 +298,16 @@ public virtual async Task DeleteDocumentAsync( Verify.NotNull(query); var response = await ElasticsearchClient - .SearchAsync(indexName, x => x - .Query(query) - .From(from) - .Size(size), - cancellationToken) + .SearchAsync( + new SearchRequest(indexName) + { + Query = query, + From = from, + Size = size, + RequestConfiguration = CustomUserAgentRequestConfiguration + }, + cancellationToken + ) .ConfigureAwait(false); if (!response.IsSuccess()) diff --git a/Elastic.SemanticKernel.Connectors.Elasticsearch/packages.lock.json b/Elastic.SemanticKernel.Connectors.Elasticsearch/packages.lock.json index cdc8f6f..0a5d8b3 100644 --- a/Elastic.SemanticKernel.Connectors.Elasticsearch/packages.lock.json +++ b/Elastic.SemanticKernel.Connectors.Elasticsearch/packages.lock.json @@ -4,18 +4,24 @@ ".NETStandard,Version=v2.0": { "Elastic.Clients.Elasticsearch": { "type": "Direct", - "requested": "[8.15.10, )", - "resolved": "8.15.10", - "contentHash": "WxbKk/PvNOhhGLkaqdrQwNWxiDtOYQJYZK6VwOkV65r7kQO+cpmjkYr/FoJ4ArfHFzZJf77VHNyvFSWDe3Vqzw==", + "requested": "[8.16.1, )", + "resolved": "8.16.1", + "contentHash": "IIqNXo1hS15aXSfr3f+QzYJqj7k01vx075VJT4d4/oQdpN4HL3IRfnhcgPHMVQSuAw8bY5l3FSztGHT54AwgtQ==", "dependencies": { - "Elastic.Transport": "0.4.26" + "Elastic.Transport": "0.5.5" } }, + "Microsoft.Build.CopyOnWrite": { + "type": "Direct", + "requested": "[1.0.334, )", + "resolved": "1.0.334", + "contentHash": "Bi/e5guuwmyPL7Kp1G+PbcDvZFKsZxuHmc39IpYHAhWOvV8I/uIHPwAZ++Fa8k/w6pEqPdHCIrxSCelMNmu0dQ==" + }, "Microsoft.SemanticKernel.Abstractions": { "type": "Direct", - "requested": "[1.26.0, )", - "resolved": "1.26.0", - "contentHash": "zvSl9tSByc8DZcFR+ii5O4dNg3AskEjtcd5kqp8lJAIhHslyNpR5kD0EkHPaxAsyJyCCD2TR0J1TOUwjBkxDAA==", + "requested": "[1.29.0, )", + "resolved": "1.29.0", + "contentHash": "PJIy7YAkaUtyp9uzRn1wO2lQYb/vuC9jtF7rmoPXe18ugrztnvY8sKyvv+LEMib48cZKfOhxOzQVE/dTa5TjrQ==", "dependencies": { "Microsoft.Bcl.AsyncInterfaces": "8.0.0", "Microsoft.Bcl.HashCode": "1.1.1", @@ -68,11 +74,12 @@ }, "Elastic.Transport": { "type": "Transitive", - "resolved": "0.4.26", - "contentHash": "ZbVlxXn9fnZqMOyOESea5n17096Xa8EPI/I9yD65y6yPXZKrs4GcqKTjfYk0jkxsl3n+CpaNureMA+VutpLZzQ==", + "resolved": "0.5.5", + "contentHash": "sWuMp1yX4R2rHtmZhWVudt5l0zIaqSYCnUtcMrsmfiZxV2qY5WlbViPIH5KdYrI52p71vhScshVJbPDRezm10Q==", "dependencies": { "Microsoft.CSharp": "4.7.0", "System.Buffers": "4.5.1", + "System.Collections.Immutable": "8.0.0", "System.Diagnostics.DiagnosticSource": "8.0.0", "System.Text.Json": "8.0.5", "System.Threading.Tasks.Extensions": "4.5.4" @@ -152,6 +159,15 @@ "resolved": "4.5.1", "contentHash": "Rw7ijyl1qqRS0YQD/WycNst8hUUMgrMH4FCn1nNm27M4VxchZ1js3fVjQaANHO5f3sN4isvP4a+Met9Y4YomAg==" }, + "System.Collections.Immutable": { + "type": "Transitive", + "resolved": "8.0.0", + "contentHash": "AurL6Y5BA1WotzlEvVaIDpqzpIPvYnnldxru8oXJU2yFxFUy3+pNXjXd1ymO+RA0rq0+590Q8gaz2l3Sr7fmqg==", + "dependencies": { + "System.Memory": "4.5.5", + "System.Runtime.CompilerServices.Unsafe": "6.0.0" + } + }, "System.Diagnostics.DiagnosticSource": { "type": "Transitive", "resolved": "8.0.1", @@ -203,18 +219,24 @@ "net8.0": { "Elastic.Clients.Elasticsearch": { "type": "Direct", - "requested": "[8.15.10, )", - "resolved": "8.15.10", - "contentHash": "WxbKk/PvNOhhGLkaqdrQwNWxiDtOYQJYZK6VwOkV65r7kQO+cpmjkYr/FoJ4ArfHFzZJf77VHNyvFSWDe3Vqzw==", + "requested": "[8.16.1, )", + "resolved": "8.16.1", + "contentHash": "IIqNXo1hS15aXSfr3f+QzYJqj7k01vx075VJT4d4/oQdpN4HL3IRfnhcgPHMVQSuAw8bY5l3FSztGHT54AwgtQ==", "dependencies": { - "Elastic.Transport": "0.4.26" + "Elastic.Transport": "0.5.5" } }, + "Microsoft.Build.CopyOnWrite": { + "type": "Direct", + "requested": "[1.0.334, )", + "resolved": "1.0.334", + "contentHash": "Bi/e5guuwmyPL7Kp1G+PbcDvZFKsZxuHmc39IpYHAhWOvV8I/uIHPwAZ++Fa8k/w6pEqPdHCIrxSCelMNmu0dQ==" + }, "Microsoft.SemanticKernel.Abstractions": { "type": "Direct", - "requested": "[1.26.0, )", - "resolved": "1.26.0", - "contentHash": "zvSl9tSByc8DZcFR+ii5O4dNg3AskEjtcd5kqp8lJAIhHslyNpR5kD0EkHPaxAsyJyCCD2TR0J1TOUwjBkxDAA==", + "requested": "[1.29.0, )", + "resolved": "1.29.0", + "contentHash": "PJIy7YAkaUtyp9uzRn1wO2lQYb/vuC9jtF7rmoPXe18ugrztnvY8sKyvv+LEMib48cZKfOhxOzQVE/dTa5TjrQ==", "dependencies": { "Microsoft.Bcl.AsyncInterfaces": "8.0.0", "Microsoft.Bcl.HashCode": "1.1.1", @@ -250,8 +272,8 @@ }, "Elastic.Transport": { "type": "Transitive", - "resolved": "0.4.26", - "contentHash": "ZbVlxXn9fnZqMOyOESea5n17096Xa8EPI/I9yD65y6yPXZKrs4GcqKTjfYk0jkxsl3n+CpaNureMA+VutpLZzQ==" + "resolved": "0.5.5", + "contentHash": "sWuMp1yX4R2rHtmZhWVudt5l0zIaqSYCnUtcMrsmfiZxV2qY5WlbViPIH5KdYrI52p71vhScshVJbPDRezm10Q==" }, "Microsoft.Bcl.AsyncInterfaces": { "type": "Transitive", diff --git a/Elastic.SemanticKernel.Playground/packages.lock.json b/Elastic.SemanticKernel.Playground/packages.lock.json index b00f6a8..e234657 100644 --- a/Elastic.SemanticKernel.Playground/packages.lock.json +++ b/Elastic.SemanticKernel.Playground/packages.lock.json @@ -4,17 +4,23 @@ "net8.0": { "Elastic.Clients.Elasticsearch": { "type": "Direct", - "requested": "[8.15.10, )", - "resolved": "8.15.10", - "contentHash": "WxbKk/PvNOhhGLkaqdrQwNWxiDtOYQJYZK6VwOkV65r7kQO+cpmjkYr/FoJ4ArfHFzZJf77VHNyvFSWDe3Vqzw==", + "requested": "[8.16.1, )", + "resolved": "8.16.1", + "contentHash": "IIqNXo1hS15aXSfr3f+QzYJqj7k01vx075VJT4d4/oQdpN4HL3IRfnhcgPHMVQSuAw8bY5l3FSztGHT54AwgtQ==", "dependencies": { - "Elastic.Transport": "0.4.26" + "Elastic.Transport": "0.5.5" } }, + "Microsoft.Build.CopyOnWrite": { + "type": "Direct", + "requested": "[1.0.334, )", + "resolved": "1.0.334", + "contentHash": "Bi/e5guuwmyPL7Kp1G+PbcDvZFKsZxuHmc39IpYHAhWOvV8I/uIHPwAZ++Fa8k/w6pEqPdHCIrxSCelMNmu0dQ==" + }, "Elastic.Transport": { "type": "Transitive", - "resolved": "0.4.26", - "contentHash": "ZbVlxXn9fnZqMOyOESea5n17096Xa8EPI/I9yD65y6yPXZKrs4GcqKTjfYk0jkxsl3n+CpaNureMA+VutpLZzQ==" + "resolved": "0.5.5", + "contentHash": "sWuMp1yX4R2rHtmZhWVudt5l0zIaqSYCnUtcMrsmfiZxV2qY5WlbViPIH5KdYrI52p71vhScshVJbPDRezm10Q==" }, "Microsoft.Bcl.AsyncInterfaces": { "type": "Transitive", @@ -57,17 +63,17 @@ "elastic.semantickernel.connectors.elasticsearch": { "type": "Project", "dependencies": { - "Elastic.Clients.Elasticsearch": "[8.15.10, )", - "Microsoft.SemanticKernel.Abstractions": "[1.26.0, )", + "Elastic.Clients.Elasticsearch": "[8.16.1, )", + "Microsoft.SemanticKernel.Abstractions": "[1.29.0, )", "MinVer": "[6.0.0, )", "System.Text.Json": "[8.0.5, )" } }, "Microsoft.SemanticKernel.Abstractions": { "type": "CentralTransitive", - "requested": "[1.26.0, )", - "resolved": "1.26.0", - "contentHash": "zvSl9tSByc8DZcFR+ii5O4dNg3AskEjtcd5kqp8lJAIhHslyNpR5kD0EkHPaxAsyJyCCD2TR0J1TOUwjBkxDAA==", + "requested": "[1.29.0, )", + "resolved": "1.29.0", + "contentHash": "PJIy7YAkaUtyp9uzRn1wO2lQYb/vuC9jtF7rmoPXe18ugrztnvY8sKyvv+LEMib48cZKfOhxOzQVE/dTa5TjrQ==", "dependencies": { "Microsoft.Bcl.AsyncInterfaces": "8.0.0", "Microsoft.Bcl.HashCode": "1.1.1",