Beginner15 min
getting-startedsetupquickstart
Prerequisites
  • curl and jq (for sample data)

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"

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

Embedding generation runs in the background. Monitor progress:

antfly index list --table wikipedia

Search for articles containing specific terms:

antfly query --table wikipedia \
  --full-text-search 'body:"Korea"' \
  --fields "title,url" \
  --limit 5

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

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
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}'

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

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

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

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.

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

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 judge config): relevance, faithfulness, completeness, coherence, safety, helpfulness, correctness, citation_quality

Next Steps#

  1. Explore the Dashboard — Manage tables, run queries, and monitor your cluster at http://localhost:8080
  2. Image Search with CLIP — Build a full image search application
  3. Browse Models — Discover available embedding, reranking, and generation models with antfly termite list --remote
  4. SDKs — Build applications with Go, TypeScript, Python, or Rust
  5. Backup and Restore — Protect your data
  6. Production Deployment — Deploy on Kubernetes with the Antfly Operator

Additional Resources#

Common questions about this section
  • 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?