Skip to content

[Feature]: Lower default top_k from 8 to 5 to reduce token usage #36

@iamvirul

Description

@iamvirul

Problem Statement

The default top_k=8 returns 8 full code chunks on every search_code call. For most queries, the answer is found in the top 2–3 results. The extra 5–6 results consume Claude tokens without contributing to the answer.

Proposed Solution

Lower the default from top_k=8 to top_k=5:

@mcp.tool()
def search_code(query: str, path: str, top_k: int = 5) -> str:

Users who need broader coverage can still pass top_k=8 or higher (up to 20) explicitly.

Alternatives Considered

  • Keeping top_k=8: current behaviour, higher token cost per search
  • Dynamic top_k based on score distribution: more complex, not worth the added complexity

Additional Context

  • Low quality risk: for simple queries (find a function, find a class) top 5 is always sufficient. For complex architectural queries the user can explicitly request more results.
  • Combined with the min_score threshold (issue [Feature]: Add minimum score threshold to filter low-relevance search results #35), the effective number of results returned will already be naturally lower without needing to reduce top_k.
  • README example output should be updated to reflect the new default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions