Skip to content
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

.Net: Pinecone connector PineconeClient will not deserialize pod_type due to converter priority #4702

Closed
royaltie-roman opened this issue Jan 22, 2024 · 3 comments
Assignees
Labels
.NET Issue or Pull requests regarding .NET code stale Issue is stale because it has been open for 90 days with no activity

Comments

@royaltie-roman
Copy link

Describe the bug

In PineconeClient there is a line that always breaks

public async Task<PineconeIndex?> DescribeIndexAsync(string indexName, CancellationToken cancellationToken = default)
{
      // .... 
      PineconeIndex? indexDescription = JsonSerializer.Deserialize<PineconeIndex>(responseContent, this._jsonSerializerOptions);
      // .... 
}

with the following error:

The JSON value could not be converted to Microsoft.SemanticKernel.Connectors.Memory.Pinecone.Model.PodType. Path: $.database.pod_type | LineNumber: 0 | BytePositionInLine: 144.

My research shows that this is because in PineconeUtils.cs there is line

    internal static JsonSerializerOptions DefaultSerializerOptions { get; } = new()
    {
        // ....
        Converters = { new JsonStringEnumConverter(JsonNamingPolicy.CamelCase) },
    };

So, custom converter PodTypeJsonConverter for PodType enum will be added AFTER the enum converter and, as result, will never be called because default converter will error out.

To Reproduce

Happens on every call to get Pinecone index info.

Expected behavior

Custom converter for PodType should be called first.

Workaround

To whoever has the same issue, here is ABSOLUTELY UGLY workaround

    // Call this somewhere from static constructor
    public static void FixPineconePodTypeConverter()
    {
        var pineconeUtilsType = typeof(PineconeUtils);
        var optionsProperty = pineconeUtilsType.GetProperty("DefaultSerializerOptions", BindingFlags.NonPublic | BindingFlags.Static)!;
        var jsonOptions = (JsonSerializerOptions)optionsProperty.GetValue(null)!;
        var converterType = pineconeUtilsType.Assembly.GetType("Microsoft.SemanticKernel.Connectors.Memory.Pinecone.Model.PodTypeJsonConverter", true)!;
        var converterInstance = (JsonConverter<PodType>)Activator.CreateInstance(converterType, true)!;
        if (jsonOptions.Converters.All(c => c.GetType() != converterType))
        {
            jsonOptions.Converters.Insert(0, converterInstance!);
        }
    }
@shawncal shawncal added .NET Issue or Pull requests regarding .NET code triage labels Jan 22, 2024
@github-actions github-actions bot changed the title Pinecone connector PineconeClient will not deserialize pod_type due to converter priority .Net: Pinecone connector PineconeClient will not deserialize pod_type due to converter priority Jan 22, 2024
@royaltie-roman
Copy link
Author

royaltie-roman commented Jan 22, 2024

I can also add that starter plan is now returning nano instead. This value is not a part of PodType enum, so it will also break for everyone using free plan I guess. This is another issue though. Just sayin.

github-merge-queue bot pushed a commit that referenced this issue Feb 6, 2024
### Motivation and Context

I came across the same
[issue](#4702 (comment))
mentioned in issue #4702 on GitHub. The problem is related to Pinecone
connector’s inability to deserialize the “nano” pod type, which is the
free tier of Pinecone. Previously the pod type for free tier was
“starter”.

It seems like a minor issue, but it’s currently blocking me from
proceeding. I would appreciate it if this bug could be addressed soon,
rather than being left on the backlog for an extended period of time.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

Co-authored-by: Imir Kalkanci <ikalkanci@collectors.com>
Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com>
Copy link

This issue is stale because it has been open for 90 days with no activity.

@github-actions github-actions bot added the stale Issue is stale because it has been open for 90 days with no activity label Apr 23, 2024
Copy link

github-actions bot commented May 7, 2024

This issue was closed because it has been inactive for 14 days since being marked as stale.

@github-actions github-actions bot closed this as completed May 7, 2024
Bryan-Roe pushed a commit to Bryan-Roe/semantic-kernel that referenced this issue Oct 6, 2024
)

### Motivation and Context

I came across the same
[issue](microsoft#4702 (comment))
mentioned in issue microsoft#4702 on GitHub. The problem is related to Pinecone
connector’s inability to deserialize the “nano” pod type, which is the
free tier of Pinecone. Previously the pod type for free tier was
“starter”.

It seems like a minor issue, but it’s currently blocking me from
proceeding. I would appreciate it if this bug could be addressed soon,
rather than being left on the backlog for an extended period of time.

### Description

<!-- Describe your changes, the overall approach, the underlying design.
These notes will help understanding how your code works. Thanks! -->

### Contribution Checklist

<!-- Before submitting this PR, please make sure: -->

- [x] The code builds clean without any errors or warnings
- [x] The PR follows the [SK Contribution
Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md)
and the [pre-submission formatting
script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts)
raises no violations
- [x] All unit tests pass, and I have added new tests where possible
- [x] I didn't break anyone 😄

Co-authored-by: Imir Kalkanci <ikalkanci@collectors.com>
Co-authored-by: Dmytro Struk <13853051+dmytrostruk@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
.NET Issue or Pull requests regarding .NET code stale Issue is stale because it has been open for 90 days with no activity
Projects
Archived in project
Development

No branches or pull requests

4 participants