Skip to content

feat: support searching by title in partial ID resolver#158

Open
Jah-yee wants to merge 1 commit intoteng-lin:mainfrom
Jah-yee:feature/search-by-title
Open

feat: support searching by title in partial ID resolver#158
Jah-yee wants to merge 1 commit intoteng-lin:mainfrom
Jah-yee:feature/search-by-title

Conversation

@Jah-yee
Copy link

@Jah-yee Jah-yee commented Mar 6, 2026

Summary

This PR adds support for searching by title in the partial ID resolver. When a user provides a partial ID that doesn't match any notebook/source/artifact ID, the resolver now falls back to searching by title prefix match.

Changes

  1. Add title prefix matching - If no ID prefix matches found, try matching by title (case-insensitive prefix match)
  2. Improve error messages - Updated messages to indicate both ID and title are searched
  3. Fix ambiguous input wording - Changed "Ambiguous ID" to "Ambiguous input" to reflect that both IDs and titles can be matched

Testing

  • Syntax check passed
  • Follows existing code patterns

Related Issues


Contributed as part of Spark Lab AI Agent exploration

- 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
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 significantly enhances the partial ID resolution logic within the CLI by introducing the ability to search for items by their title as a fallback when a direct ID match is not found. This improves user experience by making the CLI more flexible and forgiving, allowing users to locate notebooks, sources, or artifacts using more intuitive title-based queries in addition to partial IDs.

Highlights

  • Title Prefix Matching: Implemented a fallback mechanism in the partial ID resolver to search by title (case-insensitive prefix match) if no ID prefix matches are found.
  • Error Message Improvement: Updated error messages to clearly indicate that both IDs and titles are now searched.
  • Ambiguous Input Wording: Changed the error message from "Ambiguous ID" to "Ambiguous input" to accurately reflect the expanded search capabilities.
Changelog
  • src/notebooklm/cli/helpers.py
    • Added logic to _resolve_partial_id to perform a title prefix search if no ID matches are found.
    • Modified the docstring for _resolve_partial_id to reflect the new title search capability.
    • Updated error messages for clarity when no matches are found or when multiple matches exist, changing "Ambiguous ID" to "Ambiguous input".
Activity
  • No human activity has been recorded on 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 adds a useful feature to allow searching for entities by title prefix as a fallback to matching by ID. The implementation is straightforward. I've identified a minor performance improvement opportunity by avoiding repeated string operations within a loop. More importantly, the new functionality is not covered by unit tests, which is crucial for ensuring its correctness and preventing future regressions. Please add tests to cover the new title-matching logic.

Note: Security Review is unavailable for this PR.


Allows users to type partial IDs like 'abc' instead of full UUIDs.
Matches are case-insensitive prefix matches.
Also supports searching by title (prefix match, case-insensitive).

Choose a reason for hiding this comment

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

high

This is a great feature enhancement. However, the new functionality of searching by title is not covered by unit tests. Please add tests to tests/unit/cli/test_resolve.py to cover various scenarios, such as:

  • Matching by a unique title prefix.
  • Prioritizing ID matches over title matches when both could match.
  • Handling ambiguous title matches.
  • Ensuring case-insensitivity for title search.
  • Verifying behavior with items that have no title.
References
  1. When a function's signature is updated to return new values, update tests to assert the state of these new returns, including for error handling and early-return paths.

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

# If no ID matches, try title prefix match
if len(matches) == 0:
matches = [item for item in items if item.title and item.title.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

This implementation calls partial_id.lower() inside the list comprehensions, which is inefficient as it's re-evaluated for every item. It's better to compute the lowercase version of partial_id once before the loops. Also, using if not matches: is more idiomatic than if len(matches) == 0:.

Suggested change
matches = [item for item in items if item.id.lower().startswith(partial_id.lower())]
# If no ID matches, try title prefix match
if len(matches) == 0:
matches = [item for item in items if item.title and item.title.lower().startswith(partial_id.lower())]
lower_partial_id = partial_id.lower()
# First try ID prefix match
matches = [item for item in items if item.id.lower().startswith(lower_partial_id)]
# If no ID matches, try title prefix match
if not matches:
matches = [item for item in items if item.title and item.title.lower().startswith(lower_partial_id)]

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