Skip to content

Commit d31554f

Browse files
committed
Adding commits from last week mistakenly pushed to SK mirror repo vs. this SK forked repo. Commits for review added for addressing PR Comments-TEW
1 parent dd3d73b commit d31554f

13 files changed

Lines changed: 173 additions & 97 deletions

File tree

‎dotnet/src/SemanticKernel.Skills/Skills.Memory.VectorDB/Qdrant/DotNet/IVectorDbCollection.cs‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public interface IVectorDbCollection
1212
{
1313
string Name { get; }
1414

15-
Task<IAsyncEnumerable<DataEntry<VectorRecordData<float>>>> GetAllVectorsAsync();
15+
IAsyncEnumerable<DataEntry<VectorRecordData<float>>> GetAllVectorsAsync();
1616
Task<DataEntry<VectorRecordData<float>>?> GetVectorAsync(string id);
1717
Task UpsertVectorAsync(DataEntry<VectorRecordData<float>> record);
1818
Task DeleteVectorAsync(string id);
@@ -21,24 +21,23 @@ public interface IVectorDbCollection
2121

2222
public static class VectorDbCollectionExtensions
2323
{
24-
public static Task UpsertVectorAsync(this IVectorDbCollection collection, string id, float[] data, IEnumerable<string>? tags = null,
25-
Dictionary<string, object>? payload = null)
24+
public static Task UpsertVectorAsync(this IVectorDbCollection collection, string id, float[] data, IEnumerable<string>? tags = null, Dictionary<string, object>? payload = null)
2625
{
26+
IVectorDbCollection vectorColl = collection;
2727
return collection.UpsertVectorAsync(
2828
new DataEntry<VectorRecordData<float>>(key: id,
29-
value: new VectorRecordData<float>(
30-
new Embedding<float>(data),
31-
payload ?? new(),
32-
tags?.ToList() ?? new List<string>(0))));
29+
value: new VectorRecordData<float>(
30+
new Embedding<float>(data),
31+
payload ?? new(),
32+
tags?.ToList() ?? new List<string>(0))));
3333
}
3434

3535
public static Task DeleteVectorAsync(this IVectorDbCollection collection, DataEntry<VectorRecordData<float>> record)
3636
{
3737
return collection.DeleteVectorAsync(record.Key);
3838
}
3939

40-
public static IAsyncEnumerable<KeyValuePair<DataEntry<VectorRecordData<float>>, double>> FindClosestAsync(this IVectorDbCollection collection,
41-
DataEntry<VectorRecordData<float>> record, int top = 1, string[]? requiredTags = null)
40+
public static IAsyncEnumerable<KeyValuePair<DataEntry<VectorRecordData<float>>, double>> FindClosestAsync(this IVectorDbCollection collection, DataEntry<VectorRecordData<float>> record, int top = 1, string[]? requiredTags = null)
4241
{
4342
return collection.FindClosestAsync(record.Value!.Embedding.Vector.ToArray(), top, requiredTags);
4443
}

‎dotnet/src/SemanticKernel.Skills/Skills.Memory.VectorDB/Qdrant/DotNet/Internal/Diagnostics/Exception.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ private static string BuildMessage(TErrorType errorType, string? message)
1818
return message != null ? $"{errorType.ToString("G")}: {message}" : errorType.ToString("G");
1919
}
2020

21+
public Exception()
22+
{
23+
}
24+
2125
#endregion
2226
}

‎dotnet/src/SemanticKernel.Skills/Skills.Memory.VectorDB/Qdrant/DotNet/Internal/Diagnostics/VectorDbException.cs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,8 @@ public VectorDbException(ErrorCodes error, string message)
2020
: base(error, message)
2121
{
2222
}
23+
24+
public VectorDbException()
25+
{
26+
}
2327
}

‎dotnet/src/SemanticKernel.Skills/Skills.Memory.VectorDB/Qdrant/DotNet/Internal/Http/Specs/CreateVectorsRequest.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void Validate()
2626
public CreateVectorsRequest UpsertVector(string pointId, DataEntry<VectorRecordData<float>> vector)
2727
{
2828
this.Batch.Ids.Add(pointId);
29-
this.Batch.Vectors.Add(vector.Value.Embedding.Vector.ToArray());
29+
this.Batch.Vectors.Add(vector.Value!.Embedding.Vector.ToArray());
3030
this.Batch.Payloads.Add(PointPayloadDataMapper.PreparePointPayload(vector));
3131
return this;
3232
}

