You've already forked node-redis
mirror of
https://github.com/redis/node-redis.git
synced 2025-08-06 02:15:48 +03:00
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
This commit is contained in:
committed by
GitHub
parent
b52177752e
commit
c5b4f47975
36
packages/client/lib/commands/VSIM_WITHSCORES.ts
Normal file
36
packages/client/lib/commands/VSIM_WITHSCORES.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import {
|
||||
ArrayReply,
|
||||
BlobStringReply,
|
||||
Command,
|
||||
DoubleReply,
|
||||
MapReply,
|
||||
UnwrapReply
|
||||
} from '../RESP/types';
|
||||
import { transformDoubleReply } from './generic-transformers';
|
||||
import VSIM from './VSIM';
|
||||
|
||||
export default {
|
||||
IS_READ_ONLY: VSIM.IS_READ_ONLY,
|
||||
/**
|
||||
* Retrieve elements similar to a given vector or element with similarity scores
|
||||
* @param args - Same parameters as the VSIM command
|
||||
* @see https://redis.io/commands/vsim/
|
||||
*/
|
||||
parseCommand(...args: Parameters<typeof VSIM.parseCommand>) {
|
||||
const parser = args[0];
|
||||
|
||||
VSIM.parseCommand(...args);
|
||||
parser.push('WITHSCORES');
|
||||
},
|
||||
transformReply: {
|
||||
2: (reply: ArrayReply<BlobStringReply>) => {
|
||||
const inferred = reply as unknown as UnwrapReply<typeof reply>;
|
||||
const members: Record<string, DoubleReply> = {};
|
||||
for (let i = 0; i < inferred.length; i += 2) {
|
||||
members[inferred[i].toString()] = transformDoubleReply[2](inferred[i + 1]);
|
||||
}
|
||||
return members;
|
||||
},
|
||||
3: undefined as unknown as () => MapReply<BlobStringReply, DoubleReply>
|
||||
}
|
||||
} as const satisfies Command;
|
Reference in New Issue
Block a user