Skip to content

feat(ai): Improve ranker prompt robustness#1567

Merged
topher-lo merged 3 commits intomainfrom
feat/improve-ranker-prompt-robustness
Oct 24, 2025
Merged

feat(ai): Improve ranker prompt robustness#1567
topher-lo merged 3 commits intomainfrom
feat/improve-ranker-prompt-robustness

Conversation

@topher-lo
Copy link
Copy Markdown
Contributor

@topher-lo topher-lo commented Oct 24, 2025

Summary by cubic

Strengthened the ranker by rewriting prompts and validating outputs, and added min/max item limits to support exact or top‑N results. This makes rankings more consistent and lets callers control how many items come back.

  • New Features

    • Added min_items and max_items to rank_items and rank_items_pairwise; supports exact-1 and top‑N results, with local trimming to max.
    • Replaced ranking prompts with clear system/user templates and explicit output instructions; pairwise batches now force return of all IDs.
    • Sanitizes model output: normalizes IDs (e.g., backticks, numeric strings), removes duplicates/extras, and keeps only provided IDs.
    • Registry updates: select_fields now uses min_fields/max_fields; select_field and rank_documents enforce single-item ranking where appropriate. Descriptions now say “most to least relevant.”
  • Migration

    • Replace select_fields(num_fields=...) with min_fields and max_fields (defaults: min=5, max=30).
    • If you need a single best item/field, pass min=max=1 via the new parameters.

@topher-lo topher-lo added the enhancement New feature or request label Oct 24, 2025
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 112 to 117
criteria_prompt=criteria_prompt,
model_name=model_name,
model_provider=model_provider,
min_items=1,
max_items=1,
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Rank documents now returns only one result

The new min_items=1 and max_items=1 arguments passed to rank_items_pairwise and rank_items force the LLM to return exactly one ID. rank_documents previously produced a full ranking and the docstring still advertises a list "from most to least relevant". With these bounds the function will now always return a single document regardless of the input size, dropping the rest of the ordering, which breaks existing callers expecting a complete ranking.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files

Prompt for AI agents (all 1 issues)

Understand the root cause of the following 1 issues and fix them.


<file name="packages/tracecat-registry/tracecat_registry/core/ai.py">

<violation number="1" location="packages/tracecat-registry/tracecat_registry/core/ai.py:107">
Passing max_items=1 here truncates rank_documents to a single document, so the function no longer returns the full ranking it promises.</violation>
</file>

React with 👍 or 👎 to teach cubic. Mention @cubic-dev-ai to give feedback, ask questions, or re-run the review.

num_passes=num_passes,
refinement_ratio=refinement_ratio,
min_items=1,
max_items=1,
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai bot Oct 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing max_items=1 here truncates rank_documents to a single document, so the function no longer returns the full ranking it promises.

Prompt for AI agents
Address the following comment on packages/tracecat-registry/tracecat_registry/core/ai.py at line 107:

<comment>Passing max_items=1 here truncates rank_documents to a single document, so the function no longer returns the full ranking it promises.</comment>

<file context>
@@ -101,13 +103,17 @@ async def rank_documents(
             num_passes=num_passes,
             refinement_ratio=refinement_ratio,
+            min_items=1,
+            max_items=1,
         )
     elif algorithm == &quot;single-pass&quot;:
</file context>
Suggested change
max_items=1,
max_items=len(dict_items),
Fix with Cubic

@topher-lo topher-lo merged commit 1948acd into main Oct 24, 2025
16 checks passed
@topher-lo topher-lo deleted the feat/improve-ranker-prompt-robustness branch October 24, 2025 05:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant