#20194: feat(memory): support path-based weights for QMD search (Fixes #20139)
size: S
Cluster:
QMD Memory Management Fixes
### 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
#9624: fix(memory): resolve QMD search returning empty results [AI-assisted]
by kowshik24 · 2026-02-05
78.7%
#11364: fix(memory/qmd): prevent cascading failure when query fails or retu...
by blazerui · 2026-02-07
77.7%
#20085: Fix QMD memory_search empty results when docid key changes
by rylena · 2026-02-18
75.8%
#9149: Fix: Allow QMD backend to work without OpenAI auth
by vishaltandale00 · 2026-02-04
75.6%
#20214: Feat:add weights configuration for QMD and implement weight-based s...
by jayy-77 · 2026-02-18
75.4%
#18919: feat: importance-weighted temporal decay for memory search
by ruypang · 2026-02-17
75.3%
#15307: fix(memory): handle mixed/no-results QMD query output
by MohammadErfan-Jabbari · 2026-02-13
75.3%
#21471: fix: check QMD backend before memory search config
by lbo728 · 2026-02-20
74.3%
#11179: fix(memory): replace confusing "No API key" errors in memory tools ...
by liuxiaopai-ai · 2026-02-07
74.2%
#16968: fix(qmd): per-collection search to prevent large collections drowni...
by ProgramCaiCai · 2026-02-15
73.5%