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
42
packages/client/lib/commands/VLINKS_WITHSCORES.ts
Normal file
42
packages/client/lib/commands/VLINKS_WITHSCORES.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { BlobStringReply, Command, DoubleReply, MapReply } from '../RESP/types';
|
||||
import { transformDoubleReply } from './generic-transformers';
|
||||
import VLINKS from './VLINKS';
|
||||
|
||||
|
||||
function transformVLinksWithScoresReply(reply: any): Array<Record<string, DoubleReply>> {
|
||||
const layers: Array<Record<string, DoubleReply>> = [];
|
||||
|
||||
for (const layer of reply) {
|
||||
const obj: Record<string, DoubleReply> = Object.create(null);
|
||||
|
||||
// Each layer contains alternating element names and scores
|
||||
for (let i = 0; i < layer.length; i += 2) {
|
||||
const element = layer[i];
|
||||
const score = transformDoubleReply[2](layer[i + 1]);
|
||||
obj[element.toString()] = score;
|
||||
}
|
||||
|
||||
layers.push(obj);
|
||||
}
|
||||
|
||||
return layers;
|
||||
}
|
||||
|
||||
export default {
|
||||
IS_READ_ONLY: VLINKS.IS_READ_ONLY,
|
||||
/**
|
||||
* Get the connections for each layer of the HNSW graph with similarity scores
|
||||
* @param args - Same parameters as the VLINKS command
|
||||
* @see https://redis.io/commands/vlinks/
|
||||
*/
|
||||
parseCommand(...args: Parameters<typeof VLINKS.parseCommand>) {
|
||||
const parser = args[0];
|
||||
|
||||
VLINKS.parseCommand(...args);
|
||||
parser.push('WITHSCORES');
|
||||
},
|
||||
transformReply: {
|
||||
2: transformVLinksWithScoresReply,
|
||||
3: undefined as unknown as () => Array<MapReply<BlobStringReply, DoubleReply>>
|
||||
}
|
||||
} as const satisfies Command;
|
Reference in New Issue
Block a user