SDKs#

Antfly Inference is available through the unified Antfly SDKs for Go and TypeScript. Antfly Inference also exposes an Ollama-compatible /ai/v1/embed endpoint, so any Ollama client library works for embedding generation.

LanguagePackageRegistrySource
Gogithub.com/antflydb/antfly/go/pkg/sdkpkg.go.devGitHub
TypeScript@antfly/sdknpmGitHub

Installation#

go get github.com/antflydb/antfly/go/pkg/sdk

Quick Start#

Generate Embeddings#

import (
	"context"
	"net/http"

	"github.com/antflydb/antfly/go/pkg/sdk"
)

c, err := sdk.NewAntfly InferenceClient("http://localhost:8080", &http.Client{})
if err != nil {
	log.Fatal(err)
}

embeddings, err := c.Embed(
	context.Background(),
	"bge-small-en-v1.5",
	[]string{"hello world", "semantic search"},
)
if err != nil {
	log.Fatal(err)
}

// embeddings is [][]float32
fmt.Printf("dimensions: %d\n", len(embeddings[0]))

Chunk Text#

// Use the Antfly Inference HTTP API directly for chunking
import "net/http"

req, _ := http.NewRequest("POST", "http://localhost:8080/ai/v1/chunk", strings.NewReader(`{
	"text": "Your long document text goes here...",
	"config": {
		"model": "fixed",
		"target_tokens": 500
	}
}`))
req.Header.Set("Content-Type", "application/json")

resp, err := http.DefaultClient.Do(req)

Rerank Results#

// Use the Antfly Inference HTTP API directly for reranking
import "net/http"

req, _ := http.NewRequest("POST", "http://localhost:8080/ai/v1/rerank", strings.NewReader(`{
	"model": "bge-reranker-v2-m3",
	"query": "what is semantic search?",
	"documents": [
		"Semantic search uses embeddings to find relevant results.",
		"Keyword search matches exact terms in documents.",
		"Vector databases store high-dimensional embeddings."
	]
}`))
req.Header.Set("Content-Type", "application/json")

resp, err := http.DefaultClient.Do(req)

Ollama Compatibility#

Antfly Inference implements the Ollama /ai/v1/embed endpoint, so any Ollama client library can generate embeddings from Antfly Inference. This is useful if you already use Ollama in your stack and want to swap in Antfly Inference for ONNX-based inference.

# Works with the Ollama API format
curl -X POST http://localhost:8080/ai/v1/embed \
  -H "Content-Type: application/json" \
  -d '{"model": "bge-small-en-v1.5", "input": ["hello world"]}'

See the API Reference for the full list of endpoints.