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
68
packages/client/lib/commands/VSIM.ts
Normal file
68
packages/client/lib/commands/VSIM.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { CommandParser } from '../client/parser';
|
||||
import { RedisArgument, ArrayReply, BlobStringReply, Command } from '../RESP/types';
|
||||
import { transformDoubleArgument } from './generic-transformers';
|
||||
|
||||
export interface VSimOptions {
|
||||
COUNT?: number;
|
||||
EF?: number;
|
||||
FILTER?: string;
|
||||
'FILTER-EF'?: number;
|
||||
TRUTH?: boolean;
|
||||
NOTHREAD?: boolean;
|
||||
}
|
||||
|
||||
export default {
|
||||
IS_READ_ONLY: true,
|
||||
/**
|
||||
* Retrieve elements similar to a given vector or element with optional filtering
|
||||
*
|
||||
* @param parser - The command parser
|
||||
* @param key - The key of the vector set
|
||||
* @param query - The query vector (array of numbers) or element name (string)
|
||||
* @param options - Optional parameters for similarity search
|
||||
* @see https://redis.io/commands/vsim/
|
||||
*/
|
||||
parseCommand(
|
||||
parser: CommandParser,
|
||||
key: RedisArgument,
|
||||
query: RedisArgument | Array<number>,
|
||||
options?: VSimOptions
|
||||
) {
|
||||
parser.push('VSIM');
|
||||
parser.pushKey(key);
|
||||
|
||||
if (Array.isArray(query)) {
|
||||
parser.push('VALUES', query.length.toString());
|
||||
for (const value of query) {
|
||||
parser.push(transformDoubleArgument(value));
|
||||
}
|
||||
} else {
|
||||
parser.push('ELE', query);
|
||||
}
|
||||
|
||||
if (options?.COUNT !== undefined) {
|
||||
parser.push('COUNT', options.COUNT.toString());
|
||||
}
|
||||
|
||||
if (options?.EF !== undefined) {
|
||||
parser.push('EF', options.EF.toString());
|
||||
}
|
||||
|
||||
if (options?.FILTER) {
|
||||
parser.push('FILTER', options.FILTER);
|
||||
}
|
||||
|
||||
if (options?.['FILTER-EF'] !== undefined) {
|
||||
parser.push('FILTER-EF', options['FILTER-EF'].toString());
|
||||
}
|
||||
|
||||
if (options?.TRUTH) {
|
||||
parser.push('TRUTH');
|
||||
}
|
||||
|
||||
if (options?.NOTHREAD) {
|
||||
parser.push('NOTHREAD');
|
||||
}
|
||||
},
|
||||
transformReply: undefined as unknown as () => ArrayReply<BlobStringReply>
|
||||
} as const satisfies Command;
|
Reference in New Issue
Block a user