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”Terminal window mkdir rank && cd rankgo mod init example.com/rankgo get github.com/deepnoodle-ai/decide -
Write 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 therankpattern:main.go // Command rank reranks a retrieved shortlist by asking, for each passage,// whether it answers the query, then sorting by the answers.package mainimport ("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.Observationfor _, 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.NewClientreadsTYPESAFE_API_KEY. For Clef or GPT-6 Luna, create the client withbackend.NewClient, as the package documentation shows. The rest of the program stays the same. -
Run it
Section titled “Run it”Terminal window go run .The passage that answers the query comes first, with the highest probability of yes:
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.Your probabilities may differ a little.
-
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. - 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.
- Ask several questions in one request with
decide is open source under Apache 2.0.Made by Deep Noodle