legion-llm 0.6.0 → 0.6.2

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: f65ac724c32de98ddfa324545b62e81cda38e27efdcdcbceb21abd21729ae599
4
- data.tar.gz: 7c02a90eac3bda99512da956c889a06084980468c034c25e0c602d7e06db7ac3
3
+ metadata.gz: f52899e131c7b40d4dba1576584fa0e9709022db8c83dfc6c2bf21044c58efe4
4
+ data.tar.gz: a45b7ba54bd018efbdaa61c1b13d53608560c432cb804ccb565aea5e99e0087e
5
5
  SHA512:
6
- metadata.gz: 71f7496e4df651c8d93bf3ac27059a2075f0b82299afa1f61f98138dc81db90ed3139c27b933774969d7d727ff9483db2a92514d82460a3f3de1c2dfbbff44ff
7
- data.tar.gz: 6757e931ab1bef7d95c1470a3cf24077fa777683955bc0e5ed6ab6b7d7ef6a2f6f4f613668b6395a52a4200cdb97ae9aebc80f6bc9af5ee896c8a44142215425
6
+ metadata.gz: ea38c1ca6a6298e7aae10524afa822a2e85a83d0958ea8c830cf046470a3260db3605a0a59fed85bca08939a1914c86e226e306a11bbb602ffb6b6b13cfa6181
7
+ data.tar.gz: a57924ff5d697c34160d1fb5aa4ce515f55a7e0f52e5bab8d740bcbe31bfb6a947d475e44404f3f84b8078441df6087f1b8f466d25a0eb6e937781c601c99b7b
data/CHANGELOG.md CHANGED
@@ -2,6 +2,19 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.6.2] - 2026-03-31
6
+
7
+ ### Fixed
8
+ - Reduce `OLLAMA_CONTEXT_CHARS` from 2048 to 1400 for 512-token models (mxbai-embed-large, bge-large, snowflake-arctic-embed) to account for real tokenization ratios (~3 chars/token)
9
+ - `generate_ollama` now catches context-length rejections and retries with chunking at 60% char limit instead of failing over to a potentially broken provider
10
+
11
+ ## [0.6.1] - 2026-03-31
12
+
13
+ ### Added
14
+ - Advisory step reads calibration_weights from Apollo Local, includes in advisory enrichment
15
+ - Advisory meta recording: classifies advisory types and calls `Legion::Gaia.record_advisory_meta`
16
+ - Advisory type classification based on partner context (tone, verbosity, format, context, hint)
17
+
5
18
  ## [0.6.0] - 2026-03-31
6
19
 
7
20
  ### Added
@@ -17,12 +17,12 @@ module Legion
17
17
  TARGET_DIMENSION = 1024
18
18
 
19
19
  OLLAMA_CONTEXT_CHARS = {
20
- 'mxbai-embed-large' => 2048,
21
- 'bge-large' => 2048,
22
- 'snowflake-arctic-embed' => 2048,
23
- 'nomic-embed-text' => 32_768
20
+ 'mxbai-embed-large' => 1400,
21
+ 'bge-large' => 1400,
22
+ 'snowflake-arctic-embed' => 1400,
23
+ 'nomic-embed-text' => 24_000
24
24
  }.freeze
25
- OLLAMA_DEFAULT_CONTEXT_CHARS = 2048
25
+ OLLAMA_DEFAULT_CONTEXT_CHARS = 1400
26
26
 
27
27
  PREFIX_REGISTRY = {
28
28
  'nomic-embed-text' => { document: 'search_document: ', query: 'search_query: ' },
@@ -219,6 +219,12 @@ module Legion
219
219
  return dimension_error(model, :ollama, vector) if vector.is_a?(String)
220
220
 
221
221
  { vector: vector, model: model, provider: :ollama, dimensions: vector&.size || 0, tokens: 0 }
222
+ rescue RuntimeError => e
223
+ raise unless e.message.include?('input length exceeds')
224
+
225
+ reduced = (max_chars * 0.6).to_i
226
+ Legion::Logging.info("Ollama context exceeded, retrying with chunking at #{reduced} chars") if defined?(Legion::Logging)
227
+ generate_ollama_chunked(text: text, model: model, max_chars: reduced)
222
228
  end
223
229
 
224
230
  def generate_ollama_chunked(text:, model:, max_chars:)
@@ -21,6 +21,9 @@ module Legion
21
21
 
22
22
  enrich_advisory_with_partner_context(advisory)
23
23
 
24
+ calibration_weights = fetch_calibration_weights
25
+ advisory[:calibration_weights] = calibration_weights if calibration_weights
26
+
24
27
  @enrichments['gaia:advisory'] = {
25
28
  content: advisory_summary(advisory),
26
29
  data: advisory,
@@ -46,6 +49,8 @@ module Legion
46
49
  direction: :inbound, detail: advisory_summary(advisory),
47
50
  from: 'gaia', to: 'pipeline'
48
51
  )
52
+
53
+ record_advisory_meta_to_gaia(advisory)
49
54
  rescue StandardError => e
50
55
  @warnings << "GAIA advisory error: #{e.message}"
51
56
  end
@@ -160,6 +165,49 @@ module Legion
160
165
  :infrequent
161
166
  end
162
167
  end
168
+
169
+ def fetch_calibration_weights
170
+ return nil unless apollo_local_available?
171
+
172
+ result = ::Legion::Apollo::Local.query(
173
+ text: 'bond calibration weights',
174
+ tags: %w[bond calibration weights]
175
+ )
176
+ return nil unless result[:success] && result[:results]&.any?
177
+
178
+ raw = ::JSON.parse(result[:results].first[:content])
179
+ raw['weights']
180
+ rescue StandardError
181
+ nil
182
+ end
183
+
184
+ def record_advisory_meta_to_gaia(advisory)
185
+ return unless defined?(::Legion::Gaia) && ::Legion::Gaia.respond_to?(:record_advisory_meta)
186
+ return unless advisory[:partner_context]
187
+
188
+ advisory_id = SecureRandom.uuid
189
+ advisory_types = classify_advisory_types(advisory)
190
+
191
+ ::Legion::Gaia.record_advisory_meta(
192
+ advisory_id: advisory_id,
193
+ advisory_types: advisory_types
194
+ )
195
+ rescue StandardError
196
+ nil
197
+ end
198
+
199
+ def classify_advisory_types(advisory)
200
+ types = []
201
+ pc = advisory[:partner_context]
202
+ return ['partner_hint'] unless pc
203
+
204
+ types << 'partner_hint' if pc
205
+ types << 'context_injection' if advisory[:context_window]
206
+ types << 'tone_adjustment' if pc[:recent_sentiment] && pc[:recent_sentiment] != :neutral
207
+ types << 'verbosity_adjustment' if pc[:interaction_pattern] && pc[:interaction_pattern] != :unknown
208
+ types << 'format_adjustment' if pc[:compatibility]
209
+ types.empty? ? ['partner_hint'] : types
210
+ end
163
211
  end
164
212
  end
165
213
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Legion
4
4
  module LLM
5
- VERSION = '0.6.0'
5
+ VERSION = '0.6.2'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: legion-llm
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Esity