ragnar-cli 0.1.0.pre.3 → 0.1.0.pre.5

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: 6b9a7fdbf0345f1c111f8028f8b881d8014a55226cfe3d02f6a76fd6cd9b213c
4
- data.tar.gz: 2341e27f16b442c0631876303e0da5141438559ef6685e2c15514cd18416d99c
3
+ metadata.gz: 06c692710e5d5deb8cf5b8122050968deb459ad6feebd5bbdeabf63679a04d7c
4
+ data.tar.gz: dc8784c1b36aec7c473b9f93cc1929bdbd1d75ecec18d727c4e7892aeea6df30
5
5
  SHA512:
6
- metadata.gz: a87f39a5dfd246732be4e24b19aba8b49a7a735f78d825d0241f04b0b776fc8b23c15f0b3488416dedfba37d9027ff6442f38ab2aad43bb79395e0c769247275
7
- data.tar.gz: 00d7533c2e16b57da59786a840f1b653cfe472c63168a6e003abb31a79b3f6e0f056fdabe32f4b4566ea682d229e3d0710167358ab7c78fd18c497690d9a3675
6
+ metadata.gz: cd6e88640e7629725fef32214f088d11362ddbcbbf52a90aa6d315ecc0b08c0d8f487501fd802221c9b647f1e22b55aa91a97f8eefa7046b38c2c49eff3d1bd3
7
+ data.tar.gz: b58174568e4b76d6cce4aeb19e7674cddb9f8c11c0c6e44a1da0e9f545263a3874b0f99cc16fdc3723e516ffb7c4ffee6660540c891cd595b805ded4f3ff0a49
data/README.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  A complete Ruby implementation of Retrieval-Augmented Generation (RAG) pipeline using native Ruby ML/NLP gems.
4
4
 
5
+ <p align="center">
6
+ <img src="/docs/assets/screenshot.png" alt="ragnar TUI" width="600">
7
+ </p>
8
+
5
9
  ## Overview
6
10
 
7
11
  Ragnar provides a production-ready RAG pipeline for Ruby applications, integrating:
@@ -124,14 +128,14 @@ flowchart TB
124
128
  ### As a Gem
125
129
 
126
130
  ```bash
127
- gem install ragnar
131
+ gem install ragnar-cli
128
132
  ```
129
133
 
130
134
  ### From Source
131
135
 
132
136
  ```bash
133
- git clone https://github.com/yourusername/ragnar.git
134
- cd ragnar
137
+ git clone https://github.com/scientist-labs/ragnar-cli.git
138
+ cd ragnar-cli
135
139
  bundle install
136
140
  gem build ragnar.gemspec
137
141
  gem install ./ragnar-*.gem
@@ -151,21 +155,70 @@ ragnar index ./documents \
151
155
  --chunk-overlap 100
152
156
  ```
153
157
 
154
- ### 2. Train UMAP (Optional)
158
+ ### 2. Interactive Mode (TUI)
159
+
160
+ Running `ragnar` with no arguments launches an interactive TUI powered by [ratatui](https://ratatui.rs/):
161
+
162
+ ```bash
163
+ # Launch the TUI (default when no command given)
164
+ ragnar
165
+
166
+ # Or explicitly
167
+ ragnar interactive
168
+ ```
169
+
170
+ The TUI provides:
171
+ - **Auto-completion** for commands and options
172
+ - **Persistent history** across sessions
173
+ - **Live output** — see indexing progress, query results, and topic analysis inline
174
+ - **All CLI commands** available via `/command` syntax (e.g., `/index .`, `/umap train`, `/query "my question"`)
175
+ - **`/verbose`** — toggle verbose mode to see query pipeline details (retrieval, reranking, context)
176
+ - **`/profile`** — list or switch LLM profiles mid-session
177
+
178
+ ### 3. Train UMAP (Optional)
155
179
 
156
180
  Reduce embedding dimensions for faster search:
157
181
 
158
182
  ```bash
159
183
  # Train UMAP model (auto-adjusts parameters based on data)
160
- ragnar train-umap \
184
+ ragnar umap train \
161
185
  --n-components 50 \
162
186
  --n-neighbors 15
163
187
 
164
188
  # Apply to all embeddings
165
- ragnar apply-umap
189
+ ragnar umap apply
166
190
  ```
167
191
 
168
- ### 3. Query the System
192
+ ### 4. Extract Topics
193
+
194
+ Perform topic modeling to discover themes in your indexed documents:
195
+
196
+ ```bash
197
+ # Basic topic extraction (requires minimum 20-30 indexed documents)
198
+ ragnar topics
199
+
200
+ # Adjust clustering parameters for smaller datasets
201
+ ragnar topics --min-cluster-size 3 # Allow smaller topics
202
+ ragnar topics --min-samples 2 # Less strict density requirements
203
+
204
+ # Export visualizations
205
+ ragnar topics --export html # Interactive D3.js visualization
206
+ ragnar topics --export json # JSON data for further processing
207
+
208
+ # Verbose mode for debugging
209
+ ragnar topics --verbose
210
+ ```
211
+
212
+ **Note**: Topic modeling requires sufficient documents to identify meaningful patterns. For best results:
213
+ - Index at least 20-30 documents (ideally 50+)
214
+ - Ensure documents cover diverse topics
215
+ - Documents should be substantial (50+ words each)
216
+
217
+ The HTML export includes:
218
+ - **Topic Bubbles**: Interactive bubble chart showing topic sizes and coherence
219
+ - **Embedding Scatter Plot**: Visualization of all documents in embedding space, colored by cluster
220
+
221
+ ### 5. Query the System
169
222
 
170
223
  ```bash
171
224
  # Basic query
@@ -197,7 +250,7 @@ When using `--verbose` or `-v`, you'll see:
197
250
  6. **Response Generation**: The final LLM prompt and response
198
251
  7. **Final Results**: Confidence score and source attribution
199
252
 
200
- ### 4. Check Statistics
253
+ ### 6. Check Statistics
201
254
 
202
255
  ```bash
203
256
  ragnar stats
@@ -231,30 +284,142 @@ ragnar stats
231
284
 
232
285
  ## Configuration
233
286
 
234
- ### Default Settings
287
+ Ragnar uses a flexible YAML-based configuration system that allows you to customize all aspects of the RAG pipeline.
235
288
 
236
- ```ruby
237
- DEFAULT_DB_PATH = "ragnar_database"
238
- DEFAULT_CHUNK_SIZE = 512
239
- DEFAULT_CHUNK_OVERLAP = 50
240
- DEFAULT_EMBEDDING_MODEL = "jinaai/jina-embeddings-v2-base-en"
289
+ ### Configuration File
290
+
291
+ Ragnar looks for configuration files in the following order:
292
+ 1. `.ragnar.yml` in the current directory
293
+ 2. `.ragnarrc.yml` in the current directory
294
+ 3. `ragnar.yml` in the current directory
295
+ 4. `.ragnar.yml` in your home directory
296
+ 5. Built-in defaults
297
+
298
+ Generate a configuration file:
299
+ ```bash
300
+ # Create local config (in current directory)
301
+ ragnar init-config
302
+
303
+ # Create global config (in home directory)
304
+ ragnar init-config --global
305
+
306
+ # Force overwrite existing config
307
+ ragnar init-config --force
241
308
  ```
242
309
 
310
+ ### Configuration Options
311
+
312
+ Example `.ragnar.yml` file:
313
+
314
+ ```yaml
315
+ # Storage paths (all support ~ expansion)
316
+ storage:
317
+ database_path: "~/.cache/ragnar/database"
318
+ models_dir: "~/.cache/ragnar/models"
319
+ history_file: "~/.cache/ragnar/history"
320
+
321
+ # Embedding configuration
322
+ embeddings:
323
+ model: jinaai/jina-embeddings-v2-base-en
324
+ chunk_size: 512
325
+ chunk_overlap: 50
326
+
327
+ # UMAP dimensionality reduction
328
+ umap:
329
+ reduced_dimensions: 64
330
+ n_neighbors: 15
331
+ min_dist: 0.1
332
+ model_filename: umap_model.bin
333
+
334
+ # LLM profiles — switch between local and cloud models
335
+ llm:
336
+ default_profile: red_candle
337
+ profiles:
338
+ red_candle:
339
+ provider: red_candle
340
+ model: MaziyarPanahi/Qwen3-4B-GGUF
341
+ opus:
342
+ provider: anthropic
343
+ model: claude-opus-4-6
344
+ api_key: sk-ant-... # or set ANTHROPIC_API_KEY env var
345
+ sonnet:
346
+ provider: anthropic
347
+ model: claude-sonnet-4-6
348
+ ollama:
349
+ provider: ollama
350
+ model: llama3.1:8b
351
+
352
+ # Query processing
353
+ query:
354
+ top_k: 3 # Number of documents to retrieve
355
+ enable_query_rewriting: true # Use LLM to improve queries
356
+ enable_reranking: true # Cross-encoder reranking (disable for small corpora)
357
+ reranker_model: BAAI/bge-reranker-base # Reranker model
358
+
359
+ # Interactive mode
360
+ interactive:
361
+ prompt: 'ragnar> '
362
+ quiet_mode: true
363
+
364
+ # Output settings
365
+ output:
366
+ show_progress: true
367
+ ```
368
+
369
+ ### LLM Profiles
370
+
371
+ Profiles let you switch between LLM providers without editing config. Use local models for development and cloud models for production quality:
372
+
373
+ ```bash
374
+ # Use a specific profile for a single command
375
+ ragnar --profile opus query "What is our security policy?"
376
+
377
+ # In TUI mode, switch profiles mid-session
378
+ ragnar> /profile # List available profiles
379
+ ragnar> /profile opus # Switch to Opus
380
+ ragnar> /profile red_candle # Switch back to local
381
+ ```
382
+
383
+ Ragnar supports any [RubyLLM](https://rubyllm.com/) provider: `red_candle` (local), `anthropic`, `openai`, `ollama`, and more. API keys can be set per-profile in the config or via environment variables (`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, etc.).
384
+
385
+ ### Viewing Configuration
386
+
387
+ ```bash
388
+ ragnar config # Show all settings including active profile
389
+ ragnar model # Show LLM model information
390
+ ragnar profile # List all LLM profiles
391
+ ```
392
+
393
+ In interactive mode (launch with `ragnar`):
394
+ ```
395
+ ragnar> /config # Show configuration
396
+ ragnar> /profile # List profiles
397
+ ```
398
+
399
+ ### Environment Variables
400
+
401
+ Configuration values can be overridden with environment variables:
402
+ - `XDG_CACHE_HOME` - Override default cache directory (~/.cache)
403
+ - `ANTHROPIC_API_KEY` - Anthropic API key (used by anthropic profiles)
404
+ - `OPENAI_API_KEY` - OpenAI API key (used by openai profiles)
405
+
243
406
  ### Supported Models
