Skip to content

Fix IndexEmbed.as_dict() passing None values to CreateIndexForModelRequestEmbed#621

Open
MaxwellCalkin wants to merge 1 commit intopinecone-io:mainfrom
MaxwellCalkin:fix/index-embed-none-values
Open

Fix IndexEmbed.as_dict() passing None values to CreateIndexForModelRequestEmbed#621
MaxwellCalkin wants to merge 1 commit intopinecone-io:mainfrom
MaxwellCalkin:fix/index-embed-none-values

Conversation

@MaxwellCalkin
Copy link

@MaxwellCalkin MaxwellCalkin commented Mar 8, 2026

Summary

Fixes #497.

When creating an integrated index via create_index_for_model() with an IndexEmbed instance that only has required fields set (model, field_map), embed.as_dict() returns self.__dict__ which includes all attributes — including metric: None. This dict is then unpacked as CreateIndexForModelRequestEmbed(**parsed_embed), and the OpenAPI model's strict validation rejects None for the metric field (expects str, not NoneType).

Reproduction:

from pinecone import Pinecone, IndexEmbed

pc = Pinecone(api_key="...")
pc.db.index.create_for_model(
    name="test",
    cloud="aws",
    region="us-east-1",
    embed=IndexEmbed(model="multilingual-e5-large", field_map={"text": "my_text_field"})
)
# TypeError: Invalid type for variable 'metric'. Required value type is str ...

Fix: Filter out None values from the dict returned by embed.as_dict() before passing it to CreateIndexForModelRequestEmbed:

# Before:
parsed_embed = embed.as_dict()

# After:
parsed_embed = {k: v for k, v in embed.as_dict().items() if v is not None}

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

  • Create an index with IndexEmbed(model=..., field_map=...) (no metric) — should succeed instead of raising TypeError
  • Create an index with IndexEmbed(model=..., field_map=..., metric="cosine") — should continue working as before
  • Existing unit tests in tests/unit/models/test_index_embed.py pass unchanged

This 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 IndexEmbed fields are serialized; low chance of unintended side effects beyond omitting previously-sent nulls.

Overview
Fixes create_index_for_model_request() to drop None values from IndexEmbed.as_dict() before constructing CreateIndexForModelRequestEmbed, 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.

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] IndexEmbed does not convert to CreateIndexForModelRequestEmbed safely

1 participant