← Back to PRs

#20194: feat(memory): support path-based weights for QMD search (Fixes #20139)

by FradSer open 2026-02-18 16:54 View on GitHub →
size: S
### Description This PR implements the requested feature from #20139 to allow configuring path-based weights for QMD memory search. This enables users to deprioritize archived logs (e.g. `memory/archive/**`) while boosting core memory files (e.g. `MEMORY.md`), implementing a static time decay / relevance weighting system. ### Changes - **Config**: Added `weights` field to `memory.qmd` config. - Type: `Record<string, number>` - Example: `{ "memory/archive/**": 0.5, "MEMORY.md": 2.0 }` - **QMD Manager**: - Implemented client-side re-ranking logic. - Fetches 5x `limit` results from QMD to ensure sufficient candidates for re-ranking. - Multiplies score by weight if path matches pattern. - Re-sorts results by new score. - Implemented basic glob matching (`**` prefix/suffix) to avoid new dependencies. ### Example Configuration ```json "memory": { "qmd": { "weights": { "MEMORY.md": 2.0, "memory/archive/**": 0.5 } } } ``` <!-- greptile_comment --> <h3>Greptile Summary</h3> Adds path-based weight configuration for QMD memory search, allowing users to boost or deprioritize results from specific file paths (e.g., boosting `MEMORY.md` with weight 2.0, deprioritizing `memory/archive/**` with 0.5). The implementation over-fetches 5x results from QMD, applies weight multipliers based on simple glob matching, and re-sorts before returning. - Config plumbing in `types.memory.ts` and `backend-config.ts` is clean — adds `weights?: Record<string, number>` and passes it through without transformation. - The `fetchLimit` check (`this.qmd.weights`) is inconsistent with the later `hasWeights` check (`Object.keys(weights).length > 0`), causing unnecessary 5x over-fetching when `weights: {}` is configured. - The `matchesPath` glob implementation handles `dir/**`, `*.ext`, and exact matches, but silently fails on common patterns like `**/*.md` — worth documenting the supported syntax or handling this case. <h3>Confidence Score: 3/5</h3> - Functional but has a logic inconsistency in over-fetching and limited glob matching that could cause unexpected behavior. - The core re-ranking logic works for the documented patterns, but the mismatch between fetchLimit truthiness check and hasWeights check is a real logic bug (wasted work with empty weights config). The matchesPath glob limitations aren't immediately breaking but could silently surprise users with common patterns like **/*.md. - `src/memory/qmd-manager.ts` — the `fetchLimit` inconsistency and `matchesPath` glob handling need attention. <sub>Last reviewed commit: 503486d</sub> <!-- greptile_other_comments_section --> <sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub> <!-- /greptile_comment -->

Most Similar PRs