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
85
packages/client/lib/commands/VSIM.spec.ts
Normal file
85
packages/client/lib/commands/VSIM.spec.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { strict as assert } from 'node:assert';
|
||||
import testUtils, { GLOBAL } from '../test-utils';
|
||||
import VSIM from './VSIM';
|
||||
import { BasicCommandParser } from '../client/parser';
|
||||
|
||||
describe('VSIM', () => {
|
||||
describe('parseCommand', () => {
|
||||
it('with vector', () => {
|
||||
const parser = new BasicCommandParser();
|
||||
VSIM.parseCommand(parser, 'key', [1.0, 2.0, 3.0]),
|
||||
assert.deepEqual(
|
||||
parser.redisArgs,
|
||||
['VSIM', 'key', 'VALUES', '3', '1', '2', '3']
|
||||
);
|
||||
});
|
||||
|
||||
it('with element', () => {
|
||||
const parser = new BasicCommandParser();
|
||||
VSIM.parseCommand(parser, 'key', 'element');
|
||||
assert.deepEqual(
|
||||
parser.redisArgs,
|
||||
['VSIM', 'key', 'ELE', 'element']
|
||||
);
|
||||
});
|
||||
|
||||
it('with options', () => {
|
||||
const parser = new BasicCommandParser();
|
||||
VSIM.parseCommand(parser, 'key', 'element', {
|
||||
COUNT: 5,
|
||||
EF: 100,
|
||||
FILTER: '.price > 20',
|
||||
'FILTER-EF': 50,
|
||||
TRUTH: true,
|
||||
NOTHREAD: true
|
||||
});
|
||||
assert.deepEqual(
|
||||
parser.redisArgs,
|
||||
[
|
||||
'VSIM', 'key', 'ELE', 'element',
|
||||
'COUNT', '5', 'EF', '100', 'FILTER', '.price > 20',
|
||||
'FILTER-EF', '50', 'TRUTH', 'NOTHREAD'
|
||||
]
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
testUtils.testAll('vSim', async client => {
|
||||
await client.vAdd('key', [1.0, 2.0, 3.0], 'element1');
|
||||
await client.vAdd('key', [1.1, 2.1, 3.1], 'element2');
|
||||
|
||||
const result = await client.vSim('key', 'element1');
|
||||
assert.ok(Array.isArray(result));
|
||||
assert.ok(result.includes('element1'));
|
||||
}, {
|
||||
client: { ...GLOBAL.SERVERS.OPEN, minimumDockerVersion: [8, 0] },
|
||||
cluster: { ...GLOBAL.CLUSTERS.OPEN, minimumDockerVersion: [8, 0] }
|
||||
});
|
||||
|
||||
testUtils.testWithClient('vSim with RESP3', async client => {
|
||||
await client.vAdd('resp3-key', [1.0, 2.0, 3.0], 'element1');
|
||||
await client.vAdd('resp3-key', [1.1, 2.1, 3.1], 'element2');
|
||||
await client.vAdd('resp3-key', [2.0, 3.0, 4.0], 'element3');
|
||||
|
||||
// Test similarity search with vector
|
||||
const resultWithVector = await client.vSim('resp3-key', [1.05, 2.05, 3.05]);
|
||||
assert.ok(Array.isArray(resultWithVector));
|
||||
assert.ok(resultWithVector.length > 0);
|
||||
|
||||
// Test similarity search with element
|
||||
const resultWithElement = await client.vSim('resp3-key', 'element1');
|
||||
assert.ok(Array.isArray(resultWithElement));
|
||||
assert.ok(resultWithElement.includes('element1'));
|
||||
|
||||
// Test with options
|
||||
const resultWithOptions = await client.vSim('resp3-key', 'element1', { COUNT: 2 });
|
||||
assert.ok(Array.isArray(resultWithOptions));
|
||||
assert.ok(resultWithOptions.length <= 2);
|
||||
}, {
|
||||
...GLOBAL.SERVERS.OPEN,
|
||||
clientOptions: {
|
||||
RESP: 3
|
||||
},
|
||||
minimumDockerVersion: [8, 0]
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user