Registry Mirror
Skip to content

Core: a topK of NaN makes the built-in retrievers return no sources #598

Closed

Description

@anurag629

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.
  • A patch changeset for @chatcops/core.

Comment on this issue to be assigned.

Activity

  1. added
    bug
    core
    on Nov 12, 2026
  2. bhushan4work commented on Nov 13, 2026

    @bhushan4work
    Collaborator

    would like to pick this one, will raise a pr once implementation is ready

  3. self-assigned this
    on Nov 13, 2026
  4. anurag629 commented on Nov 13, 2026

    @anurag629
    MemberAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugcore

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions