Skip to content

Commit 6e2d314

Browse files
authored
Change visibility modifiers on MemoryRecord and associated collection classes (#250)
### Motivation and Context `MemoryRecord`, along with several useful classes in the `SemanticKernel.Memory.Collections` namespace currently have an internal visibility modifier. This prevents 3rd party libraries from reusing code when creating implementations of `IEmbeddingWithMetadata<float>`, which is needed in implementations of `IMemoryStore<TEmbedding>` Two implementations are currently blocked on this: * Skills.Memory.Sqlite * Skills.Memory.CosmosDB As both of these backing stores are not vector DB stores, they implement cosine similarity comparisons locally, which is performed using `TopNCollection` and its dependencies, all of which are currently internal. Related community feedback item here: #202 ### Description Change the following classes from internal to public: * MemoryRecord * MinHeap * Score * ScoredValue * TopNCollection
1 parent bcd740b commit 6e2d314

5 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎dotnet/src/SemanticKernel/Memory/Collections/MinHeap.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace Microsoft.SemanticKernel.Memory.Collections;
1111
/// Implements the classic 'heap' data structure. By default, the item with the lowest value is at the top of the heap.
1212
/// </summary>
1313
/// <typeparam name="T">Data type.</typeparam>
14-
internal class MinHeap<T> : IEnumerable<T> where T : IComparable<T>
14+
public class MinHeap<T> : IEnumerable<T> where T : IComparable<T>
1515
{
1616
private const int DefaultCapacity = 7;
1717
private const int MinCapacity = 0;

‎dotnet/src/SemanticKernel/Memory/Collections/Score.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.SemanticKernel.Memory.Collections;
88
/// <summary>
99
/// Structure for storing score value.
1010
/// </summary>
11-
internal struct Score : IComparable<Score>, IEquatable<Score>
11+
public struct Score : IComparable<Score>, IEquatable<Score>
1212
{
1313
public double Value { get; set; }
1414

‎dotnet/src/SemanticKernel/Memory/Collections/ScoredValue.cs‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.SemanticKernel.Memory.Collections;
99
/// Structure for storing data which can be scored.
1010
/// </summary>
1111
/// <typeparam name="T">Data type.</typeparam>
12-
internal struct ScoredValue<T> : IComparable<ScoredValue<T>>, IEquatable<ScoredValue<T>>
12+
public struct ScoredValue<T> : IComparable<ScoredValue<T>>, IEquatable<ScoredValue<T>>
1313
{
1414
public ScoredValue(T item, double score)
1515
{
@@ -92,6 +92,8 @@ public override int GetHashCode()
9292
return left.CompareTo(right) >= 0;
9393
}
9494

95+
96+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Design", "CA1000:Do not declare static members on generic types", Justification = "Min value convenience method")]
9597
public static ScoredValue<T> Min()
9698
{
9799
return new ScoredValue<T>(default!, Score.Min);

‎dotnet/src/SemanticKernel/Memory/Collections/TopNCollection.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace Microsoft.SemanticKernel.Memory.Collections;
1010
/// Automatically flushes out any not in the top N.
1111
/// By default, items are not sorted by score until you call <see cref="TopNCollection{T}.SortByScore"/>.
1212
/// </summary>
13-
internal class TopNCollection<T> : IEnumerable<ScoredValue<T>>
13+
public class TopNCollection<T> : IEnumerable<ScoredValue<T>>
1414
{
1515
private readonly int _maxItems;
1616
private readonly MinHeap<ScoredValue<T>> _heap;

‎dotnet/src/SemanticKernel/Memory/MemoryRecord.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.SemanticKernel.Memory;
88
/// <summary>
99
/// IMPORTANT: this is a storage schema. Changing the fields will invalidate existing metadata stored in persistent vector DBs.
1010
/// </summary>
11-
internal class MemoryRecord : IEmbeddingWithMetadata<float>
11+
public class MemoryRecord : IEmbeddingWithMetadata<float>
1212
{
1313
/// <summary>
1414
/// Source content embeddings.

0 commit comments

Comments
 (0)