Skip to content

Fix broken import and embed() retry bug in rerankers notebook#583

Open
amaralazizy wants to merge 1 commit into
pinecone-io:mainfrom
amaralazizy:fix/rerankers-notebook-modern-imports
Open

Fix broken import and embed() retry bug in rerankers notebook#583
amaralazizy wants to merge 1 commit into
pinecone-io:mainfrom
amaralazizy:fix/rerankers-notebook-modern-imports

Conversation

@amaralazizy
Copy link
Copy Markdown

@amaralazizy amaralazizy commented May 28, 2026

Summary

Two fixes to learn/generation/better-rag/00-rerankers-pinecone.ipynb:

  1. Broken import. pinecone_plugins.inference.core.client.exceptions.PineconeApiException no longer exists in current pinecone[grpc] releases (the plugin module's exceptions.py is empty). The notebook fails immediately on cell 18 with ImportError. Replaced with pinecone.exceptions.PineconeApiException.

  2. embed() retry-loop bugs:

    • passed was never initialized — if all 5 retries failed, if not passed raised UnboundLocalError instead of the intended RuntimeError. Now initialized to False at the top of the function.
    • The loop had no break after success, so every batch issued all 5 API calls even when the first one succeeded. This compounds with embedding rate limits and makes indexing extremely slow (I was seeing ~25s per batch with constant 429s before this fix).
    • except PineconeApiException: swallowed the exception, so the only feedback was a bare "Retrying...". Now prints f"Retry {j}: {e}" so users can see whether it's rate limiting, auth, quota, etc.

Test plan

  • Notebook imports cell 18 successfully against current pinecone[grpc]==5.1.0.
  • embed() raises RuntimeError (not UnboundLocalError) when all retries fail.
  • Successful embed calls stop the retry loop immediately (1 API call per batch, not 5).

Note

Low Risk
Documentation-only notebook changes with no production code; low risk aside from verifying the new import matches the pinned Pinecone version.

Overview
Updates 00-rerankers-pinecone.ipynb so it runs against current pinecone[grpc] and indexes batches without redundant API calls.

PineconeApiException is imported from pinecone.exceptions instead of the removed plugin path, so the embedding cell no longer fails on import.

The embed() retry helper now initializes passed = False, breaks after a successful pc.inference.embed, and logs Retry {j}: {e} on failure so exhausted retries raise RuntimeError instead of UnboundLocalError, and successful batches stop after one call instead of five.

Also fixes the notebook JSON trailing newline.

Reviewed by Cursor Bugbot for commit 95b55c5. Bugbot is set up for automated code reviews on this repo. Configure here.

- 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...".
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.

1 participant