Skip to main content

Embeddings CLI

Generate text embeddings using the PraisonAI CLI with AI SDK backend.

Commands

Embed Text

# Single text
praisonai-ts embed text "Hello world"

# Multiple texts
praisonai-ts embed text "Hello" "World" "How are you?"

# With specific model
praisonai-ts embed text "Hello" --model text-embedding-3-large

# Save to file
praisonai-ts embed text "Hello" "World" --save embeddings.json

# JSON output
praisonai-ts embed text "Hello" --json

Embed File

# Embed file contents
praisonai-ts embed file ./document.txt

# With specific model
praisonai-ts embed file ./document.txt --model text-embedding-3-large

# Save embedding
praisonai-ts embed file ./document.txt --save doc-embedding.json

Query Similar Texts

# First, create embeddings file
praisonai-ts embed text "AI is amazing" "Machine learning rocks" "Deep learning is cool" --save corpus.json

# Query for similar texts
praisonai-ts embed query "What is artificial intelligence?" --file corpus.json

List Models

# Show available embedding models
praisonai-ts embed models
Output:
✓ Available Embedding Models

Provider    Model                      Dimensions  Description
───────────────────────────────────────────────────────────────────────────
openai      text-embedding-3-small     1536        Fast, cost-effective
openai      text-embedding-3-large     3072        Higher quality
openai      text-embedding-ada-002     1536        Legacy model
google      text-embedding-004         768         Google embedding
cohere      embed-english-v3.0         1024        Cohere English
cohere      embed-multilingual-v3.0    1024        Cohere Multilingual

Options

OptionShortDescription
--model-mEmbedding model to use
--providerProvider (openai, google, cohere)
--backendBackend (ai-sdk, native, auto)
--saveSave embeddings to file
--fileEmbeddings file for query
--jsonOutput as JSON
--verbose-vVerbose output

Examples

Basic Embedding

$ praisonai-ts embed text "Hello world"

 Embedded 1 text(s)
 Model: text-embedding-3-small
 Backend: AI SDK
 Dimensions: 1536
 Duration: 342ms
 Tokens: 2

JSON Output

$ praisonai-ts embed text "Hello" --json
{
  "success": true,
  "data": {
    "texts": ["Hello"],
    "embeddings": [[0.0123, -0.0456, ...]],
    "dimensions": 1536,
    "count": 1
  },
  "meta": {
    "model": "text-embedding-3-small",
    "backend": "ai-sdk",
    "duration_ms": 342,
    "tokens": 2
  }
}

Batch Embedding with Save

$ praisonai-ts embed text "First document" "Second document" "Third document" --save corpus.json

 Embedded 3 text(s)
 Model: text-embedding-3-small
 Backend: AI SDK
 Dimensions: 1536
 Duration: 523ms
 Saved to: corpus.json
$ praisonai-ts embed query "machine learning" --file corpus.json

 Query: "machine learning"

Top results:
  1. [92.3%] AI and machine learning are transforming industries
  2. [87.1%] Deep learning is a subset of machine learning
  3. [76.4%] Natural language processing uses ML techniques

Force Backend

# Use AI SDK backend
praisonai-ts embed text "Hello" --backend ai-sdk

# Use native OpenAI client
praisonai-ts embed text "Hello" --backend native

Verbose Mode

$ praisonai-ts embed text "Hello" "World" --verbose

 Embedded 2 text(s)
 Model: text-embedding-3-small
 Backend: AI SDK
 Dimensions: 1536
 Duration: 412ms
 Tokens: 4

Embeddings (first 5 values each):
  [0]: [0.0123, -0.0456, 0.0789, -0.0321, 0.0654...]
  [1]: [0.0234, -0.0567, 0.0890, -0.0432, 0.0765...]

Environment Variables

# Required: OpenAI API key
export OPENAI_API_KEY=sk-...

# Optional: Force backend
export PRAISONAI_BACKEND=ai-sdk

# Optional: Default model
export OPENAI_EMBEDDING_MODEL=text-embedding-3-large

Exit Codes

CodeDescription
0Success
1General error
2Invalid arguments

Scripting Examples

Embed and Store

#!/bin/bash
# embed-docs.sh - Embed all text files in a directory

for file in docs/*.txt; do
  praisonai-ts embed file "$file" --save "${file%.txt}.json" --json
done

Build Search Index

#!/bin/bash
# build-index.sh - Build searchable embedding index

# Collect all documents
docs=$(cat docs/*.txt | tr '\n' ' ')

# Embed and save
praisonai-ts embed text "$docs" --save index.json

Query Pipeline

#!/bin/bash
# search.sh - Search documents

query="$1"
praisonai-ts embed query "$query" --file index.json --json | jq '.data.results[0]'