Local-first Retrieval-Augmented Generation CLI for personal documentation.
RAG CLI allows you to index your markdown, text, and PDF files and perform semantic search using vector embeddings. All embeddings are generated locally using @xenova/transformers - no API keys required.
Watch a quick demo of RAG CLI in action:
- ✅ Index markdown, text, and PDF files
- ✅ Local embedding generation (all-MiniLM-L6-v2, 384 dimensions)
- ✅ Vector storage with Upstash Vector DB
- ✅ Incremental indexing (only re-index changed files)
- ✅ File hashing for change detection
- ✅ Semantic search with vector similarity
- ✅ AI-powered answers with local Ollama LLM
- ✅ Streaming output support
- ✅ Clear all index data
- Node.js 18+
- npm or yarn
- Ollama (for AI-powered answers)
- Clone the repository:
git clone <repository-url>
cd rag-cli- Install dependencies:
npm install- Initialize RAG CLI configuration:
npm run dev -- initThis will create ~/.rag/.env with your configuration. Edit it with your Upstash credentials:
UPSTASH_VECTOR_REST_URL=https://your-upstash-url.upstash.io
UPSTASH_VECTOR_REST_TOKEN=your-upstash-token- Install and configure Ollama (for AI-powered answers):
# Install Ollama (macOS)
brew install ollama
# Install Ollama (Linux)
curl -fsSL https://ollama.com/install.sh | sh
# Pull the default model
ollama pull qwen2.5:3b
# Start Ollama server
ollama serve- Go to Upstash Console
- Create a new Vector index with:
- Dimensions: 384
- Metric: DOT_PRODUCT or COSINE
- Embedding Model: any 384-dim model (e.g., BAAI/bge-small-en-v1.5)
- Copy the REST URL and token to your
.envfile
First, build the project and link it globally:
npm run build
npm linkAfter linking, you can use the rag command from anywhere on your system.
For development without rebuilding, use npm run dev:
npm run dev -- <command>Examples:
npm run dev -- init
npm run dev -- add README.md
npm run dev -- "how do I index files?"
npm run dev -- ask "what are the features?"Set up RAG CLI configuration in your home directory:
rag initThis command will:
- Create
~/.rag/directory for global data storage - Copy
.envfrom current directory or use.env.exampleas template - Create
~/.rag/.envwith your configuration - Provide next steps for setup
After running init, edit ~/.rag/.env to add your Upstash credentials.
Index files or directories:
# Index a single file (use README.md for testing to learn about RAG CLI)
rag add README.md
# Index a directory
rag add ./docs
# Index multiple paths
rag add ./docs ./notes/auth.mdThe command will:
- Scan for supported files (.md, .txt, .pdf)
- Parse file content
- Chunk text into 1000-character segments with 150-character overlap
- Generate embeddings locally using all-MiniLM-L6-v2
- Store vectors in Upstash Vector DB
- Track file hashes for incremental indexing
View indexing statistics:
rag statusOutput:
RAG Status
==========
Files Indexed: 5
Chunks Stored: 42
Embedding Model: all-MiniLM-L6-v2
Vector DB: Upstash Vector
LLM Model: qwen2.5:3b
Last Indexed: 2026-05-22T05:59:28.808Z
Total Size: 12.5 KB
Document Paths: 5
Clear all index data to start fresh:
# Show warning and require confirmation
rag clear
# Clear without confirmation
rag clear --forceThe command will:
- Delete
.rag/index.jsonand.rag/hashes.json - Remove
.ragdirectory if empty - Delete all vectors from Upstash Vector DB
- Reset all indexing statistics
Search for relevant document chunks and get AI-powered answers:
# Quick ask (shortcut - no 'ask' keyword needed)
rag "how do I index files?"
# Ask with explicit command
rag ask "how do I index files?"
# Ask without streaming
rag ask "what are the features?" --no-stream
# Ask without LLM (chunk-only mode)
rag ask "how do I index files?" --no-llm
# Customize number of chunks to retrieve
rag ask "what are the features?" --top-k 10The command will:
- Generate embedding for your query
- Perform vector similarity search in Upstash
- Retrieve the most relevant chunks
- Build a RAG prompt with context
- Generate an AI answer using local Ollama
- Display the answer with source references
Required:
UPSTASH_VECTOR_REST_URL- Your Upstash Vector REST URLUPSTASH_VECTOR_REST_TOKEN- Your Upstash Vector REST token
Optional:
OLLAMA_URL- Ollama server URL (default: http://localhost:11434)EMBEDDING_MODEL- Embedding model (default: all-MiniLM-L6-v2)LLM_MODEL- LLM model (default: qwen2.5:3b)CHUNK_SIZE- Chunk size in characters (default: 1000)CHUNK_OVERLAP- Chunk overlap in characters (default: 150)SEARCH_TOP_K- Number of search results (default: 5)LOG_LEVEL- Logging level (default: info)
The CLI creates a .rag/ directory in your home directory (~/.rag/) for:
index.json- Index metadata (file counts, chunk counts, timestamps)hashes.json- File hash tracking for incremental indexing.env- Environment configuration (created byrag init)cache/- Optional embedding cache
This allows the CLI to work from any directory on your system.
npm testnpm run type-checknpm run lintnpm run formatnpm run buildLink the package globally to use rag command directly:
npm linkAfter linking, initialize and use commands directly:
rag init
rag add README.md
rag status
rag ask "what are the features?"
rag clear --forceTo unlink:
npm unlink -g rag- File scanning and parsing
- Markdown, text, and PDF support
- File hashing for change detection
- Local storage management
- Text chunking with LangChain
- Local embedding generation (@xenova/transformers)
- Upstash Vector DB integration
- Incremental indexing
- Query embedding generation
- Vector similarity search
- Chunk retrieval with metadata
- Ollama API client
- RAG prompt construction
- AI answer generation
- Streaming output (default behavior)
- Graceful fallback when Ollama unavailable
- Enhanced status command with table formatting
- CLI UI utilities (colors, spinner, table)
- Improved error messages and graceful fallbacks
- Integration tests for all commands
- 79% test coverage
- ESLint and Prettier configured
- Runtime: Node.js 18+
- Language: TypeScript (strict mode)
- CLI Framework: commander.js
- Embeddings: @xenova/transformers (local)
- Vector DB: Upstash Vector
- Text Chunking: LangChain
- File Parsing: markdown-it, pdfjs-dist
- Testing: Jest
This error occurs when your Upstash index dimension doesn't match the embedding model dimension.
Solution: Ensure your Upstash index is configured with:
- Dimensions: 384 (for all-MiniLM-L6-v2)
- Metric: DOT_PRODUCT or COSINE
Solution: Ensure you have set UPSTASH_VECTOR_REST_URL and UPSTASH_VECTOR_REST_TOKEN in your .env file.
This warning appears when Ollama is not running or not installed.
Solution:
- Install Ollama:
brew install ollama(macOS) orcurl -fsSL https://ollama.com/install.sh | sh(Linux) - Pull the model:
ollama pull qwen2.5:3b - Start the server:
ollama serve - Use
--no-llmflag to skip LLM and only show chunks
This is normal behavior - the CLI uses file hashing to skip unchanged files. To force re-index:
rm ~/.rag/hashes.json
rag add ./your-filesMIT
See CONTRIBUTING.md for development guidelines.
