microsoft/semantic-kernel · error · MemoryConnectorInitializationError

Failed to create Pinecone settings.

Error message

Failed to create Pinecone settings.

What it means

Raised in PineconeMemoryStore.__init__ when constructing PineconeSettings raises a pydantic ValidationError. The settings object resolves the API key from the constructor arg or .env fallback; if validation fails (most often a missing/empty API key), the error is wrapped as MemoryConnectorInitializationError with the original ValidationError chained via 'from ex'. The Pinecone client is never created.

Source

Thrown at python/semantic_kernel/connectors/memory_stores/pinecone/pinecone_memory_store.py:77

        Args:
            api_key (str): The Pinecone API key.
            default_dimensionality (int): The default dimensionality to use for new collections.
            env_file_path (str | None): Use the environment settings file as a fallback
                to environment variables. (Optional)
            env_file_encoding (str | None): The encoding of the environment settings file. (Optional)
        """
        if default_dimensionality > MAX_DIMENSIONALITY:
            raise MemoryConnectorInitializationError(
                f"Dimensionality of {default_dimensionality} exceeds the maximum allowed value of {MAX_DIMENSIONALITY}."
            )
        try:
            pinecone_settings = PineconeSettings(
                api_key=api_key,
                env_file_path=env_file_path,
                env_file_encoding=env_file_encoding,
            )
        except ValidationError as ex:
            raise MemoryConnectorInitializationError("Failed to create Pinecone settings.", ex) from ex

        self._default_dimensionality = default_dimensionality

        self.pinecone = Pinecone(api_key=pinecone_settings.api_key.get_secret_value())
        self.collection_names_cache = set()

    async def create_collection(
        self,
        collection_name: str,
        dimension_num: int | None = None,
        distance_type: str | None = "cosine",
        index_spec: NamedTuple = DEFAULT_INDEX_SPEC,
    ) -> None:
        """Creates a new collection in Pinecone if it does not exist.

        This function creates an index, by default the following index
        settings are used: metric = cosine, cloud = aws, region = us-east-1.

View on GitHub (pinned to c028a0c7dc)

Solutions

  1. Set the PINECONE_API_KEY environment variable, or pass api_key explicitly to the constructor.
  2. Inspect the chained ValidationError (ex) in the traceback to see exactly which field failed.
  3. Verify env_file_path points to a readable .env containing a valid PINECONE_API_KEY.
  4. Migrate to PineconeStore + Collection and supply settings there.

Example fix

// before
store = PineconeMemoryStore(api_key=None, default_dimensionality=1536)

// after
import os
key = os.environ["PINECONE_API_KEY"]  # fail loudly if missing
store = PineconeMemoryStore(api_key=key, default_dimensionality=1536)
Defensive patterns

Strategy: try-catch

Validate before calling

import os
api_key = api_key or os.environ.get("PINECONE_API_KEY")
if not api_key:
    raise RuntimeError("PINECONE_API_KEY is required")
store = PineconeMemoryStore(api_key=api_key, default_dimensionality=1536)

Type guard

def has_pinecone_credentials() -> bool:
    return bool(os.environ.get("PINECONE_API_KEY"))

Try / catch

from semantic_kernel.exceptions.memory_connector_exceptions import MemoryConnectorInitializationError
try:
    store = PineconeMemoryStore(api_key=key, default_dimensionality=1536)
except MemoryConnectorInitializationError as e:
    # e.__cause__ is the pydantic ValidationError with the failing field
    raise SystemExit(f"Pinecone settings invalid: {e.__cause__}") from e

Prevention

When it happens

Trigger: Constructing PineconeMemoryStore without an api_key and with no PINECONE_API_KEY environment variable or .env file; providing an empty/None api_key; a malformed .env at the given env_file_path.

Common situations: Deploying without the PINECONE_API_KEY secret set; .env file not loaded in the deployed environment; api_key pulled from a secret manager that returned None; env_file_encoding mismatch corrupting the parsed value.

Related errors


AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13). Data as JSON: /api/errors/c6bc07d115991f3d. Report an issue: GitHub.