1
0
mirror of https://github.com/redis/node-redis.git synced 2025-08-03 04:01:40 +03:00
Files
Nikolay Karadzhov c5b4f47975 feat: add support for vector sets (#2998)
* wip

* improve the vadd api

* resp3 tests

* fix some tests

* extract json helper functions in client package

* use transformJsonReply

* remove the CACHEABLE flag for all vector set commands

currently, client side caching is not supported
for vector set commands by the server

* properly transform vinfo result

* add resp3 test for vlinks

* add more tests for vrandmember

* fix vrem return types

* fix vsetattr return type

* fix vsim_withscores

* implement vlinks_withscores

* set minimum docker image version to 8

* align return types

* add RAW variant for VEMB -> VEMB_RAW

* use the new parseCommand api
2025-06-24 13:35:29 +03:00

66 lines
1.7 KiB
TypeScript

import { CommandParser } from '../client/parser';
import { RedisArgument, Command } from '../RESP/types';
import { transformBooleanReply, transformDoubleArgument } from './generic-transformers';
export interface VAddOptions {
REDUCE?: number;
CAS?: boolean;
QUANT?: 'NOQUANT' | 'BIN' | 'Q8',
EF?: number;
SETATTR?: Record<string, any>;
M?: number;
}
export default {
/**
* Add a new element into the vector set specified by key
*
* @param parser - The command parser
* @param key - The name of the key that will hold the vector set data
* @param vector - The vector data as array of numbers
* @param element - The name of the element being added to the vector set
* @param options - Optional parameters for vector addition
* @see https://redis.io/commands/vadd/
*/
parseCommand(
parser: CommandParser,
key: RedisArgument,
vector: Array<number>,
element: RedisArgument,
options?: VAddOptions
) {
parser.push('VADD');
parser.pushKey(key);
if (options?.REDUCE !== undefined) {
parser.push('REDUCE', options.REDUCE.toString());
}
parser.push('VALUES', vector.length.toString());
for (const value of vector) {
parser.push(transformDoubleArgument(value));
}
parser.push(element);
if (options?.CAS) {
parser.push('CAS');
}
options?.QUANT && parser.push(options.QUANT);
if (options?.EF !== undefined) {
parser.push('EF', options.EF.toString());
}
if (options?.SETATTR) {
parser.push('SETATTR', JSON.stringify(options.SETATTR));
}
if (options?.M !== undefined) {
parser.push('M', options.M.toString());
}
},
transformReply: transformBooleanReply
} as const satisfies Command;