args = model.getModelSetCommandBytes(key);
250 | return sendCommand(conn, Command.MODEL_SET, args.toArray(new byte[args.size()][]))
251 | .getStatusCodeReply()
252 | .equals("OK");
253 | } catch (JedisDataException ex) {
254 | throw new RedisAIException(ex);
255 | }
256 | }
257 |
258 | /**
259 | * Direct mapping to AI.MODELSTORE command.
260 | *
261 | * {@code AI.MODELSTORE [TAG tag] [BATCHSIZE n [MINBATCHSIZE m]]
262 | * [INPUTS ...] [OUTPUTS ...] BLOB }
263 | *
264 | * @param key name of key to store the Model
265 | * @param model Model object
266 | * @return true if Model was properly stored in RedisAI server
267 | */
268 | public boolean storeModel(String key, Model model) {
269 | try (Jedis conn = getConnection()) {
270 | List args = model.getModelStoreCommandArgs(key);
271 | return sendCommand(conn, Command.MODEL_STORE, args.toArray(new byte[args.size()][]))
272 | .getStatusCodeReply()
273 | .equals("OK");
274 | } catch (JedisDataException ex) {
275 | throw new RedisAIException(ex.getMessage(), ex);
276 | }
277 | }
278 |
279 | /**
280 | * Direct mapping to AI.MODELGET
281 | *
282 | * @param key name of key to get the Model from RedisAI server
283 | * @return Model
284 | * @throws JRedisAIRunTimeException
285 | */
286 | public Model getModel(String key) {
287 | try (Jedis conn = getConnection()) {
288 | List> reply =
289 | sendCommand(
290 | conn,
291 | Command.MODEL_GET,
292 | SafeEncoder.encode(key),
293 | Keyword.META.getRaw(),
294 | Keyword.BLOB.getRaw())
295 | .getObjectMultiBulkReply();
296 | if (reply.isEmpty()) {
297 | return null;
298 | }
299 | return Model.createModelFromRespReply(reply);
300 | }
301 | }
302 |
303 | /**
304 | * Direct mapping to AI.MODELDEL
305 | *
306 | * @param key name of key to delete the Model
307 | * @return true if Model was properly delete in RedisAI server
308 | */
309 | public boolean delModel(String key) {
310 |
311 | try (Jedis conn = getConnection()) {
312 | return sendCommand(conn, Command.MODEL_DEL, SafeEncoder.encode(key))
313 | .getStatusCodeReply()
314 | .equals("OK");
315 | } catch (JedisDataException ex) {
316 | throw new RedisAIException(ex);
317 | }
318 | }
319 |
320 | /**
321 | * Direct mapping to AI.SCRIPTSET
322 | *
323 | * @param key name of key to store the Script in RedisAI server
324 | * @param device - the device that will execute the model. can be of CPU or GPU
325 | * @param scriptFile - the file path for the script source code
326 | * @return true if Script was properly set in RedisAI server
327 | */
328 | public boolean setScriptFile(String key, Device device, String scriptFile) {
329 | try {
330 | Script script = new Script(device, Paths.get(scriptFile));
331 | return setScript(key, script);
332 | } catch (IOException ex) {
333 | throw new RedisAIException(ex);
334 | }
335 | }
336 |
337 | /**
338 | * Direct mapping to AI.SCRIPTSET
339 | *
340 | * @param key name of key to store the Script in RedisAI server
341 | * @param device - the device that will execute the model. can be of CPU or GPU
342 | * @param source - the script source code
343 | * @return true if Script was properly set in RedisAI server
344 | */
345 | public boolean setScript(String key, Device device, String source) {
346 | Script script = new Script(device, source);
347 | return setScript(key, script);
348 | }
349 |
350 | /**
351 | * Direct mapping to AI.SCRIPTSET
352 | *
353 | * @param key name of key to store the Script in RedisAI server
354 | * @param script the Script Object
355 | * @return true if Script was properly set in RedisAI server
356 | */
357 | public boolean setScript(String key, Script script) {
358 | try (Jedis conn = getConnection()) {
359 | List args = script.getScriptSetCommandBytes(key);
360 | return sendCommand(conn, Command.SCRIPT_SET, args.toArray(new byte[args.size()][]))
361 | .getStatusCodeReply()
362 | .equals("OK");
363 |
364 | } catch (JedisDataException ex) {
365 | throw new RedisAIException(ex);
366 | }
367 | }
368 |
369 | /**
370 | * Direct mapping to AI.MODELSTORE command.
371 | *
372 | * {@code AI.SCRIPTSTORE [TAG tag] ENTRY_POINTS
373 | * [...] SOURCE "