redisai / redisai-js Goto Github PK
View Code? Open in Web Editor NEWA high-performance JavaScript client for RedisAI
Home Page: https://redisai.io
License: BSD 3-Clause "New" or "Revised" License
A high-performance JavaScript client for RedisAI
Home Page: https://redisai.io
License: BSD 3-Clause "New" or "Revised" License
I have been using redisai-py for a while. Now I am starting to integrate use of redisai into my website with redisai-js.
I am using typescript and ts-node in development. Below is the code I added following the example and the error I received.
import redis from "redis";
import redisai from "redisai-js";
(async () => {
const nativeClient = redis.createClient({ url: "redis://redis:6379" });
const rai = new redisai.Client(nativeClient );
})();
Error: Cannot find module './backend'
Require stack:
- /app/node_modules/redisai-js/lib/index.js
- /app/src/index.ts
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
at Function.Module._load (internal/modules/cjs/loader.js:725:27)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/app/node_modules/redisai-js/src/index.ts:2:1)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Object.require.extensions.<computed> [as .js] (/app/node_modules/ts-node/src/index.ts:851:44)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
[nodemon] app crashed - waiting for file changes before starting...
I'm getting a syntax error doing the simplest of things:
$ npm install --save redisai-js
I copy and paste the Vanilla JS tensor example from the README.md into a file named redisai-js.js
. And then I run it:
$ node redisai-js.js
And it gives me this error:
/Users/guyroyse/code/redis-modules-assessment/node_modules/redisai-js/lib/tensor.js:49
});
^
SyntaxError: Unexpected token '}'
at wrapSafe (internal/modules/cjs/loader.js:931:16)
at Module._compile (internal/modules/cjs/loader.js:979:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Module.require (internal/modules/cjs/loader.js:903:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/Users/guyroyse/code/redis-modules-assessment/node_modules/redisai-js/lib/index.js:10:16)
at Module._compile (internal/modules/cjs/loader.js:1015:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
I pulled the repo down myself, built everything, and npm installed the folder on my machine and it worked. Seems like something wrong with our npm depoly? Maybe?
As a Node.js developer i'm using the redisai-js module to connect with Redis-Ai with my node.js application. So i'm using / save / load my models in TensorflowJs format (model.json, weights.bin) so its useful create the Redis-Ai model getting start from these two files saved. Actually the code i'm used doesn't work because the model format:
const m = await tf.loadLayersModel(`file://model/AX-model/model.json`)
const myModel = new redisai.Model(redisai.Backend.TF, 'CPU',['a','b'], ['c'], m)
const r = await aiclient.modelset('mlmodel', myModel)
So i'm interesting to thinking at a solution, in node.js application i'm struggle to use Redis to save the TensorflowJs models too directly in-memory db. I'd like to chose which operation get done in Node.js application and which in Redis-Ai, so for example train the model in Node.js application and predict in Redis-Ai:
const model = tf.sequential()
model.add(tf.layers.dense({inputShape: [1], units: 1}))
model.add(tf.layers.dense({units: 1}))
model.compile({
optimizer: 'sgd', // tf.train.adam(),
// loss: tf.losses.meanSquaredError,
loss: 'meanSquaredError',
metrics: ['mse']
})
const myModel = new redisai.Model(redisai.Backend.TF, 'CPU',['a','b'], ['c'], model)
const r = await aiclient.modelset('mlmodel', myModel)
adjust to 1.2.5
further reference: https://oss.redislabs.com/redisai/commands/#aimodelget
Further reference:
https://oss.redislabs.com/redisai/master/commands/#aiscriptrun
Example on how provide an arbitrary number of inputs after the $ sign::
redis> AI.TENSORSET mytensor1 FLOAT 1 VALUES 40
OK
redis> AI.TENSORSET mytensor2 FLOAT 1 VALUES 1
OK
redis> AI.TENSORSET mytensor3 FLOAT 1 VALUES 1
OK
redis> AI.SCRIPTRUN myscript addn INPUTS mytensor1 $ mytensor2 mytensor3 OUTPUTS result
OK
redis> AI.TENSORGET result VALUES
1) FLOAT
2) 1) (integer) 1
3) 1) "42"
Since Redis supports strings up to 512MB, blobs for very large models need to be chunked.
Further reference here: https://oss.redislabs.com/redisai/commands/#aimodelset
adjust to 1.2.5
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.