Skip to content

.Net: Obsolete custom mappers #11366

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

Merged
Merged
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 @@ -9,6 +9,8 @@

namespace Memory.VectorStoreLangchainInterop;

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete

/// <summary>
/// Contains a factory method that can be used to create an Azure AI Search vector store that is compatible with datasets ingested using Langchain.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

namespace Memory.VectorStoreLangchainInterop;

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete

/// <summary>
/// Contains a factory method that can be used to create a Qdrant vector store that is compatible with datasets ingested using Langchain.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace Memory;

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete

/// <summary>
/// An example showing how to ingest data into a vector store using <see cref="RedisVectorStore"/> with a custom mapper.
/// In this example, the storage model differs significantly from the data model, so a custom mapper is used to map between the two.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

namespace GettingStartedWithVectorStores;

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete

/// <summary>
/// Example that shows how you can use custom mappers if you wish the data model and storage schema to differ.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ await this.TestUpsertWithModelAsync<BsonVectorStoreWithNameTestModel>(
expectedPropertyName: "bson_hotel_name");
}

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
[Fact]
public async Task UpsertWithCustomMapperWorksCorrectlyAsync()
{
Expand Down Expand Up @@ -564,6 +565,7 @@ public async Task GetWithCustomMapperWorksCorrectlyAsync()
Assert.Equal(RecordKey, result.HotelId);
Assert.Equal("Name from mapper", result.HotelName);
}
#pragma warning restore CS0618

[Theory]
[MemberData(nameof(VectorizedSearchVectorTypeData))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,7 @@ public async Task UpsertBatchReturnsRecordKeysAsync()
Assert.Equal("key3", results[2]);
}

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
[Fact]
public async Task UpsertWithCustomMapperWorksCorrectlyAsync()
{
Expand Down Expand Up @@ -537,6 +538,7 @@ public async Task GetWithCustomMapperWorksCorrectlyAsync()
Assert.Equal(RecordKey, result.HotelId);
Assert.Equal("Name from mapper", result.HotelName);
}
#pragma warning restore CS0618

