Go client for RedisAI, based on redigo.
go get github.com/RedisAI/redisai-go/redisai
Command | Recommended API and godoc |
---|---|
AI.TENSORSET | TensorSet and TensorSetFromTensor |
AI.TENSORGET | TensorGet and TensorGetToTensor |
AI.MODELSET | ModelSet and ModelSetFromModel |
AI.MODELGET | ModelGet and ModelGetToModel |
AI.MODELDEL | ModelDel |
AI.MODELRUN | ModelRun |
AI._MODELSCAN | |
AI.SCRIPTSET | ScriptSet |
AI.SCRIPTGET | ScriptGet |
AI.SCRIPTDEL | ScriptDel |
AI.SCRIPTRUN | ScriptRun |
AI._SCRIPTSCAN | |
AI.DAGRUN | DagRun |
AI.DAGRUN_RO | DagRunRO |
AI.INFO | Info |
AI.CONFIG * | LoadBackend |
See the examples folder for further feature samples:
package main
import (
"fmt"
"github.com/RedisAI/redisai-go/redisai"
"log"
)
func main() {
// Create a client.
client := redisai.Connect("redis://localhost:6379", nil)
// Set a tensor
// AI.TENSORSET foo FLOAT 2 2 VALUES 1.1 2.2 3.3 4.4
_ = client.TensorSet("foo", redisai.TypeFloat, []int64{2, 2}, []float32{1.1, 2.2, 3.3, 4.4})
// Get a tensor content as a slice of values
// dt DataType, shape []int, data interface{}, err error
// AI.TENSORGET foo VALUES
_, _, fooTensorValues, err := client.TensorGetValues("foo")
if err != nil {
log.Fatal(err)
}
fmt.Println(fooTensorValues)
// Output: [1.1 2.2 3.3 4.4]
}
package main
import (
"fmt"
"github.com/RedisAI/redisai-go/redisai"
"log"
)
func main() {
// Create a client.
client := redisai.Connect("redis://localhost:6379", nil)
// Enable pipeline of commands on the client.
client.Pipeline(3)
// Set a tensor
// AI.TENSORSET foo FLOAT 2 2 VALUES 1.1 2.2 3.3 4.4
err := client.TensorSet("foo1", redisai.TypeFloat, []int64{2, 2}, []float32{1.1, 2.2, 3.3, 4.4})
if err != nil {
log.Fatal(err)
}
// AI.TENSORSET foo2 FLOAT 1" 1 VALUES 1.1
err = client.TensorSet("foo2", redisai.TypeFloat, []int64{1, 1}, []float32{1.1})
if err != nil {
log.Fatal(err)
}
// AI.TENSORGET foo2 META
_, err = client.TensorGet("foo2", redisai.TensorContentTypeMeta)
if err != nil {
log.Fatal(err)
}
// Ignore the AI.TENSORSET Reply
_, err = client.Receive()
if err != nil {
log.Fatal(err)
}
// Ignore the AI.TENSORSET Reply
_, err = client.Receive()
if err != nil {
log.Fatal(err)
}
foo2TensorMeta, err := client.Receive()
if err != nil {
log.Fatal(err)
}
fmt.Println(foo2TensorMeta)
// Output: [FLOAT [1 1]]
}