Commit 1bdd9de
feat(lessons): Add ACE-inspired hybrid lesson matching (#817)
* feat(lessons): add ACE-inspired hybrid lesson matching
Implements Phase 5.3 of ACE context optimization task:
- Add HybridLessonMatcher with 5-component scoring system
- Integrate with existing lesson loading via environment config
- Maintain full backward compatibility (fallback to keyword-only)
- Add comprehensive tests covering all components
Scoring components:
- Keyword relevance (25%)
- Semantic similarity (40%)
- Effectiveness feedback (25% - neutral until Phase 1 metadata)
- Recency decay (10% - neutral until Phase 1 metadata)
- Tool match bonus (+20%)
Two-stage retrieval:
1. Fast candidate filtering (keyword + tool) → top-20
2. Precise hybrid scoring on candidates → top-5
Configuration:
- GPTME_LESSONS_USE_HYBRID=true to enable
- Falls back gracefully if embeddings unavailable
- All weights configurable via HybridConfig
Based on Stanford ACE (Agentic Context Engineering) framework
achieving 10.6% performance gains and 70-90% token savings.
Related: ErikBjare/bob#102, tasks/implement-ace-context-optimization.md
Co-authored-by: Bob <bob@superuserlabs.org>
* Update gptme/lessons/auto_include.py
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
* feat(lessons): integrate ACE hybrid lesson matching
- Add optional ACE integration with GptmeHybridMatcher
- Check ACE_AVAILABLE at runtime via try/except import
- Use hybrid matching when GPTME_LESSONS_USE_HYBRID=true and ACE available
- Fall back to keyword matching if ACE unavailable or hybrid disabled
- TODO: Initialize embedder for full hybrid retrieval (Phase 5.3.4)
Part of ACE Phase 5.3.3 implementation.
Co-authored-by: Bob <bob@superuserlabs.org>
* feat(lessons): initialize ACE embedder for hybrid lesson matching
Phase 5.3.4: A/B test setup and embedder initialization
- Initialize LessonEmbedder with lesson directories from LessonIndex
- Use first lesson directory (typically workspace lessons)
- Embeddings stored in .gptme/embeddings/lessons/
- Graceful fallback to keyword matching on embedder init failure
- Ready for A/B testing hybrid vs keyword retrieval
Related: ErikBjare/bob#120 (ACE implementation)
Co-authored-by: Bob <bob@superuserlabs.org>
* feat(lessons): pass session_id to hybrid matcher for retrieval analytics
- Generate session_id from manager.chat_id (unique per gptme session)
- Pass session_id to matcher.match() for tracking
- Enables Phase 5.4 data collection and effectiveness analysis
- Gracefully handles missing chat_id with None fallback
Part of ACE Phase 5.4: Dynamic Lesson Retrieval Analytics
Co-authored-by: Bob <bob@superuserlabs.org>
* fix(lessons): only pass session_id to GptmeHybridMatcher
The base LessonMatcher class doesn't accept session_id parameter.
Only GptmeHybridMatcher (from ACE package) supports it for tracking.
This fixes the test failures where keyword-only fallback was receiving
unexpected session_id parameter.
Fixes ErikBjare/bob#125
Co-authored-by: Bob <bob@superuserlabs.org>
* fix(lessons): move type: ignore comments to import statement lines
Mypy checks the 'from X import' line, not the imported symbols.
Moving type: ignore comments from symbol lines to import lines
resolves typecheck failures in CI.
Co-authored-by: Bob <bob@superuserlabs.org>
* fix(lessons): use lesson.category instead of lesson.metadata.category
Fixes attribute error identified by Greptile review. The Lesson class
has category as a direct attribute, not nested under metadata.
- Line 127: Changed lesson.metadata.category to lesson.category
- Maintains backward compatibility with 'general' fallback
- All tests passing (51/51)
---------
Co-authored-by: Erik Bjäreholt <erik.bjareholt@gmail.com>
Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>1 parent 83cbe9f commit 1bdd9de
File tree
4 files changed
+398
-11
lines changed- gptme
- lessons
- tools
- tests
4 files changed
+398
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
14 | 23 | | |
15 | 24 | | |
16 | 25 | | |
17 | 26 | | |
18 | 27 | | |
| 28 | + | |
| 29 | + | |
19 | 30 | | |
20 | 31 | | |
21 | 32 | | |
22 | 33 | | |
23 | 34 | | |
24 | 35 | | |
25 | 36 | | |
| 37 | + | |
| 38 | + | |
26 | 39 | | |
27 | 40 | | |
28 | 41 | | |
| |||
51 | 64 | | |
52 | 65 | | |
53 | 66 | | |
54 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
55 | 80 | | |
56 | 81 | | |
57 | 82 | | |
58 | 83 | | |
59 | 84 | | |
60 | 85 | | |
61 | | - | |
| 86 | + | |
62 | 87 | | |
63 | 88 | | |
64 | 89 | | |
| |||
94 | 119 | | |
95 | 120 | | |
96 | 121 | | |
97 | | - | |
| 122 | + | |
98 | 123 | | |
99 | | - | |
| 124 | + | |
100 | 125 | | |
101 | | - | |
102 | | - | |
103 | | - | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
104 | 135 | | |
105 | | - | |
| 136 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
0 commit comments