[Fact]
public async Task VectorizedSearchReturnsValidRecordAsync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ namespace Microsoft.SemanticKernel.Connectors.AzureAISearch;
/// <summary>
/// A mapper that maps between the generic Semantic Kernel data model and the model that the data is stored under, within Azure AI Search.
/// </summary>
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
internal sealed class AzureAISearchGenericDataModelMapper(VectorStoreRecordModel model) : IVectorStoreRecordMapper<VectorStoreGenericDataModel<string>, JsonObject>
#pragma warning restore CS0618
{
/// <inheritdoc />
public JsonObject MapFromDataToStorageModel(VectorStoreGenericDataModel<string> dataModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public class AzureAISearchVectorStoreRecordCollection<TRecord> :
private readonly AzureAISearchVectorStoreRecordCollectionOptions<TRecord> _options;

/// <summary>A mapper to use for converting between the data model and the Azure AI Search record.</summary>
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
private readonly IVectorStoreRecordMapper<TRecord, JsonObject>? _mapper;
#pragma warning restore CS0618

/// <summary>The model for this collection.</summary>
private readonly VectorStoreRecordModel _model;
Expand Down Expand Up @@ -80,6 +82,7 @@ public AzureAISearchVectorStoreRecordCollection(SearchIndexClient searchIndexCli
this._model = new VectorStoreRecordJsonModelBuilder(AzureAISearchConstants.s_modelBuildingOptions)
.Build(typeof(TRecord), this._options.VectorStoreRecordDefinition, this._options.JsonSerializerOptions);

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
// Resolve mapper.
// First, if someone has provided a custom mapper, use that.
// If they didn't provide a custom mapper, and the record type is the generic data model, use the built in mapper for that.
Expand All @@ -92,6 +95,7 @@ public AzureAISearchVectorStoreRecordCollection(SearchIndexClient searchIndexCli
{
this._mapper = new AzureAISearchGenericDataModelMapper(this._model) as IVectorStoreRecordMapper<TRecord, JsonObject>;
}
#pragma warning restore CS0618
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Text.Json;
using System.Text.Json.Nodes;
using Azure.Search.Documents.Indexes;
Expand All @@ -18,6 +19,7 @@ public sealed class AzureAISearchVectorStoreRecordCollectionOptions<TRecord>
/// <remarks>
/// If not set, the default mapper that is provided by the Azure AI Search client SDK will be used.
/// </remarks>
[Obsolete("Custom mappers are being obsoleted.")]
public IVectorStoreRecordMapper<TRecord, JsonObject>? JsonObjectCustomMapper { get; init; } = null;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public class AzureCosmosDBMongoDBVectorStoreRecordCollection<TRecord> : IVectorS
private readonly AzureCosmosDBMongoDBVectorStoreRecordCollectionOptions<TRecord> _options;

/// <summary>Interface for mapping between a storage model, and the consumer record data model.</summary>
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
private readonly IVectorStoreRecordMapper<TRecord, BsonDocument> _mapper;
#pragma warning restore CS0618

/// <summary>The model for this collection.</summary>
private readonly VectorStoreRecordModel _model;
Expand Down Expand Up @@ -473,6 +475,7 @@ private static Dictionary<string, string> GetStoragePropertyNames(
return storagePropertyNames;
}

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
/// <summary>
/// Returns custom mapper, generic data model mapper or default record mapper.
/// </summary>
Expand All @@ -490,6 +493,7 @@ private IVectorStoreRecordMapper<TRecord, BsonDocument> InitializeMapper()

return new MongoDBVectorStoreRecordMapper<TRecord>(this._model);
}
#pragma warning restore CS0618

#endregion
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using Microsoft.Extensions.VectorData;
using MongoDB.Bson;

Expand All @@ -13,6 +14,7 @@ public sealed class AzureCosmosDBMongoDBVectorStoreRecordCollectionOptions<TReco
/// <summary>
/// Gets or sets an optional custom mapper to use when converting between the data model and the Azure CosmosDB MongoDB BSON object.
/// </summary>
[Obsolete("Custom mappers are being obsoleted.")]
public IVectorStoreRecordMapper<TRecord, BsonDocument>? BsonDocumentCustomMapper { get; init; } = null;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ namespace Microsoft.SemanticKernel.Connectors.AzureCosmosDBNoSQL;
/// <summary>
/// A mapper that maps between the generic Semantic Kernel data model and the model that the data is stored under, within Azure CosmosDB NoSQL.
/// </summary>
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
internal sealed class AzureCosmosDBNoSQLGenericDataModelMapper(VectorStoreRecordModel model, JsonSerializerOptions jsonSerializerOptions)
: IVectorStoreRecordMapper<VectorStoreGenericDataModel<string>, JsonObject>
#pragma warning restore CS0618
{
/// <summary>A default <see cref="JsonSerializerOptions"/> for serialization/deserialization of vector properties.</summary>
private static readonly JsonSerializerOptions s_vectorJsonSerializerOptions = new()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ public class AzureCosmosDBNoSQLVectorStoreRecordCollection<TRecord> :
private readonly VectorStoreRecordPropertyModel _partitionKeyProperty;

/// <summary>The mapper to use when mapping between the consumer data model and the Azure CosmosDB NoSQL record.</summary>
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
private readonly IVectorStoreRecordMapper<TRecord, JsonObject> _mapper;
#pragma warning restore CS0618

/// <inheritdoc />
public string CollectionName { get; }
Expand Down Expand Up @@ -664,6 +666,7 @@ private async IAsyncEnumerable<VectorSearchResult<TRecord>> MapSearchResultsAsyn
}
}

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
private IVectorStoreRecordMapper<TRecord, JsonObject> InitializeMapper(JsonSerializerOptions jsonSerializerOptions)
{
if (this._options.JsonObjectCustomMapper is not null)
Expand All @@ -679,6 +682,7 @@ private IVectorStoreRecordMapper<TRecord, JsonObject> InitializeMapper(JsonSeria

return new AzureCosmosDBNoSQLVectorStoreRecordMapper<TRecord>(this._model.KeyProperty, this._options.JsonSerializerOptions);
}
#pragma warning restore CS0618

#endregion
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Text.Json;
using System.Text.Json.Nodes;
using Microsoft.Azure.Cosmos;
Expand All @@ -18,6 +19,7 @@ public sealed class AzureCosmosDBNoSQLVectorStoreRecordCollectionOptions<TRecord
/// <remarks>
/// If not set, the default mapper that is provided by the Azure CosmosDB NoSQL client SDK will be used.
/// </remarks>
[Obsolete("Custom mappers are being obsoleted.")]
public IVectorStoreRecordMapper<TRecord, JsonObject>? JsonObjectCustomMapper { get; init; } = null;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ namespace Microsoft.SemanticKernel.Connectors.AzureCosmosDBNoSQL;
/// Class for mapping between a json node stored in Azure CosmosDB NoSQL and the consumer data model.
/// </summary>
/// <typeparam name="TRecord">The consumer data model to map to or from.</typeparam>
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
internal sealed class AzureCosmosDBNoSQLVectorStoreRecordMapper<TRecord>(VectorStoreRecordKeyPropertyModel keyProperty, JsonSerializerOptions? jsonSerializerOptions)
: IVectorStoreRecordMapper<TRecord, JsonObject>
#pragma warning restore CS0618
{
private readonly VectorStoreRecordKeyPropertyModel _keyProperty = keyProperty;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public class MongoDBVectorStoreRecordCollection<TRecord> : IVectorStoreRecordCol
private readonly MongoDBVectorStoreRecordCollectionOptions<TRecord> _options;

/// <summary>Interface for mapping between a storage model, and the consumer record data model.</summary>
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
private readonly IVectorStoreRecordMapper<TRecord, BsonDocument> _mapper;
#pragma warning restore CS0618

/// <summary>The model for this collection.</summary>
private readonly VectorStoreRecordModel _model;
Expand Down Expand Up @@ -597,6 +599,7 @@ private async Task<T> RunOperationWithRetryAsync<T>(
throw new VectorStoreOperationException("Retry logic failed.");
}

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
/// <summary>
/// Returns custom mapper, generic data model mapper or default record mapper.
/// </summary>
Expand All @@ -614,6 +617,7 @@ private IVectorStoreRecordMapper<TRecord, BsonDocument> InitializeMapper()

return new MongoDBVectorStoreRecordMapper<TRecord>(this._model);
}
#pragma warning restore CS0618

private static Array VerifyVectorParam<TVector>(TVector vector)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using Microsoft.Extensions.VectorData;
using MongoDB.Bson;

Expand All @@ -13,6 +14,7 @@ public sealed class MongoDBVectorStoreRecordCollectionOptions<TRecord>
/// <summary>
/// Gets or sets an optional custom mapper to use when converting between the data model and the MongoDB BSON object.
/// </summary>
[Obsolete("Custom mappers are being obsoleted.")]
public IVectorStoreRecordMapper<TRecord, BsonDocument>? BsonDocumentCustomMapper { get; init; } = null;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public class PineconeVectorStoreRecordCollection<TRecord> : IVectorStoreRecordCo
private readonly Sdk.PineconeClient _pineconeClient;
private readonly PineconeVectorStoreRecordCollectionOptions<TRecord> _options;
private readonly VectorStoreRecordModel _model;
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
private readonly IVectorStoreRecordMapper<TRecord, Sdk.Vector> _mapper;
#pragma warning restore CS0618
private IndexClient? _indexClient;

/// <inheritdoc />
Expand All @@ -54,7 +56,9 @@ public PineconeVectorStoreRecordCollection(Sdk.PineconeClient pineconeClient, st
this._model = new VectorStoreRecordModelBuilder(PineconeVectorStoreRecordFieldMapping.ModelBuildingOptions)
.Build(typeof(TRecord), this._options.VectorStoreRecordDefinition);

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
this._mapper = this._options.VectorCustomMapper ?? new PineconeVectorStoreRecordMapper<TRecord>(this._model);
#pragma warning restore CS0618
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using Microsoft.Extensions.VectorData;
using Pinecone;

Expand All @@ -13,6 +14,7 @@ public sealed class PineconeVectorStoreRecordCollectionOptions<TRecord>
/// <summary>
/// Gets or sets an optional custom mapper to use when converting between the data model and the Pinecone vector.
/// </summary>
[Obsolete("Custom mappers are being obsoleted.")]
public IVectorStoreRecordMapper<TRecord, Vector>? VectorCustomMapper { get; init; } = null;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ namespace Microsoft.SemanticKernel.Connectors.Pinecone;
/// Mapper between a Pinecone record and the consumer data model that uses json as an intermediary to allow supporting a wide range of models.
/// </summary>
/// <typeparam name="TRecord">The consumer data model to map to or from.</typeparam>
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
internal sealed class PineconeVectorStoreRecordMapper<TRecord>(VectorStoreRecordModel model) : IVectorStoreRecordMapper<TRecord, Vector>
#pragma warning restore CS0618
{
/// <inheritdoc />
public Vector MapFromDataToStorageModel(TRecord dataModel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ public class PostgresVectorStoreRecordCollection<TKey, TRecord> : IVectorStoreRe
private readonly VectorStoreRecordModel _model;

/// <summary>A mapper to use for converting between the data model and the Azure AI Search record.</summary>
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
private readonly IVectorStoreRecordMapper<TRecord, Dictionary<string, object?>> _mapper;
#pragma warning restore CS0618

/// <summary>The default options for vector search.</summary>
private static readonly VectorSearchOptions<TRecord> s_defaultVectorSearchOptions = new();
Expand Down Expand Up @@ -74,7 +76,9 @@ internal PostgresVectorStoreRecordCollection(IPostgresVectorStoreDbClient client
this._model = new VectorStoreRecordModelBuilder(PostgresConstants.ModelBuildingOptions)
.Build(typeof(TRecord), options?.VectorStoreRecordDefinition);

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
this._mapper = this._options.DictionaryCustomMapper ?? new PostgresVectorStoreRecordMapper<TRecord>(this._model);
#pragma warning restore CS0618
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using System.Collections.Generic;
using Microsoft.Extensions.VectorData;

Expand All @@ -21,6 +22,7 @@ public sealed class PostgresVectorStoreRecordCollectionOptions<TRecord>
/// <remarks>
/// If not set, the default mapper will be used.
/// </remarks>
[Obsolete("Custom mappers are being obsoleted.")]
public IVectorStoreRecordMapper<TRecord, Dictionary<string, object?>>? DictionaryCustomMapper { get; init; } = null;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ namespace Microsoft.SemanticKernel.Connectors.Postgres;
/// A mapper class that handles the conversion between data models and storage models for Postgres vector store.
/// </summary>
/// <typeparam name="TRecord">The type of the data model record.</typeparam>
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
internal sealed class PostgresVectorStoreRecordMapper<TRecord>(VectorStoreRecordModel model)
: IVectorStoreRecordMapper<TRecord, Dictionary<string, object?>>
#pragma warning restore CS0618
{
public Dictionary<string, object?> MapFromDataToStorageModel(TRecord dataModel)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public static Filter BuildFromLegacyFilter(VectorSearchFilter basicVectorSearchF
/// <param name="collectionName">The name of the collection the operation is being run on.</param>
/// <param name="operationName">The type of database operation being run.</param>
/// <returns>The mapped <see cref="VectorSearchResult{TRecord}"/>.</returns>
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
public static VectorSearchResult<TRecord> MapScoredPointToVectorSearchResult<TRecord>(ScoredPoint point, IVectorStoreRecordMapper<TRecord, PointStruct> mapper, bool includeVectors, string databaseSystemName, string collectionName, string operationName)
#pragma warning restore CS0618
{
// Since the mapper doesn't know about scored points, we need to convert the scored point to a point struct first.
var pointStruct = new PointStruct
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ public class QdrantVectorStoreRecordCollection<TRecord> :
private readonly VectorStoreRecordModel _model;

/// <summary>A mapper to use for converting between qdrant point and consumer models.</summary>
#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
private readonly IVectorStoreRecordMapper<TRecord, PointStruct> _mapper;
#pragma warning restore CS0618

/// <summary>
/// Initializes a new instance of the <see cref="QdrantVectorStoreRecordCollection{TRecord}"/> class.
Expand Down Expand Up @@ -91,7 +93,9 @@ internal QdrantVectorStoreRecordCollection(MockableQdrantClient qdrantClient, st
this._model = new VectorStoreRecordModelBuilder(QdrantVectorStoreRecordFieldMapping.GetModelBuildOptions(this._options.HasNamedVectors))
.Build(typeof(TRecord), this._options.VectorStoreRecordDefinition);

#pragma warning disable CS0618 // IVectorStoreRecordMapper is obsolete
this._mapper = this._options.PointStructCustomMapper ?? new QdrantVectorStoreRecordMapper<TRecord>(this._model, this._options.HasNamedVectors);
#pragma warning restore CS0618
}

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using Microsoft.Extensions.VectorData;
using Qdrant.Client.Grpc;

Expand All @@ -22,6 +23,7 @@ public sealed class QdrantVectorStoreRecordCollectionOptions<TRecord>
/// <remarks>
/// If not set, a default mapper that uses json as an intermediary to allow automatic mapping to a wide variety of types will be used.
/// </remarks>
[Obsolete("Custom mappers are being obsoleted.")]
public IVectorStoreRecordMapper<TRecord, PointStruct>? PointStructCustomMapper { get; init; } = null;

/// <summary>
Expand Down
Loading
Loading