244
407
 
245
- **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
408
+ **LLM Providers** (via RubyLLM):
409
+ - `red_candle` — Local GGUF models (default): `MaziyarPanahi/Qwen3-4B-GGUF`, `MaziyarPanahi/Qwen3-8B-GGUF`
410
+ - `anthropic` — Claude models: `claude-opus-4-6`, `claude-sonnet-4-6`
411
+ - `openai` — GPT models: `gpt-4o`, `gpt-4o-mini`
412
+ - `ollama` — Local Ollama models: `llama3.1:8b`, `mistral:7b`
413
+ - Any other [RubyLLM provider](https://rubyllm.com/providers/)
249
414
 
250
- **LLM Models** (via red-candle):
251
- - Qwen/Qwen2.5-1.5B-Instruct
252
- - microsoft/phi-2
253
- - TinyLlama/TinyLlama-1.1B-Chat-v1.0
415
+ **Embedding Models** (via red-candle):
416
+ - `jinaai/jina-embeddings-v2-base-en` (default, 768 dimensions)
417
+ - `BAAI/bge-base-en-v1.5`
418
+ - `sentence-transformers/all-MiniLM-L6-v2`
254
419
 
255
- **Reranker Models** (via red-candle):
256
- - BAAI/bge-reranker-base
257
- - cross-encoder/ms-marco-MiniLM-L-6-v2
420
+ **Reranker Models** (via red-candle, configurable):
421
+ - `BAAI/bge-reranker-base` (default, XLM-RoBERTa)
422
+ - `cross-encoder/ms-marco-MiniLM-L-12-v2` (smaller, BERT-based)
258
423
 
259
424
  ## Advanced Usage
260
425
 
@@ -284,6 +449,60 @@ puts result[:answer]
284
449
  puts "Confidence: #{result[:confidence]}%"
285
450
  ```
286
451
 
452
+ ### Topic Modeling
453
+
454
+ Extract topics from your indexed documents:
455
+
456
+ ```ruby
457
+ # Example with sufficient documents for clustering (minimum ~20-30 needed)
458
+ documents = [
459
+ # Finance cluster
460
+ "Federal Reserve raises interest rates to combat inflation",
461
+ "Stock markets rally on positive earnings reports",
462
+ "Cryptocurrency markets show increased volatility",
463
+ "Corporate bonds yield higher returns this quarter",
464
+ "Central banks coordinate global monetary policy",
465
+
466
+ # Technology cluster
467
+ "AI breakthrough in natural language processing announced",
468
+ "Machine learning transforms healthcare diagnostics",
469
+ "Cloud computing adoption accelerates in enterprises",
470
+ "Quantum computing reaches new error correction milestone",
471
+ "Open source frameworks receive major updates",
472
+
473
+ # Healthcare cluster
474
+ "Clinical trials show promise for cancer immunotherapy",
475
+ "Telemedicine reshapes patient care delivery models",
476
+ "Gene editing advances treatment for rare diseases",
477
+ "Mental health awareness campaigns gain momentum",
478
+ "mRNA vaccine technology platform expands",
479
+
480
+ # Add more documents for better clustering...
481
+ # See TOPIC_MODELING_EXAMPLE.md for complete example
482
+ ]
483
+
484
+ # Extract topics using Topical
485
+ database = Ragnar::Database.new("ragnar_database")
486
+ docs = database.get_all_documents_with_embeddings
487
+
488
+ embeddings = docs.map { |d| d[:embedding] }
489
+ texts = docs.map { |d| d[:chunk_text] }
490
+
491
+ topics = Topical.extract(
492
+ embeddings: embeddings,
493
+ documents: texts,
494
+ min_topic_size: 3 # Minimum docs per topic
495
+ )
496
+
497
+ topics.each do |topic|
498
+ puts "Topic: #{topic.label}"
499
+ puts "Terms: #{topic.terms.join(', ')}"
500
+ puts "Size: #{topic.size} documents\n\n"
501
+ end
502
+ ```
503
+
504
+ For a complete working example with 40+ documents, see [TOPIC_MODELING_EXAMPLE.md](TOPIC_MODELING_EXAMPLE.md).
505
+
287
506
  ### Custom Chunking Strategies
288
507
 
289
508
  ```ruby
@@ -420,20 +639,9 @@ MIT License - see LICENSE file for details
420
639
 
421
640
  This project integrates several excellent Ruby gems:
422
641
  - [red-candle](https://github.com/assaydepot/red-candle) - Ruby ML/LLM toolkit
423
- - [lancelot](https://github.com/cpetersen/lancelot) - Lance database bindings
424
- - [clusterkit](https://github.com/cpetersen/clusterkit) - UMAP and clustering implementation
425
- - [parsekit](https://github.com/cpetersen/parsekit) - Content extraction
642
+ - [lancelot](https://github.com/scientist-labs/lancelot) - Lance database bindings
643
+ - [clusterkit](https://github.com/scientist-labs/clusterkit) - UMAP and clustering implementation
644
+ - [thor-interactive](https://github.com/scientist-labs/thor-interactive) - Interactive TUI for Thor CLIs
645
+ - [ratatui_ruby](https://github.com/nicholasgasior/ratatui-ruby) - Ratatui terminal UI bindings
646
+ - [parsekit](https://github.com/scientist-labs/parsekit) - Content extraction
426
647
  - [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