From 95b55c5402f880fa3b96868b42cea75ce2ef894e Mon Sep 17 00:00:00 2001 From: amaralazizy Date: Thu, 28 May 2026 21:30:57 +0300 Subject: [PATCH] Fix broken import and embed() retry bug in rerankers notebook - Replace `pinecone_plugins.inference.core.client.exceptions.PineconeApiException` with `pinecone.exceptions.PineconeApiException`. The plugin module no longer exports this symbol in current `pinecone[grpc]` releases, so the notebook fails at import. - Initialize `passed = False` inside `embed()` so total failure raises the intended `RuntimeError` instead of `UnboundLocalError`. - `break` after a successful embed call, instead of continuing to issue the remaining retry-loop iterations. Previously every batch made 5 API calls even on success, which hit rate limits and made indexing extremely slow. - Print the actual `PineconeApiException` on retry so users can diagnose rate-limit / auth / quota errors instead of seeing a bare "Retrying...". --- .../generation/better-rag/00-rerankers-pinecone.ipynb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/learn/generation/better-rag/00-rerankers-pinecone.ipynb b/learn/generation/better-rag/00-rerankers-pinecone.ipynb index a523ab0e..ded86eb5 100644 --- a/learn/generation/better-rag/00-rerankers-pinecone.ipynb +++ b/learn/generation/better-rag/00-rerankers-pinecone.ipynb @@ -517,9 +517,10 @@ }, "outputs": [], "source": [ - "from pinecone_plugins.inference.core.client.exceptions import PineconeApiException\n", + "from pinecone.exceptions import PineconeApiException\n", "\n", "def embed(batch: list[str]) -> list[float]:\n", + " passed = False\n", " # create embeddings (exponential backoff to avoid RateLimitError)\n", " for j in range(5): # max 5 retries\n", " try:\n", @@ -532,9 +533,10 @@ " }\n", " )\n", " passed = True\n", - " except PineconeApiException:\n", + " break\n", + " except PineconeApiException as e:\n", + " print(f\"Retry {j}: {e}\")\n", " time.sleep(2**j) # wait 2^j seconds before retrying\n", - " print(\"Retrying...\")\n", " if not passed:\n", " raise RuntimeError(\"Failed to create embeddings.\")\n", " # get embeddings\n", @@ -1946,4 +1948,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +}