lex-apollo 0.4.49 → 0.4.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0fe398ea1e539ac9bc8986b617de7d5b350b16034c6b0aa03e4d21aa306f4831
|
|
4
|
+
data.tar.gz: cf6f6dc19f9eddf7e791b3a964ea14e3f5ee3eab2ab5901af63005bda791bf30
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f5c7952ee9f32f6b7bd0c459a5d5a2362934d9ef92577f5d24a67a00083aa69919fcd323e00694f2c893566a9561d5f083ee84c2247f7a5d1c6c82701f7673c0
|
|
7
|
+
data.tar.gz: 2af58f15246c91f8a4aae48d97eb16e8ab76fca7fd9f2228efa015ee4aedb34cff2ec5f9e770ffd0a7acb2021e3f8452c5f30c5d9e0e04e8f8816f5818e32a54
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.4.50] - 2026-11-19
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
- Aggregate expertise counts and average confidence in the database, returning one row per agent and domain instead of loading every knowledge entry into Ruby. Preserve first-tag and general-domain fallbacks on PostgreSQL and SQLite.
|
|
7
|
+
|
|
3
8
|
## [0.4.49] - 2026-11-18
|
|
4
9
|
|
|
5
10
|
### Fixed
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
require 'legion/logging/helper'
|
|
4
4
|
require 'legion/settings/helper'
|
|
5
5
|
require 'legion/extensions/apollo/helpers/data_models'
|
|
6
|
-
require 'legion/extensions/apollo/helpers/storage'
|
|
7
6
|
|
|
8
7
|
module Legion
|
|
9
8
|
module Extensions
|
|
@@ -13,7 +12,6 @@ module Legion
|
|
|
13
12
|
include Legion::Logging::Helper
|
|
14
13
|
include Legion::Settings::Helper
|
|
15
14
|
extend Legion::Extensions::Apollo::Helpers::DataModels
|
|
16
|
-
extend Legion::Extensions::Apollo::Helpers::Storage
|
|
17
15
|
extend self
|
|
18
16
|
|
|
19
17
|
def get_expertise(domain:, min_proficiency: settings[:expertise][:initial_proficiency], **)
|
|
@@ -60,12 +58,12 @@ module Legion
|
|
|
60
58
|
return { success: false, error: 'apollo_data_not_available' }
|
|
61
59
|
end
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
log.debug("Apollo Expertise.aggregate
|
|
61
|
+
groups = expertise_groups(model: model)
|
|
62
|
+
log.debug("Apollo Expertise.aggregate groups=#{groups.size}")
|
|
65
63
|
|
|
66
64
|
agent_set = Set.new
|
|
67
65
|
domain_set = Set.new
|
|
68
|
-
|
|
66
|
+
groups.each do |group|
|
|
69
67
|
expertise_upsert_group(model: expertise_model, group: group)
|
|
70
68
|
agent_set << group[:agent_id]
|
|
71
69
|
domain_set << group[:domain]
|
|
@@ -80,20 +78,23 @@ module Legion
|
|
|
80
78
|
|
|
81
79
|
private
|
|
82
80
|
|
|
83
|
-
def expertise_groups(
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
81
|
+
def expertise_groups(model:, **)
|
|
82
|
+
domain = case model.db.database_type
|
|
83
|
+
when :postgres then Sequel.lit("COALESCE(knowledge_domain, tags[1], 'general')")
|
|
84
|
+
when :sqlite then Sequel.lit("COALESCE(knowledge_domain, json_extract(tags, '$[0]'), 'general')")
|
|
85
|
+
else raise ArgumentError, "unsupported Apollo adapter: #{model.db.database_type}"
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
model.dataset.exclude(source_agent: nil)
|
|
89
|
+
.select(Sequel[:source_agent].as(:agent_id), domain.as(:domain),
|
|
90
|
+
Sequel.function(:count, Sequel.lit('*')).as(:entry_count),
|
|
91
|
+
Sequel.function(:avg, Sequel.function(:coalesce, :confidence, 0.0)).as(:average_confidence))
|
|
92
|
+
.group(:source_agent, domain).naked.all
|
|
92
93
|
end
|
|
93
94
|
|
|
94
95
|
def expertise_upsert_group(model:, group:, **)
|
|
95
|
-
count = group[:
|
|
96
|
-
proficiency = expertise_proficiency(
|
|
96
|
+
count = group[:entry_count]
|
|
97
|
+
proficiency = expertise_proficiency(average_confidence: group[:average_confidence], entry_count: count)
|
|
97
98
|
existing = model.first(agent_id: group[:agent_id], domain: group[:domain])
|
|
98
99
|
|
|
99
100
|
if existing
|
|
@@ -104,10 +105,9 @@ module Legion
|
|
|
104
105
|
end
|
|
105
106
|
end
|
|
106
107
|
|
|
107
|
-
def expertise_proficiency(
|
|
108
|
-
avg = confidences.sum / confidences.size
|
|
108
|
+
def expertise_proficiency(average_confidence:, entry_count:, **)
|
|
109
109
|
cap = settings[:expertise][:proficiency_cap]
|
|
110
|
-
[
|
|
110
|
+
[average_confidence.to_f * Math.log2(entry_count + 1), cap].min
|
|
111
111
|
end
|
|
112
112
|
end
|
|
113
113
|
end
|
|
@@ -100,6 +100,26 @@ RSpec.describe Legion::Extensions::Apollo::Runners::Expertise do
|
|
|
100
100
|
expect(expertise_model.first.values).to include(agent_id: 'agent-1', domain: 'vault', entry_count: 1)
|
|
101
101
|
end
|
|
102
102
|
|
|
103
|
+
it 'aggregates confidence and counts while preserving missing-domain and nil-confidence behavior' do
|
|
104
|
+
sql = []
|
|
105
|
+
logger = Object.new
|
|
106
|
+
logger.define_singleton_method(:info) { |statement| sql << statement }
|
|
107
|
+
database.loggers << logger
|
|
108
|
+
|
|
109
|
+
entry_model.create(source_agent: 'agent-1', knowledge_domain: 'ruby', confidence: 0.8)
|
|
110
|
+
entry_model.create(source_agent: 'agent-1', knowledge_domain: 'ruby', confidence: 0.6)
|
|
111
|
+
entry_model.create(source_agent: 'agent-1', knowledge_domain: 'ruby', confidence: nil)
|
|
112
|
+
entry_model.create(source_agent: 'agent-1', knowledge_domain: nil, tags: '[]', confidence: 0.5)
|
|
113
|
+
entry_model.create(source_agent: nil, knowledge_domain: 'ruby', confidence: 1.0)
|
|
114
|
+
|
|
115
|
+
expect(runner.aggregate).to include(success: true, agents: 1, domains: 2)
|
|
116
|
+
ruby = expertise_model.first(agent_id: 'agent-1', domain: 'ruby')
|
|
117
|
+
expect(ruby.entry_count).to eq(3)
|
|
118
|
+
expect(ruby.proficiency).to be_within(0.000001).of(((0.8 + 0.6) / 3) * Math.log2(4))
|
|
119
|
+
expect(expertise_model.first(agent_id: 'agent-1', domain: 'general').entry_count).to eq(1)
|
|
120
|
+
expect(sql).to include(a_string_matching(/SELECT .*avg.*FROM .*apollo_entries.*GROUP BY/i))
|
|
121
|
+
end
|
|
122
|
+
|
|
103
123
|
it 'returns zero counts for an empty canonical entry table' do
|
|
104
124
|
expect(runner.aggregate).to include(success: true, agents: 0, domains: 0)
|
|
105
125
|
end
|