Skip to content

📕(summarize) Let the model choose which doc to summarize#282

Open
camilleAND wants to merge 1 commit intomainfrom
camand/feat_choose_summarize
Open

📕(summarize) Let the model choose which doc to summarize#282
camilleAND wants to merge 1 commit intomainfrom
camand/feat_choose_summarize

Conversation

@camilleAND
Copy link
Copy Markdown
Contributor

@camilleAND camilleAND commented Feb 11, 2026

Add doc_index argument to document_summarize tool
This PR updates the document_summarize tool to support summarizing specific documents within a conversation.

Changes

Added an optional doc_index argument (integer) to the document_summarize function.
Updated the tool's docstring and examples to explain how to use doc_index (e.g., 0 for the first document, -1 for the last).
Implemented logic to filter the list of text attachments based on the provided index.
Added error handling for out-of-range indices, raising a ModelRetry exception to allow the model to correct itself.
Preserved existing behavior: if doc_index is None (default), all text documents are summarized together.

This allows the LLM to handle user requests like "summarize the last document" or "summarize the first document" more effectively by targeting a specific file instead of processing all available attachments.

Summary by CodeRabbit

  • New Features
    • Document summarization now supports selecting a specific document from multiple attachments, while maintaining full-document summarization as the default option.

@camilleAND camilleAND requested a review from qbey February 11, 2026 09:13
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 11, 2026

Walkthrough

Added an optional doc_index parameter to the document_summarize function that enables selection of a specific document to summarize. When provided, the function filters attachments to the specified index with bounds checking; when absent, all documents are summarized as before. The function signature, error handling, and documentation were updated accordingly.

Changes

Cohort / File(s) Summary
Document Summarization Enhancement
src/backend/chat/tools/document_summarize.py
Added optional doc_index parameter to allow selecting a specific document for summarization. Includes bounds checking with retryable error handling, conditional attachment filtering logic, and updated docstring examples demonstrating both indexed and default (all documents) behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: adding functionality to let the model choose which document to summarize via the new doc_index parameter.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Docstrings were successfully generated.
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch camand/feat_choose_summarize

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/backend/chat/tools/document_summarize.py (1)

101-108: Solid index filtering with appropriate error recovery.

The use of Python's native list indexing (supporting negative indices) combined with ModelRetry on IndexError is clean and lets the model self-correct. One minor nit: for the LLM's benefit, consider also including the valid index range in the error message (e.g., 0 to {len(text_attachment) - 1}) so the model can pick a correct index on retry without needing to infer it.

💡 Optional: slightly more helpful retry message
             except IndexError as exc:
                 raise ModelRetry(
                     f"Document index {doc_index} is out of range. "
-                    f"There are {len(text_attachment)} documents available."
+                    f"There are {len(text_attachment)} documents available "
+                    f"(valid indices: 0 to {len(text_attachment) - 1})."
                 ) from exc

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

@camilleAND camilleAND requested a review from providenz February 11, 2026 13:32
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Feb 11, 2026

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #283

coderabbitai bot added a commit that referenced this pull request Feb 11, 2026
Docstrings generation was requested by @camilleAND.

* #282 (comment)

The following files were modified:

* `src/backend/chat/tools/document_summarize.py`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant