Add code signal detection and dynamic symbol boosting#79
Conversation
Introduces code signal detection in repo_search to analyze queries for code-like patterns and extract symbols, using both regex and embedding-based heuristics. Dynamically boosts symbol and implementation matching based on detected code intent, and passes extracted symbols to hybrid_search for improved targeting. Updates Dockerfile to download reranker and tokenizer models at build time, and modifies hybrid_search to incorporate symbols from CODE_SIGNAL_SYMBOLS environment variable. Default repo search to snippets on.
🤖 Augment PR SummarySummary: This PR improves repo search relevance by detecting “code-like” intent in queries and dynamically boosting symbol/implementation (and filename) matches. Changes:
Technical Notes: Code-intent centroids are lazily initialized and cached; symbol hints are capped before being forwarded to hybrid search to limit query expansion. 🤖 Was this summary useful? React with 👍 or 👎 |
| signal_score = signal_score * (1 - blend_weight) + embedding_score * blend_weight | ||
| except Exception: | ||
| pass | ||
| elif use_embedding and signal_score < 0.1: |
There was a problem hiding this comment.
In _detect_code_signals, use_embedding is referenced but not defined, which will raise NameError and silently disable the embedding-only fallback (the caller catches all exceptions). Consider wiring this branch to an explicit flag/env var (with a default) or removing it to avoid detection unexpectedly no-op’ing.
🤖 Was this useful? React with 👍 or 👎
Improves code symbol detection and matching by extracting full identifiers (including private/dunder and various case styles) for more accurate symbol-based boosts in hybrid_search.py. Increases default symbol boost weights, prevents double-counting, and tunes boost multipliers in mcp_indexer_server.py to be more aggressive for code-like queries, aligning with symbol-aware search. Also updates regex patterns and logic for private and snake_case identifiers.
Enhances the hybrid search algorithm by increasing the score when multiple query tokens match the filename, both in the lexical scoring and in the result ranking stages. This change improves the ranking of files whose names closely match the user's query, making results more relevant for queries that target specific filenames.
Added logic to increase the score of all chunks from files whose filenames strongly correlate with query tokens. This improves hybrid search results by surfacing relevant files even if individual chunks do not contain all query terms.
Adds filename-query correlation boosting to hybrid_search.py to enhance relevance when query tokens match filename tokens. In rerank_recursive.py, increases blend_with_initial to 0.45 in RecursiveReranker and blends ONNX reranker scores with initial hybrid search scores for better preservation of hybrid search signals such as filename correlation and symbol matching.
This commit simplifies hybrid search scoring by removing enhanced symbol and filename correlation boosts, as well as full identifier extraction and matching logic. Symbol and filename boosts are now lighter and more configurable, and ONNX reranker blending is simplified to use only ONNX scores. These changes aim to reduce overfitting to code symbol queries and improve generalization.
Refines the condition for using code signal embedding in mcp_indexer_server.py to check the CODE_SIGNAL_EMBEDDING environment variable for common truthy values. Also adds a missing import of the re module in rerank_recursive.py.
The repo_search function now includes the optional fname_boost value in the components dictionary and the why_parts list if present. This provides more detailed scoring information in search results.
Extracted filename boost logic into helper functions for improved robustness and maintainability. Added unit tests to cover various path extraction and tokenization scenarios, ensuring correct boost calculation and fallback behavior.
Adds documentation for the HYBRID_FNAME_BOOST setting, explaining how filename-based boosting works in search, its default value, and usage examples.
Introduces a fallback mechanism to apply a filename-query correlation boost to search results when the learning reranker is disabled, fails, or is not used. This ensures relevant results receive a score boost based on filename token matches, improving result ranking consistency.
Updated context answer-related tests to mock the embedding model, preventing the need to load the real model during test execution. Also fixed a test data structure in test_server_helpers.py to use a dictionary for 'components' instead of a list.
Renames the filename boost environment variable from HYBRID_FNAME_BOOST and RERANK_FNAME_BOOST to FNAME_BOOST across the codebase and documentation. Updates the default boost value from 0.25/0.12 to 0.15 for consistency. Adjusts related documentation and tests to reflect the new variable name and default value.
|
augment review |
| _match_count = len(_q_toks & _fname_toks) | ||
| if _match_count >= 2: | ||
| _boost = float(_fname_boost_factor) * _match_count | ||
| r["score"] = float(r.get("score", 0)) + _boost |
There was a problem hiding this comment.
After increasing r["score"] with fname_boost, the list order may no longer reflect the updated scores. Consider re-sorting results after this loop so the boost actually affects ranking (and score/ordering don’t diverge).
🤖 Was this useful? React with 👍 or 👎
Enhances the filename boost logic to support robust tokenization and normalization, including handling of various naming conventions (camelCase, PascalCase, snake_case, etc.), acronym splitting, abbreviation normalization, and position-aware scoring. Updates the scoring algorithm to provide more accurate and context-aware boosts, and adds comprehensive tests to cover new tokenization and matching behaviors.
Expanded the documentation for filename/path boosting to detail tokenization, normalization, and scoring tiers. Increased penalties for test and documentation files and boosted implementation file preference in hybrid_search.py to ensure code files rank above tests and docs.
Introduces logic to detect when a user's query is seeking implementation code and dynamically increases the boost for implementation files. Also increases penalties for test and documentation files in such cases to improve search relevance.
Introduces query intent detection for the CLI path in hybrid_search.py, aligning its behavior with run_hybrid_search. Adjusts the test penalty if implementation intent is detected.
Replaces TEST_FILE_PENALTY with test_penalty_cli when applying penalties to test files in the recommendation scoring. Ensures the penalty value can be set via the CLI for greater flexibility.
Ensures that the fname_boost adjustment affects the final ranking by re-sorting the results list by updated score after applying the boost.
Adjusted RRF_K, DENSE_WEIGHT, and LEXICAL_WEIGHT in hybrid_search.py to improve score distribution and balance for repositories. Enhanced lexical_score function to boost filename matches more strongly. Updated .gitignore to exclude additional files and directories.
Add code signal detection and dynamic symbol boosting
Introduces code signal detection in repo_search to analyze queries for code-like patterns and extract symbols, using both regex and embedding-based heuristics. Dynamically boosts symbol and implementation matching based on detected code intent, and passes extracted symbols to hybrid_search for improved targeting. Updates Dockerfile to download reranker and tokenizer models at build time, and modifies hybrid_search to incorporate symbols from CODE_SIGNAL_SYMBOLS environment variable.
Default repo search to snippets on.