legion-apollo 0.3.6 → 0.3.7
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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/legion/apollo/local.rb +80 -0
- data/lib/legion/apollo/version.rb +1 -1
- data/lib/legion/apollo.rb +1 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd344e49282eb4e397ce81a5920980466dea27d9b23cf4156f549280f46af768
|
|
4
|
+
data.tar.gz: 96b8d482992dbbe9d442bead192f128cf96dc776879cebd68e8b934b281c157e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35bc5fac20a5d153a54805d23a33218fed71177fe4b4f63724b527cc8fe3ca761912b617c0dc80380609d7eaa32a3197070525c9b08330f200343198ea01988d
|
|
7
|
+
data.tar.gz: 6b84f74fd517e4500d389fe51d9bd7f149abd96ccd4eaac2d110899f82ed6856be775f5a55c104a0f59cb92a974ba9da6237bc1bce16c564bd1725e738c3de43
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
- `Apollo::Local.promote_to_global(tags:, min_confidence:)` — promotes local entries to Apollo Global
|
|
7
|
+
- `Apollo::Local.query_by_tags(tags:, limit:)` — tag-only query (bypasses FTS5)
|
|
8
|
+
- `Apollo::Local.hydrate_from_global` — boots local store from global partner data with 0.9 confidence discount
|
|
9
|
+
- Boot hook: auto-hydrates partner data from global on first start
|
|
10
|
+
|
|
3
11
|
## [0.3.6] - 2026-03-31
|
|
4
12
|
|
|
5
13
|
### Added
|
data/lib/legion/apollo/local.rb
CHANGED
|
@@ -131,6 +131,86 @@ module Legion
|
|
|
131
131
|
@seeded == true
|
|
132
132
|
end
|
|
133
133
|
|
|
134
|
+
def query_by_tags(tags:, limit: 50) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize
|
|
135
|
+
return { success: false, error: :not_started } unless started?
|
|
136
|
+
|
|
137
|
+
candidates = db[:local_knowledge]
|
|
138
|
+
.where { expires_at > Time.now.utc.iso8601 }
|
|
139
|
+
.limit(limit)
|
|
140
|
+
.all
|
|
141
|
+
|
|
142
|
+
results = candidates.select do |row|
|
|
143
|
+
row_tags = parse_tags(row[:tags])
|
|
144
|
+
tags.all? { |t| row_tags.include?(t) }
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
{ success: true, results: results, count: results.size }
|
|
148
|
+
rescue StandardError => e
|
|
149
|
+
{ success: false, error: e.message }
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
def promote_to_global(tags:, min_confidence: 0.6) # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
153
|
+
return { success: false, error: :not_started } unless started?
|
|
154
|
+
|
|
155
|
+
entries = query_by_tags(tags: tags)
|
|
156
|
+
return { success: true, promoted: 0 } unless entries[:success] && entries[:results]&.any?
|
|
157
|
+
|
|
158
|
+
promoted = 0
|
|
159
|
+
entries[:results].each do |entry|
|
|
160
|
+
next if entry[:confidence].to_f < min_confidence
|
|
161
|
+
|
|
162
|
+
entry_tags = parse_tags(entry[:tags])
|
|
163
|
+
hostname = ::Socket.gethostname rescue 'unknown' # rubocop:disable Style/RescueModifier
|
|
164
|
+
result = Legion::Apollo.ingest(
|
|
165
|
+
content: entry[:content],
|
|
166
|
+
tags: entry_tags + ['promoted_from_local'],
|
|
167
|
+
source_channel: 'local_promotion',
|
|
168
|
+
submitted_by: "node:#{hostname}",
|
|
169
|
+
confidence: entry[:confidence],
|
|
170
|
+
scope: :global
|
|
171
|
+
)
|
|
172
|
+
promoted += 1 if result[:success]
|
|
173
|
+
end
|
|
174
|
+
|
|
175
|
+
{ success: true, promoted: promoted }
|
|
176
|
+
rescue StandardError => e
|
|
177
|
+
{ success: false, error: e.message }
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
def hydrate_from_global # rubocop:disable Metrics/MethodLength,Metrics/AbcSize,Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
|
|
181
|
+
return { success: false, error: :not_started } unless started?
|
|
182
|
+
|
|
183
|
+
local_check = query_by_tags(tags: ['partner'])
|
|
184
|
+
return { success: true, skipped: :local_data_exists } if local_check[:success] && local_check[:results]&.any?
|
|
185
|
+
|
|
186
|
+
unless Legion::Apollo.transport_available? || Legion::Apollo.data_available?
|
|
187
|
+
return { success: true, skipped: :global_unavailable }
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
global_entries = Legion::Apollo.retrieve(text: 'partner bond', scope: :global, limit: 20)
|
|
191
|
+
unless global_entries[:success] && global_entries[:results]&.any?
|
|
192
|
+
return { success: true, skipped: :no_global_data }
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
hydrated = 0
|
|
196
|
+
global_entries[:results].each do |entry|
|
|
197
|
+
entry_tags = entry[:tags].is_a?(Array) ? entry[:tags] : []
|
|
198
|
+
clean_tags = entry_tags.reject { |t| t == 'promoted_from_local' } + ['hydrated_from_global']
|
|
199
|
+
|
|
200
|
+
result = ingest(
|
|
201
|
+
content: entry[:content],
|
|
202
|
+
tags: clean_tags,
|
|
203
|
+
confidence: ((entry[:confidence] || 0.5) * 0.9).round(10),
|
|
204
|
+
source_channel: 'global_hydration'
|
|
205
|
+
)
|
|
206
|
+
hydrated += 1 if result[:success]
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
{ success: true, hydrated: hydrated }
|
|
210
|
+
rescue StandardError => e
|
|
211
|
+
{ success: false, error: e.message }
|
|
212
|
+
end
|
|
213
|
+
|
|
134
214
|
private
|
|
135
215
|
|
|
136
216
|
def self_knowledge_files
|
data/lib/legion/apollo.rb
CHANGED