‎dotnet/src/SemanticKernel.Skills/Skills.Memory.VectorDB/Qdrant/DotNet/Internal/Http/Specs/FetchVectorsRequest.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22

33
using System.Collections.Generic;
44
using System.Net.Http;

‎dotnet/src/SemanticKernel.Skills/Skills.Memory.VectorDB/Qdrant/DotNet/Internal/Http/Specs/FetchVectorsResponse.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft. All rights reserved.
1+
// Copyright (c) Microsoft. All rights reserved.
22

33
using System;
44
using System.Collections.Generic;

‎dotnet/src/SemanticKernel.Skills/Skills.Memory.VectorDB/Qdrant/DotNet/Internal/QdrantCollection.cs‎

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,22 @@ public QdrantCollection(string id, QdrantHttpClientWrapper vectorHttp, ILogger l
3131
this._log = log ?? NullLogger.Instance;
3232
}
3333

34+
3435
public async Task<DataEntry<VectorRecordData<float>>?> GetVectorAsync(string id)
3536
{
3637
var point = await this.FindQdrantPointByExternalIdAsync(id);
3738
if (point == null) { return null; }
3839

3940
var result = new DataEntry<VectorRecordData<float>>(key: point.ExternalId,
40-
value: new VectorRecordData<float>(
41-
new Embedding<float>(point.Vector),
42-
point.ExternalPayload,
43-
point.ExternalTags));
41+
value: new VectorRecordData<float>(
42+
new Embedding<float>(point.Vector),
43+
point.ExternalPayload,
44+
point.ExternalTags));
4445

4546
return result;
4647
}
4748

48-
public async Task<IAsyncEnumerable<DataEntry<VectorRecordData<float>>>> GetAllVectorsAsync()
49+
public async IAsyncEnumerable<DataEntry<VectorRecordData<float>>> GetAllVectorsAsync()
4950
{
5051
HttpRequestMessage vectorRequest = FetchVectorsRequest
5152
.Fetch(this.Name)
@@ -54,7 +55,19 @@ public async Task<IAsyncEnumerable<DataEntry<VectorRecordData<float>>>> GetAllVe
5455
var (response, responseContent) = await this._vectorHttp.ExecuteHttpRequestAsync(vectorRequest);
5556
response.EnsureSuccessStatusCode();
5657

57-
return null;
58+
var data = new FetchVectorsResponse(responseContent);
59+
Verify.Equals("ok", data.Status, $"Something went wrong while getting vectors for {this.Name}");
60+
61+
foreach (var point in data.VectorPointCollection)
62+
{
63+
var record = new DataEntry<VectorRecordData<float>>(key: point.VectorId!,
64+
value: new VectorRecordData<float>(
65+
new Embedding<float>(point.Vector!),
66+
point.Payload!,
67+
new List<string>()));
68+
69+
yield return record;
70+
}
5871
}
5972

6073
public Task UpsertVectorAsync(DataEntry<VectorRecordData<float>> record)
@@ -74,14 +87,13 @@ public async Task DeleteVectorAsync(string id)
7487
await this.DeleteVectorInternalAsync(qdrantId);
7588
}
7689

77-
public async IAsyncEnumerable<KeyValuePair<DataEntry<VectorRecordData<float>>, double>> FindClosestAsync(float[] target, int top = 1,
78-
string[]? requiredTags = null)
90+
public async IAsyncEnumerable<KeyValuePair<DataEntry<VectorRecordData<float>>, double>> FindClosestAsync(float[] target, int top = 1, string[]? requiredTags = null)
7991
{
8092
this._log.Debug("Searching top {0} closest vectors in {1}", top);
8193

8294
Verify.NotNull(target, "The given vector is NULL");
8395

84-
HttpRequestMessage request = SearchVectorsRequest
96+
using HttpRequestMessage request = SearchVectorsRequest
8597
.Create(this.Name)
8698
.SimilarTo(target)
8799
.HavingTags(requiredTags)
@@ -107,10 +119,10 @@ public async IAsyncEnumerable<KeyValuePair<DataEntry<VectorRecordData<float>>, d
107119
foreach (var v in data.Vectors)
108120
{
109121
var record = new DataEntry<VectorRecordData<float>>(key: v.ExternalId,
110-
value: new VectorRecordData<float>(
111-
new Embedding<float>(v.Vector),
112-
v.ExternalPayload,
113-
v.ExternalTags));
122+
value: new VectorRecordData<float>(
123+
new Embedding<float>(v.Vector),
124+
v.ExternalPayload,
125+
v.ExternalTags));
114126

115127
result.Add(new KeyValuePair<DataEntry<VectorRecordData<float>>, double>(record, v.Score ?? 0));
116128
}
@@ -125,8 +137,7 @@ public async IAsyncEnumerable<KeyValuePair<DataEntry<VectorRecordData<float>>, d
125137

