This guide walks you through installing Antfly, loading data, and running your first queries — from full-text search to semantic search to AI-powered RAG.
Install Antfly
brew install --cask antflydb/antfly/antfly
# Verify
antfly --version
Start Antfly
Pull a text embedding model for semantic search. Termite is Antfly's built-in ML inference engine — it runs ONNX-optimized models locally for fast CPU inference, no external APIs needed.
antfly termite pull --variants i8 BAAI/bge-small-en-v1.5
Start Antfly in swarm mode:
antfly swarm 2>&1 | tee "antfly.log"
Swarm mode starts metadata, data nodes, and Termite in a single process — ideal for local development. You can also access the web dashboard at http://localhost:8080 to manage tables, run queries, and monitor your cluster.
Download Sample Data
In a new terminal, download 10,000 Wikipedia articles enriched with thumbnail images:
curl -L -o wiki-articles.json https://cdn.antfly.io/datasets/wiki-articles-10k-v001.json
head -n 1 wiki-articles.json | jq '.'
Each article has title, body, url, and thumbnail_url fields.
Create a Table
Create a table with a text embedding index for semantic search:
antfly table create --table wikipedia \
--index '{
"name": "title_body",
"type": "embeddings",
"template": "{{title}} {{body}}",
"embedder": {
"provider": "termite",
"model": "BAAI/bge-small-en-v1.5"
},
"chunker": {
"provider": "antfly",
"text": {
"target_tokens": 200,
"overlap_tokens": 25
}
}
}'
Verify the table and index were created:
antfly table list
antfly index list --table wikipedia
Load Data
# Load all 10,000 articles using the title as the document ID
antfly load --table wikipedia \
--file wiki-articles.json \
--id-field title
The CLI load command reads a JSON file and batches documents automatically. For SDK usage with large files, see the Batch Operations documentation.
Embedding generation runs in the background. Monitor progress:
antfly index list --table wikipedia
Search
You can run these queries using the CLI (shown below) or the web dashboard at http://localhost:8080.
Full-Text Search
Search for articles containing specific terms:
antfly query --table wikipedia \
--full-text-search 'body:"Korea"' \
--fields "title,url" \
--limit 5
Semantic Search
Find articles semantically similar to a natural language query:
antfly query --table wikipedia \
--semantic-search "anatomy and physiology" \
--indexes "title_body" \
--fields "title,url" \
--limit 5
You've loaded 10,000 documents and run your first full-text and semantic searches. From here, the guide builds on what you have — adding reranking, image search, and RAG.
Hybrid Search & Reranking
Hybrid search combines full-text and semantic search using Reciprocal Rank Fusion (RRF). Adding a reranker further improves relevance by re-scoring results with a cross-encoder model.
Pull the reranker model:
antfly termite pull --variants i8 mixedbread-ai/mxbai-rerank-base-v1
If Antfly doesn't detect the new model, restart antfly swarm.
antfly query --table wikipedia \
--full-text-search 'body:Einstein' \
--semantic-search "theory of relativity and physics" \
--indexes "title_body" \
--fields "title,url" \
--limit 10 \
--reranker '{
"provider": "termite",
"model": "mixedbread-ai/mxbai-rerank-base-v1",
"field": "body"
}' \
--pruner '{"min_score_ratio": 0.01}'
Reranking vs Pruning:
- Reranking uses a cross-encoder model to re-score results based on query-document relevance. It improves ordering but keeps the same number of results.
- Pruning filters out low-relevance results based on score quality. Use
min_score_ratioto keep only results scoring at least N% of the top result, ormax_score_gap_percentto detect "elbows" in score distribution.
Image Search
Search by visual content using CLIP, a multimodal embedding model that understands both text descriptions and images.
Pull the CLIP model
antfly termite pull openai/clip-vit-base-patch32
If Antfly doesn't detect the new model, restart antfly swarm.
Add an image index to your table
Add a CLIP-based index to embed each article's Wikipedia thumbnail:
antfly index create --table wikipedia \
--index thumbnail \
--type embeddings \
--template "{{media url=thumbnail_url}}" \
--embedder '{"provider": "termite", "model": "openai/clip-vit-base-patch32"}' \
--dimension 512
Adding an index to a table with existing data triggers background embedding generation. Articles without a thumbnail_url are skipped. Monitor progress with antfly index list --table wikipedia.
Search by visual content
CLIP understands visual concepts, so you can describe what you're looking for in natural language:
antfly query --table wikipedia \
--semantic-search "map of a country" \
--indexes "thumbnail" \
--fields "title,url,thumbnail_url" \
--limit 5
CLIP responds best to concrete visual descriptions ("red sports car", "mountain landscape") rather than abstract concepts. For a deeper dive, see the Image Search with CLIP example.
RAG (Retrieval-Augmented Generation)
Combine search with LLM-powered classification and generation using the retrieval agent.
Pull a generation model
antfly termite pull hf:onnxruntime/Gemma-3-ONNX
onnxruntime/Gemma-3-ONNX (~4B params, 5.7 GB) runs locally via Termite and supports all RAG features — classification, generation, reasoning, and follow-up questions. For alternative providers, see the next step.
Classify and generate
Use the Gemma model to classify a query and generate an answer from search results:
antfly agents retrieval --table wikipedia \
--semantic-search "What are the major events in Korean history?" \
--indexes "title_body" \
--fields "title,body" \
--limit 5 \
--reranker '{
"provider": "termite",
"model": "mixedbread-ai/mxbai-rerank-base-v1",
"field": "body"
}' \
--pruner '{"min_score_ratio": 0.6, "max_score_gap_percent": 40}' \
--generator '{
"provider": "termite",
"model": "onnxruntime/Gemma-3-ONNX"
}' \
--max-context-tokens 512 \
--classify --reasoning --generate --followup
This command searches for semantically similar articles, reranks and prunes results for quality, classifies the query, generates an answer with reasoning, and suggests follow-up questions — all using the local Gemma model.
Pruning for RAG: Score-based pruning (--pruner) filters out marginally relevant documents, while token-based pruning (--max-context-tokens) ensures the context fits within the model's limits.
RAG with alternative providers
The previous step uses Termite for local inference. You can also use cloud APIs or Ollama:
Requires a Google AI API key. Set the GEMINI_API_KEY environment variable — Antfly picks it up automatically:
export GEMINI_API_KEY="your-api-key-here"
antfly agents retrieval --table wikipedia \
--semantic-search "What are the major events in Korean history?" \
--indexes "title_body" \
--fields "title,body" \
--limit 5 \
--generator '{"provider": "gemini", "model": "gemini-2.5-flash", "api_key": "${GEMINI_API_KEY}"}' \
--max-context-tokens 2048 \
--classify --reasoning --generate --followup
Choosing a generator model:
onnxruntime/Gemma-3-ONNX(~4B params, 5.7 GB) — local ONNX inference via Termite, no API key needed, supports all RAG features- Ollama
gemma3:4b-it-qat— local inference via Ollama, quantized for fast CPU/GPU performance - Gemini
gemini-2.5-flash— cloud API, fast and high quality, requires API key - OpenAI
gpt-4.1-mini— cloud API, fast and high quality, requires API key
Structured output
Add --streaming=false to get structured JSON output with source references instead of streaming text:
antfly agents retrieval --table wikipedia \
--semantic-search "Explain the theory of relativity" \
--indexes "title_body" \
--fields "title,body,url" \
--limit 5 \
--generator '{"provider": "gemini", "model": "gemini-2.5-flash", "api_key": "${GEMINI_API_KEY}"}' \
--streaming=false --generate
Evaluation
Add --eval to score the quality of retrieval and generation:
antfly agents retrieval --table wikipedia \
--semantic-search "What are the major events in Korean history?" \
--indexes "title_body" \
--fields "title,body" \
--limit 5 \
--generator '{"provider": "gemini", "model": "gemini-2.5-flash", "api_key": "${GEMINI_API_KEY}"}' \
--generate \
--eval '{
"evaluators": ["faithfulness", "relevance"],
"judge": {"provider": "gemini", "model": "gemini-3.0-flash", "api_key": "${GEMINI_API_KEY}"}
}'
Available evaluators:
- Retrieval metrics (require
ground_truth.relevant_ids):recall,precision,ndcg,mrr,map - LLM-as-judge metrics (require
judgeconfig):relevance,faithfulness,completeness,coherence,safety,helpfulness,correctness,citation_quality
Next Steps
- Explore the Dashboard — Manage tables, run queries, and monitor your cluster at
http://localhost:8080 - Image Search with CLIP — Build a full image search application
- Browse Models — Discover available embedding, reranking, and generation models with
antfly termite list --remote - SDKs — Build applications with Go, TypeScript, Python, or Rust
- Backup and Restore — Protect your data
- Production Deployment — Deploy on Kubernetes with the Antfly Operator
Additional Resources
- Antfly CLI & REST API Documentation
- Hybrid Search Guide
- Termite Guide — Configure ML inference, embedding providers, and more
- Configuration Reference
- How do I install Antfly?
- How do I create my first table and index?
- How do I load data into Antfly?
- How do I run a search query?
- How do I use RAG with Termite for AI-powered answers?