ragnar-cli 0.1.0.pre.3 → 0.1.0.pre.4
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/README.md +187 -36
- data/lib/ragnar/cli.rb +527 -172
- data/lib/ragnar/cli_visualization.rb +184 -0
- data/lib/ragnar/config.rb +226 -0
- data/lib/ragnar/database.rb +94 -8
- data/lib/ragnar/llm_manager.rb +4 -1
- data/lib/ragnar/query_processor.rb +38 -20
- data/lib/ragnar/topic_modeling.rb +13 -10
- data/lib/ragnar/umap_processor.rb +77 -65
- data/lib/ragnar/umap_transform_service.rb +169 -88
- data/lib/ragnar/version.rb +1 -1
- metadata +43 -22
- data/lib/ragnar/topic_modeling/engine.rb +0 -301
- data/lib/ragnar/topic_modeling/labeling_strategies.rb +0 -300
- data/lib/ragnar/topic_modeling/llm_adapter.rb +0 -131
- data/lib/ragnar/topic_modeling/metrics.rb +0 -186
- data/lib/ragnar/topic_modeling/term_extractor.rb +0 -170
- data/lib/ragnar/topic_modeling/topic.rb +0 -117
- data/lib/ragnar/topic_modeling/topic_labeler.rb +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e0837b5d907d7b5336d938a4fa94c53b4dacdb96b56ffc753144dfaa4f476133
|
4
|
+
data.tar.gz: 7cd9d94241f8dc38a7dd4b3b2732966f21f9783b818087b30db3f03b5e6c2dfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a87f654f8502b292d3bfbea31c5f6bb5ba6f02638cd024e8efd623ec88c69f528c59ca4f2604437df9169ec4ad11ffcf4f6223441f9787b8d94ab312c149192
|
7
|
+
data.tar.gz: 133364ec6142c14ded8c58c7041aab342b290e9a196da54c9164f3dfc83d466410d173cb35aa5a5988b201dac251f34e441346f2debfcc0d8bb3e95e24476d1c
|
data/README.md
CHANGED
@@ -124,14 +124,14 @@ flowchart TB
|
|
124
124
|
### As a Gem
|
125
125
|
|
126
126
|
```bash
|
127
|
-
gem install ragnar
|
127
|
+
gem install ragnar-cli
|
128
128
|
```
|
129
129
|
|
130
130
|
### From Source
|
131
131
|
|
132
132
|
```bash
|
133
|
-
git clone https://github.com/
|
134
|
-
cd ragnar
|
133
|
+
git clone https://github.com/scientist-labs/ragnar-cli.git
|
134
|
+
cd ragnar-cli
|
135
135
|
bundle install
|
136
136
|
gem build ragnar.gemspec
|
137
137
|
gem install ./ragnar-*.gem
|
@@ -165,7 +165,36 @@ ragnar train-umap \
|
|
165
165
|
ragnar apply-umap
|
166
166
|
```
|
167
167
|
|
168
|
-
### 3.
|
168
|
+
### 3. Extract Topics
|
169
|
+
|
170
|
+
Perform topic modeling to discover themes in your indexed documents:
|
171
|
+
|
172
|
+
```bash
|
173
|
+
# Basic topic extraction (requires minimum 20-30 indexed documents)
|
174
|
+
ragnar topics
|
175
|
+
|
176
|
+
# Adjust clustering parameters for smaller datasets
|
177
|
+
ragnar topics --min-cluster-size 3 # Allow smaller topics
|
178
|
+
ragnar topics --min-samples 2 # Less strict density requirements
|
179
|
+
|
180
|
+
# Export visualizations
|
181
|
+
ragnar topics --export html # Interactive D3.js visualization
|
182
|
+
ragnar topics --export json # JSON data for further processing
|
183
|
+
|
184
|
+
# Verbose mode for debugging
|
185
|
+
ragnar topics --verbose
|
186
|
+
```
|
187
|
+
|
188
|
+
**Note**: Topic modeling requires sufficient documents to identify meaningful patterns. For best results:
|
189
|
+
- Index at least 20-30 documents (ideally 50+)
|
190
|
+
- Ensure documents cover diverse topics
|
191
|
+
- Documents should be substantial (50+ words each)
|
192
|
+
|
193
|
+
The HTML export includes:
|
194
|
+
- **Topic Bubbles**: Interactive bubble chart showing topic sizes and coherence
|
195
|
+
- **Embedding Scatter Plot**: Visualization of all documents in embedding space, colored by cluster
|
196
|
+
|
197
|
+
### 4. Query the System
|
169
198
|
|
170
199
|
```bash
|
171
200
|
# Basic query
|
@@ -197,7 +226,7 @@ When using `--verbose` or `-v`, you'll see:
|
|
197
226
|
6. **Response Generation**: The final LLM prompt and response
|
198
227
|
7. **Final Results**: Confidence score and source attribution
|
199
228
|
|
200
|
-
###
|
229
|
+
### 5. Check Statistics
|
201
230
|
|
202
231
|
```bash
|
203
232
|
ragnar stats
|
@@ -231,30 +260,111 @@ ragnar stats
|
|
231
260
|
|
232
261
|
## Configuration
|
233
262
|
|
234
|
-
|
263
|
+
Ragnar uses a flexible YAML-based configuration system that allows you to customize all aspects of the RAG pipeline.
|
235
264
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
265
|
+
### Configuration File
|
266
|
+
|
267
|
+
Ragnar looks for configuration files in the following order:
|
268
|
+
1. `.ragnar.yml` in the current directory
|
269
|
+
2. `.ragnarrc.yml` in the current directory
|
270
|
+
3. `ragnar.yml` in the current directory
|
271
|
+
4. `.ragnar.yml` in your home directory
|
272
|
+
5. Built-in defaults
|
273
|
+
|
274
|
+
Generate a configuration file:
|
275
|
+
```bash
|
276
|
+
# Create local config (in current directory)
|
277
|
+
ragnar init-config
|
278
|
+
|
279
|
+
# Create global config (in home directory)
|
280
|
+
ragnar init-config --global
|
281
|
+
|
282
|
+
# Force overwrite existing config
|
283
|
+
ragnar init-config --force
|
284
|
+
```
|
285
|
+
|
286
|
+
### Configuration Options
|
287
|
+
|
288
|
+
Example `.ragnar.yml` file:
|
289
|
+
|
290
|
+
```yaml
|
291
|
+
# Storage paths (all support ~ expansion)
|
292
|
+
storage:
|
293
|
+
database_path: "~/.cache/ragnar/database" # Vector database location
|
294
|
+
models_dir: "~/.cache/ragnar/models" # Downloaded model files
|
295
|
+
history_file: "~/.cache/ragnar/history" # Interactive mode history
|
296
|
+
|
297
|
+
# Embedding configuration
|
298
|
+
embeddings:
|
299
|
+
model: jinaai/jina-embeddings-v2-base-en # Embedding model to use
|
300
|
+
chunk_size: 512 # Tokens per chunk
|
301
|
+
chunk_overlap: 50 # Token overlap between chunks
|
302
|
+
|
303
|
+
# UMAP dimensionality reduction
|
304
|
+
umap:
|
305
|
+
reduced_dimensions: 64 # Target dimensions (2-100)
|
306
|
+
n_neighbors: 15 # UMAP neighbors parameter
|
307
|
+
min_dist: 0.1 # UMAP minimum distance
|
308
|
+
model_filename: umap_model.bin # Saved model filename
|
309
|
+
|
310
|
+
# LLM configuration
|
311
|
+
llm:
|
312
|
+
default_model: TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF
|
313
|
+
default_gguf_file: tinyllama-1.1b-chat-v1.0.q4_k_m.gguf
|
314
|
+
|
315
|
+
# Query processing
|
316
|
+
query:
|
317
|
+
top_k: 3 # Number of documents to retrieve
|
318
|
+
enable_query_rewriting: true # Use LLM to improve queries
|
319
|
+
|
320
|
+
# Interactive mode
|
321
|
+
interactive:
|
322
|
+
prompt: 'ragnar> ' # Command prompt
|
323
|
+
quiet_mode: true # Suppress verbose output
|
324
|
+
|
325
|
+
# Output settings
|
326
|
+
output:
|
327
|
+
show_progress: true # Show progress bars during indexing
|
241
328
|
```
|
242
329
|
|
330
|
+
### Viewing Configuration
|
331
|
+
|
332
|
+
Check current configuration:
|
333
|
+
```bash
|
334
|
+
# Show all configuration settings
|
335
|
+
ragnar config
|
336
|
+
|
337
|
+
# Show LLM model information
|
338
|
+
ragnar model
|
339
|
+
```
|
340
|
+
|
341
|
+
In interactive mode:
|
342
|
+
```bash
|
343
|
+
ragnar interactive
|
344
|
+
ragnar> config # Show configuration
|
345
|
+
ragnar> model # Show model details
|
346
|
+
```
|
347
|
+
|
348
|
+
### Environment Variables
|
349
|
+
|
350
|
+
Configuration values can be overridden with environment variables:
|
351
|
+
- `XDG_CACHE_HOME` - Override default cache directory (~/.cache)
|
352
|
+
|
243
353
|
### Supported Models
|
244
354
|
|
245
355
|
**Embedding Models** (via red-candle):
|
246
|
-
- jinaai/jina-embeddings-v2-base-en
|
247
|
-
- BAAI/bge-base-en-v1.5
|
248
|
-
- sentence-transformers/all-MiniLM-L6-v2
|
356
|
+
- `jinaai/jina-embeddings-v2-base-en` (default, 768 dimensions)
|
357
|
+
- `BAAI/bge-base-en-v1.5`
|
358
|
+
- `sentence-transformers/all-MiniLM-L6-v2`
|
249
359
|
|
250
|
-
**LLM Models** (via red-candle):
|
251
|
-
-
|
252
|
-
-
|
253
|
-
-
|
360
|
+
**LLM Models** (via red-candle, GGUF format):
|
361
|
+
- `TheBloke/TinyLlama-1.1B-Chat-v1.0-GGUF` (default, fast)
|
362
|
+
- `TheBloke/Qwen2.5-1.5B-Instruct-GGUF`
|
363
|
+
- `TheBloke/phi-2-GGUF`
|
254
364
|
|
255
365
|
**Reranker Models** (via red-candle):
|
256
|
-
- BAAI/bge-reranker-base
|
257
|
-
- cross-encoder/ms-marco-MiniLM-L-6-v2
|
366
|
+
- `BAAI/bge-reranker-base`
|
367
|
+
- `cross-encoder/ms-marco-MiniLM-L-6-v2`
|
258
368
|
|
259
369
|
## Advanced Usage
|
260
370
|
|
@@ -284,6 +394,60 @@ puts result[:answer]
|
|
284
394
|
puts "Confidence: #{result[:confidence]}%"
|
285
395
|
```
|
286
396
|
|
397
|
+
### Topic Modeling
|
398
|
+
|
399
|
+
Extract topics from your indexed documents:
|
400
|
+
|
401
|
+
```ruby
|
402
|
+
# Example with sufficient documents for clustering (minimum ~20-30 needed)
|
403
|
+
documents = [
|
404
|
+
# Finance cluster
|
405
|
+
"Federal Reserve raises interest rates to combat inflation",
|
406
|
+
"Stock markets rally on positive earnings reports",
|
407
|
+
"Cryptocurrency markets show increased volatility",
|
408
|
+
"Corporate bonds yield higher returns this quarter",
|
409
|
+
"Central banks coordinate global monetary policy",
|
410
|
+
|
411
|
+
# Technology cluster
|
412
|
+
"AI breakthrough in natural language processing announced",
|
413
|
+
"Machine learning transforms healthcare diagnostics",
|
414
|
+
"Cloud computing adoption accelerates in enterprises",
|
415
|
+
"Quantum computing reaches new error correction milestone",
|
416
|
+
"Open source frameworks receive major updates",
|
417
|
+
|
418
|
+
# Healthcare cluster
|
419
|
+
"Clinical trials show promise for cancer immunotherapy",
|
420
|
+
"Telemedicine reshapes patient care delivery models",
|
421
|
+
"Gene editing advances treatment for rare diseases",
|
422
|
+
"Mental health awareness campaigns gain momentum",
|
423
|
+
"mRNA vaccine technology platform expands",
|
424
|
+
|
425
|
+
# Add more documents for better clustering...
|
426
|
+
# See TOPIC_MODELING_EXAMPLE.md for complete example
|
427
|
+
]
|
428
|
+
|
429
|
+
# Extract topics using Topical
|
430
|
+
database = Ragnar::Database.new("ragnar_database")
|
431
|
+
docs = database.get_all_documents_with_embeddings
|
432
|
+
|
433
|
+
embeddings = docs.map { |d| d[:embedding] }
|
434
|
+
texts = docs.map { |d| d[:chunk_text] }
|
435
|
+
|
436
|
+
topics = Topical.extract(
|
437
|
+
embeddings: embeddings,
|
438
|
+
documents: texts,
|
439
|
+
min_topic_size: 3 # Minimum docs per topic
|
440
|
+
)
|
441
|
+
|
442
|
+
topics.each do |topic|
|
443
|
+
puts "Topic: #{topic.label}"
|
444
|
+
puts "Terms: #{topic.terms.join(', ')}"
|
445
|
+
puts "Size: #{topic.size} documents\n\n"
|
446
|
+
end
|
447
|
+
```
|
448
|
+
|
449
|
+
For a complete working example with 40+ documents, see [TOPIC_MODELING_EXAMPLE.md](TOPIC_MODELING_EXAMPLE.md).
|
450
|
+
|
287
451
|
### Custom Chunking Strategies
|
288
452
|
|
289
453
|
```ruby
|
@@ -420,20 +584,7 @@ MIT License - see LICENSE file for details
|
|
420
584
|
|
421
585
|
This project integrates several excellent Ruby gems:
|
422
586
|
- [red-candle](https://github.com/assaydepot/red-candle) - Ruby ML/LLM toolkit
|
423
|
-
- [lancelot](https://github.com/
|
424
|
-
- [clusterkit](https://github.com/
|
425
|
-
- [parsekit](https://github.com/
|
587
|
+
- [lancelot](https://github.com/scientist-labs/lancelot) - Lance database bindings
|
588
|
+
- [clusterkit](https://github.com/scientist-labs/clusterkit) - UMAP and clustering implementation
|
589
|
+
- [parsekit](https://github.com/scientist-labs/parsekit) - Content extraction
|
426
590
|
- [baran](https://github.com/moeki0/baran) - Text splitting utilities
|
427
|
-
|
428
|
-
## Roadmap
|
429
|
-
|
430
|
-
- [ ] Add support for PDF and HTML documents
|
431
|
-
- [ ] Implement incremental indexing
|
432
|
-
- [ ] Add conversation memory for multi-turn queries
|
433
|
-
- [ ] Support for hybrid search (vector + keyword)
|
434
|
-
- [ ] Web UI for interactive queries
|
435
|
-
- [ ] Docker containerization
|
436
|
-
- [ ] Performance benchmarking suite
|
437
|
-
- [ ] Support for multiple embedding models simultaneously
|
438
|
-
- [ ] Query result caching
|
439
|
-
- [ ] Automatic index optimization
|