-
Notifications
You must be signed in to change notification settings - Fork 0
Fix Notion search missing relevant matches with multi-strategy query expansion #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Co-authored-by: jck411 <81551487+jck411@users.noreply.github.com>
Co-authored-by: jck411 <81551487+jck411@users.noreply.github.com>
Co-authored-by: jck411 <81551487+jck411@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR enhances the Notion search functionality to handle queries that don't exactly match page titles by implementing a multi-strategy query expansion approach. When exact matches yield insufficient results (<3), the system automatically tries variations of the query (individual significant words, adjacent pairs) to find relevant pages, addressing issues where searches like "names to remember" or "old lady at the park" previously returned zero results.
Key changes:
- Added query variation generation that decomposes queries into significant terms and combinations
- Implemented enhanced search that tries multiple query variations when initial results are insufficient
- Added comprehensive test coverage for the new functionality
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
src/backend/mcp_servers/notion_server.py |
Implements _generate_search_variations() and _perform_enhanced_search() functions, integrates enhanced search into notion_search() tool |
tests/test_notion_server.py |
Adds 7 new test cases covering variation generation, enhanced search behavior, deduplication, and error handling |
There was a problem hiding this 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".
- Fix enhanced search flow and early return; try multiple query variations and deduplicate results - Improve search variation generation and limit extra queries - Increase DEFAULT_SEARCH_BLOCK_LIMIT from 20 to 100 - Surface "PAGE ID" consistently in search headings and page summaries - Default notion_retrieve_page to include_children=True and clarify PAGE ID vs block ID in docs - Add/expand MCP tool descriptions for notion_search, notion_retrieve_page, notion_create_page, notion_append_block_children, and notion_update_block - Misc: whitespace/formatting cleanup and minor docstring refinements
Notion's
/v1/searchAPI uses exact matching, causing searches like "names to remember" or "old lady at the park" to return zero results when page titles don't match precisely.Changes
Query variation generation (
_generate_search_variations)"names to remember"→["names to remember", "names", "remember", "names remember"]Multi-strategy search (
_perform_enhanced_search)Updated search tool (
notion_search)Result
Test coverage: 7 new tests covering variation generation, enhanced search behavior, error handling, deduplication
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
astral.shcurl -LsSf REDACTED(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
still not working good, when I search for things to remember it should pull up possible matches but it misses
/home/jack/Backend_FastAPI/logs/conversations/2025-10-28/session_2025-10-28_05-01-07_EDT_88b179e5f1224974b791d209b03f2832.log
[Chronological Review: The conversation began with the user expressing a desire to set up tools for a Notion MCP server to help the LLM remember names and other information. The user then delegated tasks to a cloud agent. The conversation shifted to querying information about Russell's kids, where the assistant successfully retrieved names but failed to find specific details initially. The user questioned why the LLM did not retrieve certain names and expressed frustration with the search functionality, particularly regarding the "old lady at the park." The user continued to report issues with the search tool not pulling up relevant matches.][Intent Mapping: The user explicitly requested to set up tools for remembering names and information. They sought to understand why certain queries did not yield expected results and expressed a desire for the LLM to effectively search and retrieve relevant information from their notes.]
[Technical Inventory: Tools mentioned include:
The user is working with a Notion MCP server to manage reminders and names.]
[Code Archaeology: The user referenced the file /home/jack/Backend_FastAPI/src/backend/mcp_servers/notion_server.py, indicating recent edits that may affect functionality. Specific functions related to searching and retrieving data from Notion were discussed.]
[Progress Assessment: The user successfully retrieved names related to Russell's kids but encountered issues with the search tool not returning expected results for queries about the "old lady at the park" and other names. The user expressed ongoing frustration with the tool's performance.]
[Context Validation: The conversation captures the user's goals of improving the search functionality of their Notion integration and ensuring that relevant information is easily accessible.]
[Recent Commands Analysis:
1. Conversation Overview: - Primary Objectives: The user requested to set up tools for remembering names and information, stating, "my plan is to set up the tool names and descriptions so that the llm uses them for context about reminders." - Session Context: The conversation involved querying names related to Russell's kids, discussing the effectiveness of the search tool, and expressing frustration over missed matches. - User Intent Evolution: The user shifted from setting up tools to troubleshooting the search functionality, seeking clarity on why certain queries did not yield expected results.- Technical Foundation:
- Notion MCP Server: The user is integrating a Notion server to manage reminders and names.
- Tools:
- notion_search: Used for querying names and information.
- notion_retrieve_page: Used for retrieving detailed information from Notion pages.
- Codebase Status:
- /home/jack/Backend_FastAPI/src/backend/mcp_servers/notion_server.py: This file has been edited recently, potentially affecting the search functionality.
- Key Code Segments: Functions related to searching and retrieving data from Notion were discussed.
- Problem Resolution:
- Issues Encountered: The search tool did not return expected results for queries about the "old lady at the park" and other names.
- Solutions Implemented: The user attempted to troubleshoot the search functionality by querying specific names.
- Debugging Context: The user expressed ongoing frustration with the tool's performance and its inability to pull up relevant matches.
- Progress Tracking:
- Completed Tasks: The user successfully retrieved names related to Russell's kids.
- Partially Complete Work: The search functionality remains problematic, with the user still seeking effective retrieval of information.
- Validated Outcomes: Some names were confirmed as retrievable, but the overall search experience is lacking.
- Active Work State:
- Current Focus: The user was troubleshooting the search functionality of their Notion integra...
Created from VS Code via the GitHub Pull Request extension.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.