Rewrite it in Rust version of LEANN - Lightweight vector database for RAG
Rust
1
6 commits
updated Feb 17, 2026
"Rewrite it in Rust" version of LEANN - Lightweight Embedding-based Approximate Nearest Neighbor search.
A single-binary CLI for building, searching, and querying vector indexes for RAG applications. No Python runtime required.
# Build from source
cargo build --release
# Binary at target/release/leann (~4MB)
# Build an index from documents
leann build my-docs --docs ./documents --embedding-mode ollama --embedding-model nomic-embed-text
# Search
leann search my-docs "How does authentication work?"
# Ask questions (RAG)
leann ask my-docs "Explain the architecture" --llm ollama --model qwen3:8b
# Interactive mode
leann ask my-docs --interactive
# Basic build with OpenAI embeddings
leann build my-docs --docs ./documents
# Use Ollama for local embeddings
leann build my-docs --docs ./documents --embedding-mode ollama --embedding-model nomic-embed-text
# Custom options
leann build my-code --docs ./src \
--file-types ".rs,.py,.ts" \
--doc-chunk-size 512 \
--graph-degree 48
# Basic search
leann search my-docs "vector database"
# With metadata filtering
leann search my-docs "authentication" -f "source:*.rs"
# Hybrid search (vector + BM25)
leann search my-docs "user login" --hybrid
# JSON output
leann search my-docs "query" --format json
# Single question
leann ask my-docs "How does caching work?"
# Use different LLM providers
leann ask my-docs "question" --llm openai --model gpt-4o
leann ask my-docs "question" --llm anthropic --model claude-3-5-sonnet-20241022
leann ask my-docs "question" --llm ollama --model qwen3:8b
# Interactive chat
leann ask my-docs --interactive
Multi-turn reasoning with search tool:
leann react my-docs "What are all the ways errors are handled?"
# Show reasoning trace
leann react my-docs "Compare feature X and Y" --verbose --max-steps 10
# Start server
leann serve my-docs --port 8080 --cors
# API endpoints:
# POST /search - Search the index
# GET /info - Index information
# GET /health - Health check
# List all indexes
leann list
# Detailed info
leann list --detailed
# Remove an index
leann remove my-docs
# Build with PDF support
cargo build --release --features pdf
# Build with HTTP server
cargo build --release --features server
# Build with DiskANN backend
cargo build --release --features diskann-backend
# Build with all features
cargo build --release --features full
Filter by document metadata:
# By file extension
leann search my-docs "query" -f "source:*.rs"
# By type
leann search my-docs "query" -f "type=code"
# Numeric comparison
leann search my-docs "query" -f "lines>100"
Supported operators: =, !=, >, >=, <, <=, : (glob patterns)
Combine vector similarity with BM25 keyword matching:
leann search my-docs "exact function name" --hybrid --hybrid-alpha 0.5
Alpha controls the balance: 1.0 = pure vector, 0.0 = pure BM25.
LEANN-RS reads Python LEANN indexes:
.passages.jsonl - Text passages.passages.idx.json - JSON offset map.index - Vector index (usearch format).meta.json - Metadata.ids.txt - ID mapping| Variable | Description |
|---|---|
OPENAI_API_KEY | OpenAI API key |
OPENAI_BASE_URL | Custom OpenAI-compatible URL |
ANTHROPIC_API_KEY | Anthropic/Claude API key |
OLLAMA_HOST | Ollama server URL (default: http://localhost:11434) |
| Build | Size |
|---|---|
| Default | ~4 MB |
| ~5 MB | |
| + Server | ~5 MB |
| + DiskANN | ~6 MB |
| Full | ~8 MB |
src/
├── cli/ # Commands (build, search, ask, react, serve)
├── index/ # Index management, BM25, filtering
├── backend/ # HNSW (usearch), DiskANN
├── embedding/ # OpenAI, Ollama providers
└── llm/ # OpenAI, Ollama, Anthropic
MIT
6 commits
Rust
100.0%
Rewrite it in Rust version of LEANN - Lightweight vector database for RAG
Rust
1
6 commits
updated Feb 17, 2026
"Rewrite it in Rust" version of LEANN - Lightweight Embedding-based Approximate Nearest Neighbor search.
A single-binary CLI for building, searching, and querying vector indexes for RAG applications. No Python runtime required.
# Build from source
cargo build --release
# Binary at target/release/leann (~4MB)
# Build an index from documents
leann build my-docs --docs ./documents --embedding-mode ollama --embedding-model nomic-embed-text
# Search
leann search my-docs "How does authentication work?"
# Ask questions (RAG)
leann ask my-docs "Explain the architecture" --llm ollama --model qwen3:8b
# Interactive mode
leann ask my-docs --interactive
# Basic build with OpenAI embeddings
leann build my-docs --docs ./documents
# Use Ollama for local embeddings
leann build my-docs --docs ./documents --embedding-mode ollama --embedding-model nomic-embed-text
# Custom options
leann build my-code --docs ./src \
--file-types ".rs,.py,.ts" \
--doc-chunk-size 512 \
--graph-degree 48
# Basic search
leann search my-docs "vector database"
# With metadata filtering
leann search my-docs "authentication" -f "source:*.rs"
# Hybrid search (vector + BM25)
leann search my-docs "user login" --hybrid
# JSON output
leann search my-docs "query" --format json
# Single question
leann ask my-docs "How does caching work?"
# Use different LLM providers
leann ask my-docs "question" --llm openai --model gpt-4o
leann ask my-docs "question" --llm anthropic --model claude-3-5-sonnet-20241022
leann ask my-docs "question" --llm ollama --model qwen3:8b
# Interactive chat
leann ask my-docs --interactive
Multi-turn reasoning with search tool:
leann react my-docs "What are all the ways errors are handled?"
# Show reasoning trace
leann react my-docs "Compare feature X and Y" --verbose --max-steps 10
# Start server
leann serve my-docs --port 8080 --cors
# API endpoints:
# POST /search - Search the index
# GET /info - Index information
# GET /health - Health check
# List all indexes
leann list
# Detailed info
leann list --detailed
# Remove an index
leann remove my-docs
# Build with PDF support
cargo build --release --features pdf
# Build with HTTP server
cargo build --release --features server
# Build with DiskANN backend
cargo build --release --features diskann-backend
# Build with all features
cargo build --release --features full
Filter by document metadata:
# By file extension
leann search my-docs "query" -f "source:*.rs"
# By type
leann search my-docs "query" -f "type=code"
# Numeric comparison
leann search my-docs "query" -f "lines>100"
Supported operators: =, !=, >, >=, <, <=, : (glob patterns)
Combine vector similarity with BM25 keyword matching:
leann search my-docs "exact function name" --hybrid --hybrid-alpha 0.5
Alpha controls the balance: 1.0 = pure vector, 0.0 = pure BM25.
LEANN-RS reads Python LEANN indexes:
.passages.jsonl - Text passages.passages.idx.json - JSON offset map.index - Vector index (usearch format).meta.json - Metadata.ids.txt - ID mapping| Variable | Description |
|---|---|
OPENAI_API_KEY | OpenAI API key |
OPENAI_BASE_URL | Custom OpenAI-compatible URL |
ANTHROPIC_API_KEY | Anthropic/Claude API key |
OLLAMA_HOST | Ollama server URL (default: http://localhost:11434) |
| Build | Size |
|---|---|
| Default | ~4 MB |
| ~5 MB | |
| + Server | ~5 MB |
| + DiskANN | ~6 MB |
| Full | ~8 MB |
src/
├── cli/ # Commands (build, search, ask, react, serve)
├── index/ # Index management, BM25, filtering
├── backend/ # HNSW (usearch), DiskANN
├── embedding/ # OpenAI, Ollama providers
└── llm/ # OpenAI, Ollama, Anthropic
MIT
6 commits
Rust
100.0%