Skip to content

.Net MEVD: Port the Pinecone connector to use Pinecone.Client #10788

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

Closed
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
2 changes: 1 addition & 1 deletion dotnet/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.9.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.9.0" />
<PackageVersion Include="PdfPig" Version="0.1.9" />
<PackageVersion Include="Pinecone.NET" Version="2.1.1" />
<PackageVersion Include="Pinecone.Client" Version="2.1.0" />
<PackageVersion Include="Prompty.Core" Version="0.0.23-alpha" />
<PackageVersion Include="PuppeteerSharp" Version="20.0.5" />
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.1" />
Expand Down
15 changes: 15 additions & 0 deletions dotnet/SK-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CosmosMongoDBIntegrationTes
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureAISearchIntegrationTests", "src\VectorDataIntegrationTests\AzureAISearchIntegrationTests\AzureAISearchIntegrationTests.csproj", "{06181F0F-A375-43AE-B45F-73CBCFC30C14}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PineconeIntegrationTests", "src\VectorDataIntegrationTests\PineconeIntegrationTests\PineconeIntegrationTests.csproj", "{9D37CD08-620D-4AAC-9FEC-A8126AD8AB56}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Agents.AzureAI", "src\Agents\AzureAI\Agents.AzureAI.csproj", "{EA35F1B5-9148-4189-BE34-5E00AED56D65}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugins.AI", "src\Plugins\Plugins.AI\Plugins.AI.csproj", "{0C64EC81-8116-4388-87AD-BA14D4B59974}"
Expand Down Expand Up @@ -1149,6 +1151,12 @@ Global
{39EAB599-742F-417D-AF80-95F90376BB18}.Publish|Any CPU.Build.0 = Publish|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Release|Any CPU.ActiveCfg = Release|Any CPU
{39EAB599-742F-417D-AF80-95F90376BB18}.Release|Any CPU.Build.0 = Release|Any CPU
{232E1153-6366-4175-A982-D66B30AAD610}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{232E1153-6366-4175-A982-D66B30AAD610}.Debug|Any CPU.Build.0 = Debug|Any CPU
{232E1153-6366-4175-A982-D66B30AAD610}.Publish|Any CPU.ActiveCfg = Debug|Any CPU
{232E1153-6366-4175-A982-D66B30AAD610}.Publish|Any CPU.Build.0 = Debug|Any CPU
{232E1153-6366-4175-A982-D66B30AAD610}.Release|Any CPU.ActiveCfg = Release|Any CPU
{232E1153-6366-4175-A982-D66B30AAD610}.Release|Any CPU.Build.0 = Release|Any CPU
{DAC54048-A39A-4739-8307-EA5A291F2EA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DAC54048-A39A-4739-8307-EA5A291F2EA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DAC54048-A39A-4739-8307-EA5A291F2EA0}.Publish|Any CPU.ActiveCfg = Debug|Any CPU
Expand Down Expand Up @@ -1287,6 +1295,12 @@ Global
{06181F0F-A375-43AE-B45F-73CBCFC30C14}.Publish|Any CPU.Build.0 = Debug|Any CPU
{06181F0F-A375-43AE-B45F-73CBCFC30C14}.Release|Any CPU.ActiveCfg = Release|Any CPU
{06181F0F-A375-43AE-B45F-73CBCFC30C14}.Release|Any CPU.Build.0 = Release|Any CPU
{9D37CD08-620D-4AAC-9FEC-A8126AD8AB56}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9D37CD08-620D-4AAC-9FEC-A8126AD8AB56}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9D37CD08-620D-4AAC-9FEC-A8126AD8AB56}.Publish|Any CPU.ActiveCfg = Debug|Any CPU
{9D37CD08-620D-4AAC-9FEC-A8126AD8AB56}.Publish|Any CPU.Build.0 = Debug|Any CPU
{9D37CD08-620D-4AAC-9FEC-A8126AD8AB56}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9D37CD08-620D-4AAC-9FEC-A8126AD8AB56}.Release|Any CPU.Build.0 = Release|Any CPU
{EA35F1B5-9148-4189-BE34-5E00AED56D65}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA35F1B5-9148-4189-BE34-5E00AED56D65}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA35F1B5-9148-4189-BE34-5E00AED56D65}.Publish|Any CPU.ActiveCfg = Publish|Any CPU
Expand Down Expand Up @@ -1537,6 +1551,7 @@ Global
{A0E65043-6B00-4836-850F-000A52238914} = {4F381919-F1BE-47D8-8558-3187ED04A84F}
{11DFBF14-6FBA-41F0-B7F3-A288952D6FDB} = {4F381919-F1BE-47D8-8558-3187ED04A84F}
{06181F0F-A375-43AE-B45F-73CBCFC30C14} = {4F381919-F1BE-47D8-8558-3187ED04A84F}
{9D37CD08-620D-4AAC-9FEC-A8126AD8AB56} = {4F381919-F1BE-47D8-8558-3187ED04A84F}
{EA35F1B5-9148-4189-BE34-5E00AED56D65} = {6823CD5E-2ABE-41EB-B865-F86EC13F0CF9}
{0C64EC81-8116-4388-87AD-BA14D4B59974} = {D6D598DF-C17C-46F4-B2B9-CDE82E2DE132}
{03ACF9DD-00C9-4F2B-80F1-537E2151AF5F} = {D6D598DF-C17C-46F4-B2B9-CDE82E2DE132}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@
<Description>Pinecone connector for Semantic Kernel plugins and semantic memory</Description>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)'!='Publish'">
<DefineConstants>$(DefineConstants);NON_PUBLISH</DefineConstants>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Pinecone.NET" />
<PackageReference Include="Pinecone.Client" />
<PackageReference Include="System.Text.Json" />
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,17 @@ public PineconeGenericDataModelMapper(
/// <inheritdoc />
public Vector MapFromDataToStorageModel(VectorStoreGenericDataModel<string> dataModel)
{
var metadata = new MetadataMap();
var metadata = new Metadata();

// Map data properties.
foreach (var dataProperty in this._propertyReader.DataProperties)
{
if (dataModel.Data.TryGetValue(dataProperty.DataModelPropertyName, out var propertyValue))
{
var propertyStorageName = this._propertyReader.GetStoragePropertyName(dataProperty.DataModelPropertyName);
metadata[propertyStorageName] = propertyValue == null ?
new MetadataValue() :
PineconeVectorStoreRecordFieldMapping.ConvertToMetadataValue(propertyValue);
metadata[propertyStorageName] = propertyValue is not null
? PineconeVectorStoreRecordFieldMapping.ConvertToMetadataValue(propertyValue)
: null;
}
}

Expand All @@ -62,8 +62,8 @@ public Vector MapFromDataToStorageModel(VectorStoreGenericDataModel<string> data
// TODO: what about sparse values?
var result = new Vector
{
Id = (string)dataModel.Key,
Values = values.ToArray(),
Id = dataModel.Key,
Values = values,
Metadata = metadata,
SparseValues = null
};
Expand All @@ -80,7 +80,7 @@ public VectorStoreGenericDataModel<string> MapFromStorageToDataModel(Vector stor
// Set Vector.
if (options?.IncludeVectors is true)
{
dataModel.Vectors.Add(this._propertyReader.FirstVectorPropertyName!, new ReadOnlyMemory<float>(storageModel.Values));
dataModel.Vectors.Add(this._propertyReader.FirstVectorPropertyName!, storageModel.Values);
}

// Set Data.
Expand All @@ -91,9 +91,10 @@ public VectorStoreGenericDataModel<string> MapFromStorageToDataModel(Vector stor
var propertyStorageName = this._propertyReader.GetStoragePropertyName(dataProperty.DataModelPropertyName);
if (storageModel.Metadata.TryGetValue(propertyStorageName, out var propertyValue))
{
dataModel.Data[dataProperty.DataModelPropertyName] = PineconeVectorStoreRecordFieldMapping.ConvertFromMetadataValueToNativeType(
propertyValue,
dataProperty.PropertyType);
dataModel.Data[dataProperty.DataModelPropertyName] =
propertyValue is not null
? PineconeVectorStoreRecordFieldMapping.ConvertFromMetadataValueToNativeType(propertyValue, dataProperty.PropertyType)
: null;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;
using Grpc.Core;
using Microsoft.Extensions.VectorData;
using Pinecone;
using Sdk = Pinecone;
Expand All @@ -20,7 +19,6 @@ namespace Microsoft.SemanticKernel.Connectors.Pinecone;
public class PineconeVectorStore : IVectorStore
{
private const string DatabaseName = "Pinecone";
private const string ListCollectionsName = "ListCollections";

private readonly Sdk.PineconeClient _pineconeClient;
private readonly PineconeVectorStoreOptions _options;
Expand Down Expand Up @@ -63,24 +61,27 @@ public virtual IVectorStoreRecordCollection<TKey, TRecord> GetCollection<TKey, T
/// <inheritdoc />
public virtual async IAsyncEnumerable<string> ListCollectionNamesAsync([EnumeratorCancellation] CancellationToken cancellationToken = default)
{
IndexDetails[] collections;
IndexList indexList;

try
{
collections = await this._pineconeClient.ListIndexes(cancellationToken).ConfigureAwait(false);
indexList = await this._pineconeClient.ListIndexesAsync(cancellationToken: cancellationToken).ConfigureAwait(false);
}
catch (RpcException ex)
catch (PineconeApiException ex)
{
throw new VectorStoreOperationException("Call to vector store failed.", ex)
{
VectorStoreType = DatabaseName,
OperationName = ListCollectionsName
OperationName = "ListCollections"
};
}

foreach (var collection in collections)
if (indexList.Indexes is not null)
{
yield return collection.Name;
foreach (var index in indexList.Indexes)
{
yield return index.Name;
}
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ internal static class PineconeVectorStoreCollectionSearchMapping
{
#pragma warning disable CS0618 // FilterClause is obsolete
/// <summary>
/// Build a Pinecone <see cref="MetadataMap"/> from a set of filter clauses.
/// Build a Pinecone <see cref="Metadata"/> from a set of filter clauses.
/// </summary>
/// <param name="filterClauses">The filter clauses to build the Pinecone <see cref="MetadataMap"/> from.</param>
/// <param name="filterClauses">The filter clauses to build the Pinecone <see cref="Metadata"/> from.</param>
/// <param name="storagePropertyNamesMap">A mapping from property name to the name under which the property would be stored.</param>
/// <returns>The Pinecone <see cref="MetadataMap"/>.</returns>
/// <returns>The Pinecone <see cref="Metadata"/>.</returns>
/// <exception cref="InvalidOperationException">Thrown for invalid property names, value types or filter clause types.</exception>
public static MetadataMap BuildSearchFilter(IEnumerable<FilterClause>? filterClauses, IReadOnlyDictionary<string, string> storagePropertyNamesMap)
public static Metadata BuildSearchFilter(IEnumerable<FilterClause>? filterClauses, IReadOnlyDictionary<string, string> storagePropertyNamesMap)
{
var metadataMap = new MetadataMap();
var metadataMap = new Metadata();

if (filterClauses is null)
{
Expand All @@ -46,7 +46,6 @@ public static MetadataMap BuildSearchFilter(IEnumerable<FilterClause>? filterCla
bool boolValue => (MetadataValue)boolValue,
float floatValue => (MetadataValue)floatValue,
double doubleValue => (MetadataValue)doubleValue,
decimal decimalValue => (MetadataValue)decimalValue,
_ => throw new InvalidOperationException($"Unsupported filter value type '{equalToFilterClause.Value.GetType().Name}'.")
};

Expand Down
Loading
Loading