126138
#region private ================================================================================
127139

128-
private static List<KeyValuePair<DataEntry<VectorRecordData<float>>, double>> SortSearchResultByScore(
129-
List<KeyValuePair<DataEntry<VectorRecordData<float>>, double>> list)
140+
private static List<KeyValuePair<DataEntry<VectorRecordData<float>>, double>> SortSearchResultByScore(List<KeyValuePair<DataEntry<VectorRecordData<float>>, double>> list)
130141
{
131142
return (from entry in list orderby entry.Value descending select entry).ToList();
132143
}
@@ -141,7 +152,7 @@ private static List<KeyValuePair<DataEntry<VectorRecordData<float>>, double>> So
141152
{
142153
this._log.Debug("Searching vector by external ID {0}", externalId);
143154

144-
HttpRequestMessage request = SearchVectorsRequest
155+
using HttpRequestMessage request = SearchVectorsRequest
145156
.Create(this.Name, this.VectorSize)
146157
.HavingExternalId(externalId)
147158
.IncludePayLoad()
@@ -189,7 +200,7 @@ private async Task UpsertVectorInternalAsync(DataEntry<VectorRecordData<float>>
189200
if (response.StatusCode == HttpStatusCode.UnprocessableEntity
190201
&& responseContent.Contains("data did not match any variant of untagged enum ExtendedPointId"))
191202
{
192-
throw new Exception("The vector ID must be a GUID string");
203+
throw new VectorDbException("The vector ID must be a GUID string");
193204
}
194205

195206
try
@@ -217,5 +228,7 @@ private async Task DeleteVectorInternalAsync(string qdrantPointId)
217228
await this._vectorHttp.ExecuteHttpRequestAsync(request);
218229
}
219230

231+
232+
220233
#endregion
221234
}

‎dotnet/src/SemanticKernel.Skills/Skills.Memory.VectorDB/Qdrant/DotNet/Internal/QdrantHttpClientWrapper.cs‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public QdrantHttpClientWrapper(HttpClient client, ILogger logger)
4040
dynamic tmp = JObject.Parse(responseContent);
4141
if (tmp != null && this._log.IsEnabled(LogLevel.Debug))
4242
{
43-
this._log.LogDebug("Qdrant response time: {0}", (double)tmp.time);
43+
this._log.LogDebug("Qdrant response time: {0}", (double)tmp!.time);
4444
}
4545

4646
this._log.LogTrace("Qdrant response: {0}", responseContent);
@@ -67,8 +67,9 @@ private static Uri SanitizeEndpoint(string endpoint)
6767
private static Uri SanitizeEndpoint(string endpoint, int port)
6868
{
6969
UriBuilder builder = new UriBuilder(SanitizeEndpoint(endpoint))
70-
{ Port = port };
70+
{ Port = port };
7171
return builder.Uri;
72+
7273
}
7374

7475
#endregion

‎dotnet/src/SemanticKernel.Skills/Skills.Memory.VectorDB/Qdrant/DotNet/VectorRecord.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,6 @@ public VectorRecordData(Embedding<TEmbedding> embedding, Dictionary<string, obje
1818
this.Payload = payload;
1919
this.Tags = tags;
2020
}
21+
2122
}
23+

‎dotnet/src/SemanticKernel.Skills/Skills.Memory.VectorDB/Qdrant/ILongTermMemoryStore.cs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
using System.Collections.Generic;
55
using System.Text;
66
using Microsoft.SemanticKernel.AI.Embeddings;
7+
using Microsoft.SemanticKernel.Memory;
78
using Microsoft.SemanticKernel.Memory.Storage;
89
using Qdrant.DotNet;
910

10-
//namespace Microsoft.SemanticKernel.Connectors.VectorDB.Qdrant;
1111
namespace Microsoft.SemanticKernel.Skills.Memory.VectorDB;
1212

13-
internal interface ILongTermMemoryStore<TEmbedding> : IDataStore<VectorRecordData<TEmbedding>>, IEmbeddingIndex<TEmbedding>
13+
internal interface ILongTermMemoryStore<TEmbedding> : IQdrantMemoryStore<TEmbedding>, IMemoryStore<TEmbedding>
1414
where TEmbedding : unmanaged
1515
{
1616
}

0 commit comments

Comments
 (0)