ragflow icon indicating copy to clipboard operation
ragflow copied to clipboard

[Question]: top_k in retrieval_testing

Open nevergone123 opened this issue 11 months ago • 3 comments

Describe your problem

I set top_k=10 before retrieval_testing, but more than 10 chunks retrieved. What's the actual meaning of top_k?

nevergone123 avatar Feb 08 '25 08:02 nevergone123

Top K control how many retrievals are involved with KNN calculation.

KevinHuSh avatar Feb 08 '25 10:02 KevinHuSh

It seems top_k is used by rerank model. If 500 chunks is retrieved (sorted by vector similarity),and top_k is 100.
Then only the first 100 chunks will be involved in the rerank process and obtain new scores. The rest 400 chunks remain using vector similiarity score.

After that, 500 chunks will be resorted refer to their scores. Is that right? By the way, what controls the number of chunks that return?

nevergone123 avatar Mar 05 '25 13:03 nevergone123

Yes, it's right. I think it's top N.

KevinHuSh avatar Mar 06 '25 09:03 KevinHuSh

@KevinHuSh @nevergone123 I’d like to clarify the current behavior.

Currently, it looks like:

top_k controls the number of chunks retrieved using vector similarity (e.g., 1024).

RERANK_LIMIT is hardcoded (currently 64) and defines how many of those chunks are passed to the reranker for scoring /rag/nlp/search.py.

top_n defines how many chunks are returned as the final result after reranking or fallback to vector similarity scores (e.g., 8).

So even if top_k=1024, only the top 64 (as per RERANK_LIMIT) are reranked/

There is currently no UI or config option to control how many chunks are passed to the reranker — it's fixed in the code RERANK_LIMIT.

z-vishal avatar May 08 '25 04:05 z-vishal