-
Notifications
You must be signed in to change notification settings - Fork 0
feat: composite relevance scoring + radical observation cleanup #39
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
Changes from all commits
acdb385
e1a91be
92a786b
efa5084
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,6 +119,55 @@ func (m *SearchMetrics) GetStats() map[string]any { | |
| } | ||
| } | ||
|
|
||
| // ApplyCompositeScoring re-ranks observations using multi-signal scoring. | ||
| // Formula: score = similarity × recencyDecay × typeWeight × max(importance, 0.3) | ||
| // This ensures that recent, high-importance decisions rank above old generic discoveries. | ||
| func ApplyCompositeScoring(observations []*models.Observation, similarityScores map[int64]float64) { | ||
| now := time.Now() | ||
|
|
||
| // Type weights: decisions and patterns have higher behavioral impact | ||
| typeWeights := map[models.ObservationType]float64{ | ||
| "decision": 1.4, | ||
| "bugfix": 1.3, | ||
| "feature": 1.2, | ||
| "pattern": 1.2, | ||
| "discovery": 0.8, | ||
| "change": 0.7, | ||
| "refactor": 0.9, | ||
| } | ||
|
Comment on lines
+129
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Поиск констант ObservationType в models
rg -n "ObsType\w*\s*=|ObservationType\s*=" --type=goRepository: thebtf/engram Length of output: 1054 🏁 Script executed: cd internal/search && cat -n manager.go | sed -n '125,145p'Repository: thebtf/engram Length of output: 769 🏁 Script executed: cat -n pkg/models/observation.go | head -30Repository: thebtf/engram Length of output: 1012 Используйте константы типов вместо строковых литералов для типобезопасности. Карта Требуется либо:
После этого заменить все строковые литералы на константы:
🤖 Prompt for AI Agents
Comment on lines
+129
to
+137
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| for _, obs := range observations { | ||
| sim := similarityScores[obs.ID] | ||
| if sim == 0 { | ||
| sim = 0.5 // default if no similarity score | ||
| } | ||
|
|
||
| // Recency decay: half-life of 7 days | ||
| ageDays := now.Sub(time.Unix(obs.CreatedAtEpoch/1000, 0)).Hours() / 24.0 | ||
| recency := math.Pow(0.5, ageDays/7.0) | ||
| // Floor at 0.05 so old but very important observations don't disappear | ||
| if recency < 0.05 { | ||
| recency = 0.05 | ||
| } | ||
|
|
||
| // Type weight | ||
| tw := 1.0 | ||
| if w, ok := typeWeights[obs.Type]; ok { | ||
| tw = w | ||
| } | ||
|
|
||
| // Importance (floor at 0.3 so unscored observations aren't penalized to zero) | ||
| imp := obs.ImportanceScore | ||
| if imp < 0.3 { | ||
| imp = 0.3 | ||
| } | ||
|
|
||
| // Composite score replaces raw similarity | ||
| compositeScore := sim * recency * tw * imp | ||
| similarityScores[obs.ID] = compositeScore | ||
| } | ||
| } | ||
|
|
||
| // Manager provides unified search across PostgreSQL and pgvector. | ||
| type Manager struct { | ||
| ctx context.Context | ||
|
|
||
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.
This loop executes a separate
DELETEquery for each of the ~45 patterns. This results in many database round trips and can be inefficient, especially on a largeobservationstable. Consider combining these into a singleDELETEstatement usingORconditions to improve performance. For example:DELETE FROM observations WHERE title LIKE ? OR title LIKE ? .... This would make the operation atomic and significantly faster.