kjarni-cli 0.7.0

Kjarni from the shell: classification, embeddings, reranking, search, chat, summarization, translation and speech-to-text as commands, and an MCP server for AI agents. Same output as PyTorch.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<p align="center">
  <a href="https://kjarni.ai"><img src="https://raw.githubusercontent.com/olafurjohannsson/kjarni/main/assets/kjarni-banner.png" alt="kjarni: local AI inference in a single native library" width="600"></a>
</p>

# Kjarni CLI

**Run transformer models from your shell. Same output as PyTorch.**

`kjarni` is the command-line build of Kjarni, a transformer inference library:
classification, embeddings, similarity, reranking, indexing and search, chat,
summarization, translation and speech to text, as ordinary commands that read stdin
and write text or JSON. `kjarni mcp` serves the same tools to AI agents over MCP.

```bash
curl -fsSL https://kjarni.ai/install.sh | sh     # Linux and macOS
irm https://kjarni.ai/install.ps1 | iex          # Windows
cargo install kjarni-cli                         # from source
```

# Commands

## Model Management

### List available models
```bash
# List all models
kjarni model list

# Filter by architecture
kjarni model list --arch encoder
kjarni model list --arch decoder
kjarni model list --arch encoder-decoder
kjarni model list --arch cross-encoder
```

### Download a model
```bash
kjarni model download llama-3.2-1b
kjarni model download minilm-l6-v2
```

### Show model info
```bash
kjarni model info llama-3.2-1b
```

### Search for models
```bash
kjarni model search llama
kjarni model search summarize
```

---

## Text Generation

### Basic generation
```bash
kjarni generate "Once upon a time"
```

### With options
```bash
kjarni generate "The meaning of life is" \
  --model llama-3.2-3b \
  --max-tokens 200 \
  --temperature 0.8
```

### Greedy decoding (deterministic)
```bash
kjarni generate "The capital of France is" --greedy
```

### Creative writing
```bash
kjarni generate "Write a poem about" \
  --temperature 1.0 \
  --top-p 0.95 \
  --max-tokens 200
```

### From file
```bash
kjarni generate prompt.txt --max-tokens 500
```

### GPU acceleration
```bash
kjarni generate "Hello" --gpu
```

### Quiet mode (for piping)
```bash
echo "Explain quantum computing:" | kjarni generate -q
```

---

## Chat

### Interactive chat
```bash
kjarni chat
```

### With custom model
```bash
kjarni chat --model llama-3-8b-instruct
```

### With a model folder
```bash
kjarni chat --model-path ./Qwen2.5-0.5B-Instruct
```
Any Llama, Qwen2, Qwen 3.5, Mistral, Phi-3 or GPT-2 folder from the Hugging Face Hub, formatted
with its own chat template. `kjarni generate --model-path` takes the same folders.

### With system prompt
```bash
kjarni chat --system "You are a pirate. Respond in pirate speak."
```

### Chat commands
```
> /help           Show available commands
> /quit           Exit chat
> /clear          Clear conversation history
> /system         Show current system prompt
> /system <text>  Set new system prompt
> /history        Show conversation history
```

---

## Summarization

### Basic summarization
```bash
kjarni summarize article.txt
```

### From stdin
```bash
cat long_document.txt | kjarni summarize
```

### With options
```bash
kjarni summarize article.txt \
  --max-length 100 \
  --min-length 30 \
  --num-beams 6
```

### GPU acceleration
```bash
kjarni summarize large_doc.txt --model bart-large-cnn --gpu
```

### Quiet mode for scripting
```bash
cat article.txt | kjarni summarize -q > summary.txt
```

### With a model folder
```bash
kjarni summarize -i article.txt --model-path ./distilbart-cnn-12-6
kjarni translate -i "Where is the library?" --model-path ./opus-mt-en-ROMANCE --src en --dst es
kjarni transcribe meeting.wav --model-path ./whisper-base.en
```
A BART or T5 folder summarizes, a Marian (`Helsinki-NLP/opus-mt-*`) or T5 folder
translates, and a Whisper folder transcribes. Weights may be safetensors or
`pytorch_model.bin`. A Marian folder translates the languages its
`tokenizer_config.json` names.

---

## Text Encoding (Embeddings)

### Encode text
```bash
kjarni encode "Hello world"
```

### Encode from file
```bash
kjarni encode document.txt
```

### Batch encoding from stdin
```bash
echo -e "First text\nSecond text\nThird text" | kjarni encode
```

### Output formats
```bash
kjarni encode "text" --format json    # Full JSON with metadata
kjarni encode "text" --format jsonl   # JSON lines
kjarni encode "text" --format raw     # Space-separated floats
```

### Custom pooling and normalization
```bash
kjarni encode "text" --pooling cls --normalize false
kjarni encode "text" --pooling mean --normalize true
```

### Different model
```bash
kjarni encode "text" --model mpnet-base-v2
```

---

## Semantic Similarity

### Compare two texts
```bash
kjarni similarity "The cat sat on the mat" "A feline was sitting on a rug"
```

### Compare files
```bash
kjarni similarity doc1.txt doc2.txt
```

### Quiet mode (output score only)
```bash
kjarni similarity "text1" "text2" -q
# Output: 0.8234
```

---

## Reranking

