Skip to content
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
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.VectorData;
using Microsoft.SemanticKernel.Connectors.InMemory;

Expand Down Expand Up @@ -32,7 +33,7 @@ public static IKernelBuilder AddInMemoryVectorStore(this IKernelBuilder builder,
/// <param name="options">Optional options to further configure the <see cref="IVectorStoreRecordCollection{TKey, TRecord}"/>.</param>
/// <param name="serviceId">An optional service id to use as the service key.</param>
/// <returns>The kernel builder.</returns>
public static IKernelBuilder AddInMemoryVectorStoreRecordCollection<TKey, TRecord>(
public static IKernelBuilder AddInMemoryVectorStoreRecordCollection<TKey, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicConstructors)] TRecord>(
this IKernelBuilder builder,
string collectionName,
InMemoryVectorStoreRecordCollectionOptions<TKey, TRecord>? options = default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static IServiceCollection AddInMemoryVectorStore(this IServiceCollection
/// <param name="options">Optional options to further configure the <see cref="IVectorStoreRecordCollection{TKey, TRecord}"/>.</param>
/// <param name="serviceId">An optional service id to use as the service key.</param>
/// <returns>The service collection.</returns>
public static IServiceCollection AddInMemoryVectorStoreRecordCollection<TKey, TRecord>(
public static IServiceCollection AddInMemoryVectorStoreRecordCollection<TKey, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicConstructors)] TRecord>(
this IServiceCollection services,
string collectionName,
InMemoryVectorStoreRecordCollectionOptions<TKey, TRecord>? options = default,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading;
using Microsoft.Extensions.VectorData;
Expand Down Expand Up @@ -38,7 +39,7 @@ internal InMemoryVectorStore(ConcurrentDictionary<string, ConcurrentDictionary<o
}

/// <inheritdoc />
public IVectorStoreRecordCollection<TKey, TRecord> GetCollection<TKey, TRecord>(string name, VectorStoreRecordDefinition? vectorStoreRecordDefinition = null)
public IVectorStoreRecordCollection<TKey, TRecord> GetCollection<TKey, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicConstructors)] TRecord>(string name, VectorStoreRecordDefinition? vectorStoreRecordDefinition = null)
where TKey : notnull
{
if (this._internalCollectionTypes.TryGetValue(name, out var existingCollectionDataType) && existingCollectionDataType != typeof(TRecord))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Text.Json;
Expand All @@ -26,7 +27,7 @@ public static class InMemoryVectorStoreExtensions
/// <param name="collectionName">The collection name.</param>
/// <param name="stream">The stream to write the serialized JSON to.</param>
/// <param name="jsonSerializerOptions">The JSON serializer options to use.</param>
public static async Task SerializeCollectionAsJsonAsync<TKey, TRecord>(
public static async Task SerializeCollectionAsJsonAsync<TKey, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicConstructors)] TRecord>(
this InMemoryVectorStore vectorStore,
string collectionName,
Stream stream,
Expand Down Expand Up @@ -55,7 +56,7 @@ public static async Task SerializeCollectionAsJsonAsync<TKey, TRecord>(
/// <typeparam name="TRecord">Type of the record.</typeparam>
/// <param name="vectorStore">Instance of <see cref="InMemoryVectorStore"/> used to retrieve the collection.</param>
/// <param name="stream">The stream to read the serialized JSON from.</param>
public static async Task<IVectorStoreRecordCollection<TKey, TRecord>?> DeserializeCollectionFromJsonAsync<TKey, TRecord>(
public static async Task<IVectorStoreRecordCollection<TKey, TRecord>?> DeserializeCollectionFromJsonAsync<TKey, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicConstructors)] TRecord>(
this InMemoryVectorStore vectorStore,
Stream stream)
where TKey : notnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
Expand All @@ -18,7 +19,7 @@ namespace Microsoft.SemanticKernel.Connectors.InMemory;
/// <typeparam name="TKey">The data type of the record key.</typeparam>
/// <typeparam name="TRecord">The data model to use for adding, updating and retrieving data from storage.</typeparam>
#pragma warning disable CA1711 // Identifiers should not have incorrect suffix
public sealed class InMemoryVectorStoreRecordCollection<TKey, TRecord> : IVectorStoreRecordCollection<TKey, TRecord>
public sealed class InMemoryVectorStoreRecordCollection<TKey, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicConstructors)] TRecord> : IVectorStoreRecordCollection<TKey, TRecord>
#pragma warning restore CA1711 // Identifiers should not have incorrect suffix
where TKey : notnull
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
// Copyright (c) Microsoft. All rights reserved.

using System.Collections.Generic;
#if NET7_0_OR_GREATER
using System.Diagnostics.CodeAnalysis;
#endif
using System.Threading;

namespace Microsoft.Extensions.VectorData;
Expand Down Expand Up @@ -28,7 +31,11 @@ public interface IVectorStore
/// <seealso cref="VectorStoreRecordKeyAttribute"/>
/// <seealso cref="VectorStoreRecordDataAttribute"/>
/// <seealso cref="VectorStoreRecordVectorAttribute"/>
IVectorStoreRecordCollection<TKey, TRecord> GetCollection<TKey, TRecord>(string name, VectorStoreRecordDefinition? vectorStoreRecordDefinition = null)
IVectorStoreRecordCollection<TKey, TRecord> GetCollection<TKey,
#if NET7_0_OR_GREATER
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicConstructors)]
#endif
TRecord>(string name, VectorStoreRecordDefinition? vectorStoreRecordDefinition = null)
where TKey : notnull;

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,8 @@ public static void SetPropertiesOnRecord<TRecord>(
/// <param name="requiredEnumerable">The type to convert to.</param>
/// <returns>The new enumerable in the required type.</returns>
/// <exception cref="NotSupportedException">Thrown when a target type is requested that is not supported.</exception>
public static object? CreateEnumerable<T>(IEnumerable<T> input, Type requiredEnumerable)
[RequiresDynamicCode("Calls System.Collections.ArrayList.ToArray(Type)")]
public static object? CreateEnumerable<T>(IEnumerable<T> input, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors)] Type requiredEnumerable)
{
if (input is null)
{
Expand Down
1 change: 1 addition & 0 deletions dotnet/src/InternalUtilities/src/Type/TypeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ internal static class TypeExtensions
/// <param name="resultType">The result type of the Nullable generic parameter.</param>
/// <returns><c>true</c> if the result type was successfully retrieved; otherwise, <c>false</c>.</returns>
/// TODO [@teresaqhoang]: Issue #4202 Cache Generic Types Extraction - Handlebars
[RequiresDynamicCode("Calls System.Type.MakeGenericType(params Type[])")]
public static bool TryGetGenericResultType(this Type? returnType, out Type resultType)
{
resultType = typeof(object);
Expand Down
Loading