{"record":{"id":"64064faa4418c1df","repo":"mem0ai/mem0","slug":"pinecone-api-key-must-be-provided-either-as-a-para","errorCode":null,"errorMessage":"Pinecone API key must be provided either as a parameter or as an environment variable","messagePattern":"Pinecone API key must be provided either as a parameter or as an environment variable","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"mem0/vector_stores/pinecone.py","lineNumber":63,"sourceCode":"            collection_name (str): Name of the index/collection.\n            embedding_model_dims (int): Dimensions of the embedding model.\n            client (Pinecone, optional): Existing Pinecone client instance. Defaults to None.\n            api_key (str, optional): API key for Pinecone. Defaults to None.\n            environment (str, optional): Pinecone environment. Defaults to None.\n            serverless_config (Dict, optional): Configuration for serverless deployment. Defaults to None.\n            pod_config (Dict, optional): Configuration for pod-based deployment. Defaults to None.\n            hybrid_search (bool, optional): Whether to enable hybrid search. Defaults to False.\n            metric (str, optional): Distance metric for vector similarity. Defaults to \"cosine\".\n            batch_size (int, optional): Batch size for operations. Defaults to 100.\n            extra_params (Dict, optional): Additional parameters for Pinecone client. Defaults to None.\n            namespace (str, optional): Namespace for the collection. Defaults to None.\n        \"\"\"\n        if client:\n            self.client = client\n        else:\n            api_key = api_key or os.environ.get(\"PINECONE_API_KEY\")\n            if not api_key:\n                raise ValueError(\n                    \"Pinecone API key must be provided either as a parameter or as an environment variable\"\n                )\n\n            params = extra_params or {}\n            self.client = Pinecone(api_key=api_key, **params)\n\n        self.collection_name = collection_name\n        self.embedding_model_dims = embedding_model_dims\n        self.environment = environment\n        self.serverless_config = serverless_config\n        self.pod_config = pod_config\n        self.hybrid_search = hybrid_search\n        self.metric = metric\n        self.batch_size = batch_size\n        self.namespace = namespace\n\n        self.sparse_encoder = None\n        if self.hybrid_search:","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0/vector_stores/pinecone.py#L45-L81","documentation":"Raised in Pinecone.__init__ when neither an `api_key` constructor parameter nor a PINECONE_API_KEY environment variable is available. mem0 deliberately fails fast instead of constructing a client that would 401 on first use. Note the `client` short-circuit: passing a pre-built Pinecone client skips the check entirely.","triggerScenarios":"`Pinecone(collection_name=..., embedding_model_dims=...)` with api_key=None and no PINECONE_API_KEY in os.environ; or building Memory with vector_store config `\"provider\": \"pinecone\"` while the key exists only in a .env file that was never loaded into the process env.","commonSituations":"Forgetting python-dotenv/load_dotenv() before creating Memory; running the same code in CI where secrets are injected under a different variable name; shell exports not visible to a systemd service or Docker container; key set only in the deployment platform's UI but not passed to the container.","solutions":["Export the variable in the process that runs mem0: `export PINECONE_API_KEY=...` or load it via python-dotenv before constructing Memory.","Or pass it explicitly in config: `vector_store={\"provider\": \"pinecone\", \"config\": {\"api_key\": os.environ[\"PINECONE_API_KEY\"], ...}}`.","Or inject a pre-built client (`client=Pinecone(api_key=...)`) which bypasses the key lookup — useful when the key lives in a secrets manager."],"exampleFix":"# before\nmemory = Memory.from_config({\"vector_store\": {\"provider\": \"pinecone\", \"config\": {\"collection_name\": \"mem\"}}})\n# ValueError: Pinecone API key must be provided...\n\n# after\nimport os\nfrom dotenv import load_dotenv\nload_dotenv()\nmemory = Memory.from_config({\n    \"vector_store\": {\n        \"provider\": \"pinecone\",\n        \"config\": {\"collection_name\": \"mem\", \"embedding_model_dims\": 1536},\n    }\n})  # picks up PINECONE_API_KEY from env","handlingStrategy":"validation","validationCode":"import os\n\ndef pinecone_ready() -> bool:\n    return bool(os.environ.get(\"PINECONE_API_KEY\"))\n\nif not pinecone_ready():\n    raise SystemExit(\"PINECONE_API_KEY not set; refusing to start with pinecone provider\")","typeGuard":null,"tryCatchPattern":"try:\n    store = Pinecone(collection_name=\"mem\", embedding_model_dims=1536)\nexcept ValueError as e:\n    if \"API key\" in str(e):\n        raise RuntimeError(\"Pinecone credentials missing; check PINECONE_API_KEY in the runtime env\") from e\n    raise","preventionTips":["Load .env files (python-dotenv) as the first statement of the entrypoint, before any Memory construction.","Fail fast at boot on required secrets rather than at first query.","Prefer passing an explicit api_key (or pre-built client) from your secrets manager instead of relying on ambient env."],"tags":["configuration","pinecone","api-key","environment-variables","vector-store"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}