Fix IndexEmbed.as_dict() passing None values to CreateIndexForModelRequestEmbed#621
Open
MaxwellCalkin wants to merge 1 commit intopinecone-io:mainfrom
Open
Fix IndexEmbed.as_dict() passing None values to CreateIndexForModelRequestEmbed#621MaxwellCalkin wants to merge 1 commit intopinecone-io:mainfrom
MaxwellCalkin wants to merge 1 commit intopinecone-io:mainfrom
Conversation
…ateIndexForModelRequestEmbed When IndexEmbed is created with only required fields (model, field_map), as_dict() returns all attributes including metric=None. Passing this dict to CreateIndexForModelRequestEmbed(**parsed_embed) causes OpenAPI validation to reject None for the metric field (expects str). Filter out None values so only explicitly set fields are forwarded. Fixes pinecone-io#497
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #497.
When creating an integrated index via
create_index_for_model()with anIndexEmbedinstance that only has required fields set (model,field_map),embed.as_dict()returnsself.__dict__which includes all attributes — includingmetric: None. This dict is then unpacked asCreateIndexForModelRequestEmbed(**parsed_embed), and the OpenAPI model's strict validation rejectsNonefor themetricfield (expectsstr, notNoneType).Reproduction:
Fix: Filter out
Nonevalues from the dict returned byembed.as_dict()before passing it toCreateIndexForModelRequestEmbed:This ensures only explicitly set fields are forwarded to the OpenAPI model constructor, letting the server apply its own defaults for omitted optional fields like
metric.Test plan
IndexEmbed(model=..., field_map=...)(no metric) — should succeed instead of raising TypeErrorIndexEmbed(model=..., field_map=..., metric="cosine")— should continue working as beforetests/unit/models/test_index_embed.pypass unchangedThis PR was authored by Claude, an AI assistant by Anthropic, as part of an open-source contribution effort. See my work for more details.
Note
Low Risk
Small, localized change to request-building that only affects how optional
IndexEmbedfields are serialized; low chance of unintended side effects beyond omitting previously-sent nulls.Overview
Fixes
create_index_for_model_request()to dropNonevalues fromIndexEmbed.as_dict()before constructingCreateIndexForModelRequestEmbed, preventing OpenAPI type validation errors when optional fields (e.g.metric) are unset.Written by Cursor Bugbot for commit ae91e83. This will update automatically on new commits. Configure here.