Skip to content

fix(docs): forward top_n to rerank in gen-qa-openai notebook - #628

Open
RaphaelFakhri wants to merge 1 commit into
pinecone-io:mainfrom
RaphaelFakhri:fix/gen-qa-openai-rerank-top-n
Open

RaphaelFakhri wants to merge 1 commit into
pinecone-io:mainfrom
RaphaelFakhri:fix/gen-qa-openai-rerank-top-n

Conversation

@RaphaelFakhri

@RaphaelFakhri RaphaelFakhri commented Oct 19, 2026 •

Copy link
Copy Markdown

Problem

In docs/gen-qa-openai.ipynb, rerank(query, results, top_n=5) ignores its top_n argument and always sends top_n=10 to pc.inference.rerank. As a result:

  • cascading_retrieval(..., top_n=5) in the "Cascading Retrieval" section returns 10 papers instead of 5.
  • rag(query) asks for top_n=5, but the prompt sent to gpt-4o-mini contains 10 papers, which doubles the context size and token cost and contradicts the notebook text ("returning the top_n results").

Solution

Pass the top_n argument through to pc.inference.rerank. This is a one-line change.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Test plan

The repository has no unit test harness for notebooks, so the cell that defines query_pinecone, dedupe, rerank and cascading_retrieval was executed against stub pc and index objects that record the arguments sent to pc.inference.rerank:

  • Before the change: top_n=3 and top_n=5 both send top_n=10 and return 10 results (0 passed, 2 failed).
  • After the change: top_n=3 returns 3 results and top_n=5 returns 5 results (2 passed, 0 failed).

ruff check, ruff format --check, codespell and the four notebook checks from the lint workflow (check-secrets, check-structure, check-timeless, check-pinning) pass on the changed notebook.


Note

Low Risk
Documentation-only notebook fix with no production code or security impact.

Overview
Fixes a bug in the gen-qa-openai notebook where rerank() accepted a top_n argument but always called pc.inference.rerank with a hardcoded top_n=10.

The call now passes through the function’s top_n parameter, so cascading_retrieval and rag honor values like top_n=5 instead of returning ten papers and inflating the RAG prompt sent to gpt-4o-mini.

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

rerank() accepted a top_n argument but always sent top_n=10 to
pc.inference.rerank, so cascading_retrieval() and rag() returned 10
papers no matter which top_n the caller passed. Pass the argument
through.
@RaphaelFakhri
RaphaelFakhri requested a review from a team as a code owner October 19, 2026 08:03
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