Ask from Go
You’ll end with a Go program that asks one yes-or-no question about each of three passages and sorts them by the probability of yes. You need Go 1.27 or later and a key for one provider.
Create a module
Section titled “Create a module”mkdir rank && cd rankgo mod init example.com/rankgo get github.com/deepnoodle-ai/decideWrite the program
Section titled “Write the program”Save this as main.go. It asks whether each passage answers the query,
then reranks the passages with the rank pattern:
// Command rank reranks a retrieved shortlist by asking, for each passage,// whether it answers the query, then sorting by the answers.package main
import ( "context" "fmt" "log"
"github.com/deepnoodle-ai/decide" "github.com/deepnoodle-ai/decide/patterns/rank")
const query = "How do I recover an expired session?"
var shortlist = []string{ "A general account of account access.", "The session recovery procedure: sign in again and resume from the saved draft.", "Refresh tokens rotate when a session is refreshed.",}
func main() { client, err := decide.NewClient() if err != nil { log.Fatal(err) }
var observations []rank.Observation for _, passage := range shortlist { req := decide.NewRequest(map[string]string{"query": query, "passage": passage}) decide.Ask(req, "answers", decide.Noul("Does this passage directly answer the query?")) resp, err := client.SystemOne(context.Background(), req) if err != nil { log.Fatal(err) } o, err := rank.FromResponse(resp, "answers") if err != nil { log.Fatal(err) } observations = append(observations, o) }
// Ties break on the passage text so the order is deterministic. order, err := rank.Rerank(shortlist, observations, func(_ int, passage string) string { return passage }) if err != nil { log.Fatal(err) } for _, e := range order.Entries { fmt.Printf("%.2f %s\n", e.Value, e.Item) }}decide.NewClient reads TYPESAFE_API_KEY. For Clef, GPT-6 Luna, or
Gemini Decision, create the client with backend.NewClient and pass the
key yourself:
client, err := backend.NewClient(backend.Config{ Provider: backend.Cloudflare, // or backend.OpenAI, backend.Gemini APIKey: os.Getenv("CLOUDFLARE_AUTH_TOKEN"), AccountID: os.Getenv("CLOUDFLARE_ACCOUNT_ID"),})The package documentation has every option.
Run it
Section titled “Run it”go run .The passage that answers the query comes first:
0.93 The session recovery procedure: sign in again and resume from the saved draft.0.10 Refresh tokens rotate when a session is refreshed.0.05 A general account of account access.Go further
Section titled “Go further”- Ask several questions in one request with
decide.Ask, and ask a built-in template’s questions with thetemplatespackage. - Ask about an image, PDF, audio clip, or video: attach it with
decide.WithMedia. Jev reads no files yet, so use Clef, GPT-6 Luna, or Gemini Decision. Thebackenddocumentation lists which provider reads which file, and its limits. - Gate an agent’s action, screen in stages, or calibrate a cutoff with
the packages under
patterns/. Each has a short program inexamples/. - Test without a key using fakes from
decidetest.
decide is Apache 2.0. Made by Deep Noodle, after some very hard thinking.