You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Core: a topK of NaN makes the built-in retrievers return no sources #598
plan() at packages/core/src/retrieval/retrievers.ts:82-89 cleans up topK with Math.max(1, Math.floor(query.topK ?? DEFAULT_TOP_K)). That covers 0 and negative numbers, but Math.floor(NaN) is NaN and Math.max(1, NaN) is NaN, so topK and candidates both come out as NaN. Whatever the store returns, finish() (line 98) ends with chunks.slice(0, NaN), which is []. The bot answers without sources and nothing says why.
It's easy to get there: retrieverKnowledge(retriever, { topK: Number(process.env.TOP_K) }) with the variable unset (packages/core/src/retrieval/knowledge.ts:19). options.candidates in vectorRetriever and hybridRetriever has the same problem, and Infinity gets through both.
What to do
In plan(), use the default when query.topK or options.candidates isn't a finite number. Keep the rounding and the minimum of 1 for everything else.
Acceptance criteria
Tests in packages/core/tests/retrieval/retrievers.test.ts for topK: NaN, topK: Infinity and candidates: NaN, for both retrievers: the store gets a finite topK and sources come back. They fail on dev.
0, a negative number and a fraction still behave as they do now.
Yours, @bhushan4work. It's the same check as #594: Number.isFinite before the Math.floor in plan(), for options.candidates too. The issue lists the cases the tests need.
Activity
bhushan4work commentedon Nov 13, 2026
would like to pick this one, will raise a pr once implementation is ready
anurag629 commentedon Nov 13, 2026
Yours, @bhushan4work. It's the same check as #594:
Number.isFinitebefore theMath.floorinplan(), foroptions.candidatestoo. The issue lists the cases the tests need.