Skip to content

Update helpers.py to search by title#115

Open
Tikkel77 wants to merge 1 commit intoteng-lin:mainfrom
Tikkel77:patch-2
Open

Update helpers.py to search by title#115
Tikkel77 wants to merge 1 commit intoteng-lin:mainfrom
Tikkel77:patch-2

Conversation

@Tikkel77
Copy link

Add to the resolve_partial_id function to look at the title as well (instead of just ID).

Updated the code based on comment (in the event title is blank) for security reason.

Add to the resolve_partial_id function to look at the title as well (instead of just ID). 

Updated the code based on comment (in the event title is blank) for security reason.
@gemini-code-assist
Copy link

Summary of Changes

Hello @Tikkel77, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the _resolve_partial_id utility function by introducing the ability to resolve partial IDs based on an item's title, in addition to its ID. This change improves user experience by allowing more flexible input for identifying entities. It also adjusts the threshold for when partial ID resolution is skipped, and adds robustness for handling potentially missing titles.

Highlights

  • Enhanced ID Resolution: The _resolve_partial_id function now attempts to match entities by their title if no match is found using a partial ID.
  • Increased ID Length Threshold: The minimum length for a partial_id to skip resolution has been increased from 20 to 50 characters.
  • Robust Title Matching: Added a safeguard to handle cases where an item's title might be blank or null during the title-based search.
Changelog
  • src/notebooklm/cli/helpers.py
    • Implemented logic to search for matches by item title if no matches are found by item ID.
    • Increased the partial_id length check from 20 to 50 characters to determine if resolution should be skipped.
    • Added a null-coalescing operator (or "") to item.title to prevent errors if the title is blank during the search.
Activity
  • No human activity (comments, reviews, etc.) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enhances the partial ID resolution logic to also search by title, which is a great usability improvement. My review focuses on two areas: first, a minor issue where a code comment and a related unit test have become outdated due to a change in an ID length threshold. Second, I've proposed a change to the search logic to combine results from both ID and title searches. This will ensure more comprehensive and intuitive results, especially in cases where a search term could ambiguously match either an ID prefix or a title.

Comment on lines 277 to +278
# Skip resolution for IDs that look complete (20+ chars)
if len(partial_id) >= 20:
if len(partial_id) >= 50:

Choose a reason for hiding this comment

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

medium

The comment on line 277 is now out of sync with the code on line 278. Please update the comment to reflect the new threshold of 50 characters.

Additionally, this change will likely cause the unit test TestResolveNotebookId.test_long_id_skips_resolution in tests/unit/cli/test_resolve.py to fail, as it asserts behavior based on the old 20-character threshold. Please update the test accordingly.

Suggested change
# Skip resolution for IDs that look complete (20+ chars)
if len(partial_id) >= 20:
if len(partial_id) >= 50:
# Skip resolution for IDs that look complete (50+ chars)
if len(partial_id) >= 50:

Comment on lines 282 to +286
matches = [item for item in items if item.id.lower().startswith(partial_id.lower())]

# Do a match based on title if there is no match on UUID:
if len(matches) == 0:
matches = [item for item in items if (item.title or "").lower().startswith(partial_id.lower())]

Choose a reason for hiding this comment

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

medium

The current logic prioritizes ID matches and only searches by title if no ID matches are found. This can lead to confusing behavior if a user's search term matches an ID prefix but they intended to find an item by its title. For example, searching for 'action' might match an item with ID 'action-item-id' and ignore another item with the title 'action plan'.

To provide more intuitive results, it would be better to search by both ID and title, and then present all unique matches to the user. This way, if there are multiple possibilities, the user is notified of the ambiguity.

Suggested change
matches = [item for item in items if item.id.lower().startswith(partial_id.lower())]
# Do a match based on title if there is no match on UUID:
if len(matches) == 0:
matches = [item for item in items if (item.title or "").lower().startswith(partial_id.lower())]
matches = [item for item in items if item.id.lower().startswith(partial_id.lower()) or (item.title or "").lower().startswith(partial_id.lower())]

Jah-yee added a commit to Jah-yee/notebooklm-py that referenced this pull request Mar 6, 2026
- Add title prefix matching as fallback when ID prefix match yields no results
- Improve error message to indicate both ID and title are searched
- Fix ambiguous input message wording

This resolves teng-lin#115 and teng-lin#113
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