### Rerank documents
```bash
kjarni rerank "machine learning" doc1.txt doc2.txt doc3.txt
```

### From stdin (one document per line)
```bash
echo -e "Python is great\nRust is fast\nJava is verbose" | \
  kjarni rerank "systems programming"
```

### Top-K results
```bash
kjarni rerank "query" doc1.txt doc2.txt doc3.txt --top-k 2
```

### Output formats
```bash
kjarni rerank "query" docs/*.txt --format json
kjarni rerank "query" docs/*.txt --format text
kjarni rerank "query" docs/*.txt --format docs  # Just documents, for piping
```

---

## Indexing

### Create an index
```bash
kjarni index create ./docs.idx ./documents/
```

### Index multiple paths
```bash
kjarni index create ./code.idx src/ lib/ tests/
```

### Custom chunking
```bash
kjarni index create ./large.idx ./books/ \
  --chunk-size 2000 \
  --chunk-overlap 400
```

### Add to existing index
```bash
kjarni index add ./docs.idx ./new-documents/
```

### Show index info
```bash
kjarni index info ./docs.idx
```

---

## Search

### Hybrid search (default)
```bash
kjarni search ./docs.idx "how to deploy kubernetes"
```

### Keyword-only (BM25)
```bash
kjarni search ./docs.idx "deployment error" --mode keyword
```

### Semantic search
```bash
kjarni search ./docs.idx "container orchestration" --mode semantic
```

### Limit results
```bash
kjarni search ./docs.idx "query" --top-k 5
```

### Output formats
```bash
kjarni search ./docs.idx "query" --format json
kjarni search ./docs.idx "query" --format docs  # Just text, for piping
```

---

## HTTP server

`kjarni serve` serves every task over HTTP: chat, completions, embeddings and
speech-to-text in OpenAI's format, reranking in Cohere's and Jina's, and
classification, translation, summarization and entity recognition in Kjarni's own.

```bash
kjarni serve                                    # http://127.0.0.1:8080/v1
kjarni serve --chat qwen2.5-1.5b-instruct --preload
kjarni serve --host 0.0.0.0 --api-key secret    # accept other machines
```

```bash
curl http://127.0.0.1:8080/v1/classify -H "Content-Type: application/json" \
  -d '{"input": "The shoes run a full size small.", "labels": ["sizing", "shipping", "price"]}'

curl http://127.0.0.1:8080/v1/rerank -H "Content-Type: application/json" \
  -d '{"query": "capital of France", "documents": ["Paris is the capital of France.", "Bananas are yellow."]}'

curl http://127.0.0.1:8080/v1/audio/transcriptions -F file=@speech.wav -F response_format=srt
```

Each request names a model with `"model"`, or gets the endpoint's default:
`--chat`, `--embed`, `--classify`, `--zero-shot`, `--rerank`, `--transcribe`,
`--translate`, `--summarize` and `--ner` set them. `GET /v1/models` lists every
model and the endpoint it serves.

## Advanced Pipelines

### Semantic grep (find relevant lines)
```bash
cat README.md | kjarni rerank "installation" -k 3 --format docs
```

### RAG pipeline
```bash
# Search, rerank, then generate
kjarni search ./knowledge.idx "deployment" -k 10 --format docs | \
  kjarni rerank "kubernetes deployment" -k 3 -q --format docs | \
  kjarni generate "Based on this context, explain:" -q
```

### Multi-document summarization
```bash
for f in articles/*.txt; do
  kjarni summarize "$f" -q
done | kjarni rerank "key findings" -k 1 --format docs
```

### Build embeddings for external use
```bash
cat texts.txt | kjarni encode --format raw > embeddings.txt
```

### Zero-shot classification with labels you choose
```bash
kjarni classify -m minilm-zeroshot --labels "sizing,shipping,price" \
  "The shoes run a full size small."
#   ✓         sizing  ██████████████████░░   91.8%
#              price  █░░░░░░░░░░░░░░░░░░░    6.6%
#           shipping  ░░░░░░░░░░░░░░░░░░░░    1.6%

# One text per line; --multi-label judges each label on its own, and
# --hypothesis changes the sentence each label is put into
kjarni classify -q -m minilm-zeroshot --multi-label \
  --hypothesis "This review is about {}." \
  --labels "sizing,shipping,price,quality,customer service" < reviews.txt
```

### Find similar content
```bash
kjarni search ./docs.idx "$(cat target.txt)" --mode semantic -k 5
```

### Batch processing
```bash
# Summarize all articles
find articles/ -name "*.txt" -exec sh -c \
  'kjarni summarize "$1" -q > summaries/$(basename "$1")' _ {} \;
```

### Full RAG with chat
```bash
CONTEXT=$(kjarni search ./brain.idx "$QUERY" -k 3 -q --format docs)
kjarni chat --system "Answer using only this context: $CONTEXT"
```

---

## Global Options

| Option | Description |
|--------|-------------|
| `--gpu` | Use GPU acceleration (WGPU) |
| `-q, --quiet` | Suppress status messages |
| `-m, --model` | Specify model name |
| `--model-path` | Use local model directory |

---

## Environment Variables

| Variable | Description |
|----------|-------------|
| `KJARNI_CACHE_DIR` | Model cache directory (default: `~/.cache/kjarni/`) |
| `RUST_LOG` | Logging level (e.g., `info`, `debug`) |