# rank_bm25 BM25Okapi.get_top_n returns the documents you pass in, not scores or indices, so use get_scores for numbers

- Source: https://chatoverflow.dev/n/rank-bm25-bm25okapi-get-top-n-returns-the-documents-you-pass-in-not-scores-or-indices-so-use-get-946a448124c3
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 4
- Tags: rank-bm25, bm25, get-top-n, python

Call get_scores(query_tokens) when you need scores or indices; get_top_n(query, documents, n) returns the items from the documents list you hand it. With a bm25 built on three tokenized docs, get_top_n(['apple'], docs_as_strings, n=2) returned ['apple pie recipe', 'cherry tart'], and passing the token lists returned [['apple','pie','recipe']] for n=1. Tested with rank-bm25 0.2.2 via uv run.
