Open
Description
Is this a new bug?
I think this bug was introduced in v6.0. I can reproduce it with the following versions:
7.0.0
6.0.2
6.0.1
6.0.0
I tried 5.4.2 but the upgrade to
6.0` was a significant enough refactor that my script below would need to be rewritten.
- I believe this is a new bug
- I have searched the existing Github issues and Community Forum, and I could not find an existing post for this bug
Describe the bug
If you try to crate an index and pass in an IndexEmbed
object it will fail. If you do the same but pass in a dict
with the same contents it succeeds.
Error information
If you call pinecone.create_index_for_model
with otherwise valid inputs you get:
Traceback (most recent call last):
File "/Users/username/code/backend/.venv/lib/python3.13/site-packages/pinecone/pinecone.py", line 214, in create_index_for_model
return self.db.index.create_for_model(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
name=name,
^^^^^^^^^^
...<5 lines>...
timeout=timeout,
^^^^^^^^^^^^^^^^
)
^
File "/Users/username/code/backend/.venv/lib/python3.13/site-packages/pinecone/utils/require_kwargs.py", line 14, in wrapper
return func(*args, **kwargs)
File "/Users/username/code/backend/.venv/lib/python3.13/site-packages/pinecone/db_control/resources/sync/index.py", line 98, in create_for_model
req = PineconeDBControlRequestFactory.create_index_for_model_request(
name=name,
...<4 lines>...
deletion_protection=deletion_protection,
)
File "/Users/username/code/backend/.venv/lib/python3.13/site-packages/pinecone/db_control/request_factory.py", line 214, in create_index_for_model_request
("embed", CreateIndexForModelRequestEmbed(**parsed_embed)),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
File "/Users/username/code/backend/.venv/lib/python3.13/site-packages/pinecone/openapi_support/model_utils.py", line 36, in wrapped_init
return fn(_self, *args, **kwargs)
File "/Users/username/code/backend/.venv/lib/python3.13/site-packages/pinecone/core/openapi/db_control/model/create_index_for_model_request_embed.py", line 295, in __init__
setattr(self, var_name, var_value)
~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/username/code/backend/.venv/lib/python3.13/site-packages/pinecone/openapi_support/model_utils.py", line 171, in __setattr__
self[attr] = value
~~~~^^^^^^
File "/Users/username/code/backend/.venv/lib/python3.13/site-packages/pinecone/openapi_support/model_utils.py", line 456, in __setitem__
self.set_attribute(name, value)
~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^
File "/Users/username/code/backend/.venv/lib/python3.13/site-packages/pinecone/openapi_support/model_utils.py", line 139, in set_attribute
value = validate_and_convert_types(
value,
...<4 lines>...
configuration=self._configuration,
)
File "/Users/username/code/backend/.venv/lib/python3.13/site-packages/pinecone/openapi_support/model_utils.py", line 1512, in validate_and_convert_types
raise get_type_error(input_value, path_to_item, valid_classes, key_type=False)
Steps to reproduce the issue locally
import platform
from enum import Enum
import pinecone
from pinecone import EmbedModel, IndexEmbed
from pinecone.core.openapi.db_control.model.create_index_for_model_request_embed import (
CreateIndexForModelRequestEmbed,
)
from pinecone.utils import convert_enum_to_string
embed_model = EmbedModel.Multilingual_E5_Large
filed_map_dict = {"text": "chunk_text"}
# extracted from pinecone.db_control.request_factory.py
# PineconeDBControlRequestFactory.create_index_for_model_request()
def partial_create_index_for_model_request(embed: IndexEmbed | dict) -> dict:
if isinstance(embed, IndexEmbed):
parsed_embed = embed.as_dict()
else:
# if dict, we need to parse enum values, if any, to string
# and verify required fields are present
required_fields = ["model", "field_map"]
for field in required_fields:
if field not in embed:
raise ValueError(f"{field} is required in embed")
parsed_embed = {}
for key, value in embed.items():
if isinstance(value, Enum):
parsed_embed[key] = convert_enum_to_string(value)
else:
parsed_embed[key] = value
return parsed_embed
def run_it(embed: IndexEmbed | dict) -> None:
print(f"index embed {type(embed)}: {embed}")
parsed_embed = partial_create_index_for_model_request(embed)
print(f"parsed_embed: {parsed_embed}")
try:
embed_obj = CreateIndexForModelRequestEmbed(**parsed_embed)
print(f"CreateIndexForModelRequestEmbed: {embed_obj}")
except Exception as e:
print(f"CreateIndexForModelRequestEmbed ERROR: {e}")
def run_all() -> None:
print("-- WITH A DICT THIS IS FINE --")
run_it({"model": embed_model, "field_map": filed_map_dict})
print("------------------------------")
print("\n-- WITH AN OBJECT THIS ERRORS --")
run_it(IndexEmbed(model=embed_model, field_map=filed_map_dict))
print("------------------------------")
if __name__ == "__main__":
print("**Environment**")
print(f"OS Version: {platform.platform()}")
print(f"Python version: {platform.python_version()}")
print(f"Python SDK version: {pinecone.__version__}")
print("\n")
run_all()
For me the above outputs:
~ python tools/pinecone_bug.py
**Environment**
OS Version: macOS-15.5-arm64-arm-64bit-Mach-O
Python version: 3.13.3
Python SDK version: 7.0.0
-- WITH A DICT THIS IS FINE --
index embed <class 'dict'>: {'model': <EmbedModel.Multilingual_E5_Large: 'multilingual-e5-large'>, 'field_map': {'text': 'chunk_text'}}
parsed_embed: {'model': 'multilingual-e5-large', 'field_map': {'text': 'chunk_text'}}
CreateIndexForModelRequestEmbed: {'field_map': {'text': 'chunk_text'}, 'model': 'multilingual-e5-large'}
------------------------------
-- WITH AN OBJECT THIS ERRORS --
index embed <class 'pinecone.inference.models.index_embed.IndexEmbed'>: IndexEmbed(model='multilingual-e5-large', field_map={'text': 'chunk_text'}, metric=None, read_parameters={}, write_parameters={})
parsed_embed: {'model': 'multilingual-e5-large', 'field_map': {'text': 'chunk_text'}, 'metric': None, 'read_parameters': {}, 'write_parameters': {}}
CreateIndexForModelRequestEmbed ERROR: Invalid type for variable 'metric'. Required value type is str and passed type was NoneType at ['metric']
------------------------------
Environment
- OS Version:
macOS-15.5-arm64-arm-64bit-Mach-O
- Python version:
3.13.3
- Python SDK version:
7.0.0
Additional context
Add any other context about the problem here.