Skip to content

Commit 482ead2

Browse files
authored
Add reference to the documentation of AI-gears in docs - cherry pick (#882)
1 parent 746b199 commit 482ead2

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

docs/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ RedisAI is a Redis module for executing Deep Learning/Machine Learning models an
77
## Where Next?
88
* The [Introduction](intro.md) is the recommended starting point
99
* The [Quickstart](quickstart.md) page provides information about building, installing and running RedisAI
10-
* The [Commands](commands.md) page is a reference of the RedisAI API
10+
* The [Commands](commands.md) page is a reference of the RedisAI API
11+
* The [RedisGears integration](https://oss.redis.com/redisgears/master/redisai.html) page is a reference of the built-in integration of [RedisGears](https://oss.redis.com/redisgears/) with RedisAI via a Python plugin.
1112
* The [Clients](clients.md) page lists RedisAI clients by programming language
1213
* The [Configuration](configuration.md) page explains how to configure RedisAI
1314
* The [Performance](performance.md) page provides instructions for running benchmarks with RedisAI

docs/intro.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,51 @@ The tensors that were stored under the given INPUTS names can be accessed from t
349349
```
350350
Moreover, it is possible to run 'native' Redis commands from within a TorchScript in RedisAI, and even executing a model in RedisAI. These capabilities enable RedisAI users to run end-to-end processes with their data. Further details and examples can be found under [`AI.SCRIPTEXECUTE` command](commands.md#aiscriptexecute)
351351

352+
## Running AI flows via Python plugin
353+
354+
[RedisGears](https://oss.redis.com/redisgears/) module has a built-in integration with RedisAI via a Python plugin that enables the registration of AI flows, and triggering it upon events.
355+
For example, we can store the following AI flow which sets tensors in Redis and executes `mymodel` over these tensors:
356+
357+
```py
358+
import redisAI
359+
360+
async def ModelRun(record):
361+
tensor_a = redisAI.createTensorFromValues('FLOAT', [2,2], [1.0, 2.0, 3.0, 4.0])
362+
tensor_b = redisAI.createTensorFromValues('FLOAT', [2,2], [2.0, 3.0, 2.0, 3.0])
363+
redisAI.msetTensorsInKeyspace({'a{1}': tensor_a, 'b{1}': tensor_b})
364+
365+
# assuming 'mymodel' is a model stored in Redis
366+
modelRunner = redisAI.createModelRunner('mymodel')
367+
redisAI.modelRunnerAddInput(modelRunner, 'a', tensor_a)
368+
redisAI.modelRunnerAddInput(modelRunner, 'b', tensor_b)
369+
redisAI.modelRunnerAddOutput(modelRunner, 'c')
370+
371+
# run the model asynchronously in RedisAI
372+
res = await redisAI.modelRunnerRunAsync(modelRunner)
373+
redisAI.setTensorInKey('c{1}', res[0])
374+
return "ModelRun_OK"
375+
376+
GB("CommandReader").map(ModelRun).register(trigger="ModelRun")
377+
```
378+
379+
Then, you can trigger this execution and get the results by running:
380+
381+
```
382+
redis> RG.TRIGGER ModelRun
383+
1) "ModelRun_OK"
384+
redis> AI.TENSORGET c{1} VALUES
385+
1) "2"
386+
2) "6"
387+
3) "6"
388+
4) "12"
389+
```
390+
391+
The full reference page for the RedisGears-RedisAI-Python integration which also includes setup instructions and more detailed examples, can be found [here](https://oss.redis.com/redisgears/master/redisai.html).
392+
352393
## Where Next?
353394
This covers the basics of RedisAI's data structures and capabilities. For more information refer to:
354395

355396
* The [Commands page](commands.md) provides a reference of the RedisAI API
397+
* The [RedisGears integration](https://oss.redis.com/redisgears/master/redisai.html) page is a reference of the built-in integration of RedisGears with RedisAI.
356398
* The [Clients page](clients.md) lists RedisAI clients in several programming languages
357399
* The [Examples page](examples.md) showcases several examples that can be extended

docs/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
mkdocs==1.1.2
1+
mkdocs==1.2.3
22
mkdocs-material==6.2.2
33
-e git+https://github.com/RedisLabs/mkdocs-versions-menu.git#egg=mkdocs-versions-menu
44
-e git+https://github.com/RedisLabs/mkdocs-include.git#egg=mkdocs-include

0 commit comments

Comments
 (0)