From a24a7be9b4321b60c069c95190213ca8d883a082 Mon Sep 17 00:00:00 2001 From: Vladyslav Vildanov <117659936+vladvildanov@users.noreply.github.com> Date: Wed, 4 Feb 2026 10:49:05 +0200 Subject: [PATCH] Added support for Redis 8.6 (#1631) * Added support for Redis 8.6 * Codestyle changes and test fixes * Fixed hybdrid tests * Updated CHANGELOG.md and composer.json * Fixed XINFO tests --- .github/workflows/tests.yml | 2 + CHANGELOG.md | 1 + composer.json | 8 +- examples/shared.php | 4 +- src/Client.php | 10 +- .../VectorSearch/BaseVectorSearchConfig.php | 13 +- src/Command/Redis/INFO.php | 4 +- src/Command/Redis/VINFO.php | 4 +- src/Configuration/Option/Aggregate.php | 1 - src/Configuration/Option/CRC16.php | 12 +- src/Configuration/Option/Cluster.php | 11 +- src/Configuration/Option/Commands.php | 9 +- src/Configuration/Option/Connections.php | 7 +- src/Configuration/Option/Replication.php | 11 +- src/Configuration/Options.php | 2 - src/Connection/Cluster/RedisCluster.php | 4 +- .../Replication/MasterSlaveReplication.php | 10 +- .../Replication/SentinelReplication.php | 7 +- src/Pipeline/ConnectionErrorProof.php | 7 +- src/Protocol/Text/Handler/BulkResponse.php | 2 - src/Protocol/Text/Handler/IntegerResponse.php | 2 - src/Protocol/Text/ResponseReader.php | 4 +- tests/PHPUnit/PredisTestCase.php | 2 + .../HybridSearch/HybridSearchQueryTest.php | 57 +++--- .../KNNVectorSearchConfigTest.php | 17 +- .../RangeVectorSearchConfigTest.php | 17 +- .../Command/Redis/Search/FTHYBRID_Test.php | 177 +++++++++++++----- .../Redis/TDigest/TDIGESTINFO_Test.php | 10 +- tests/Predis/Command/Redis/XINFO_Test.php | 10 +- tests/Predis/Retry/RetryTest.php | 3 +- 30 files changed, 246 insertions(+), 182 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a49856f7..e68c0f7f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -33,6 +33,7 @@ jobs: - '8.0' - '8.2' - '8.4' + - '8.6' steps: @@ -40,6 +41,7 @@ jobs: run: | # Mapping of original redis versions to client test containers declare -A redis_clients_version_mapping=( + ["8.6"]="8.6-rc1-21356658603-debian-amd64" ["8.4"]="8.4.0" ["8.2"]="8.2.2-pre" ["8.0"]="8.0.2" diff --git a/CHANGELOG.md b/CHANGELOG.md index 86805145..cff31819 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ ### Maintenance - Added testing with SSL connection (#1624) +- Added support for Redis 8.6 (#1631) ## v3.3.0 (2025-11-24) ### Added diff --git a/composer.json b/composer.json index 8bae9ebe..a5be6408 100644 --- a/composer.json +++ b/composer.json @@ -46,7 +46,13 @@ }, "config": { "sort-packages": true, - "preferred-install": "dist" + "preferred-install": "dist", + "audit": { + "ignore": [ + "GHSA-vvj3-c3rp-c85p", + "PKSA-z3gr-8qht-p93v" + ] + } }, "minimum-stability": "dev", "prefer-stable": true diff --git a/examples/shared.php b/examples/shared.php index f82e6b05..9f55f17b 100644 --- a/examples/shared.php +++ b/examples/shared.php @@ -22,9 +22,9 @@ function redis_version($info) return $info['Server']['redis_version']; } elseif (isset($info['redis_version'])) { return $info['redis_version']; - } else { - return 'unknown version'; } + + return 'unknown version'; } $single_server = [ diff --git a/src/Client.php b/src/Client.php index c0535c6f..af28e99f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -92,9 +92,8 @@ class Client implements ClientInterface, IteratorAggregate return new Options($options); } elseif ($options instanceof OptionsInterface) { return $options; - } else { - throw new InvalidArgumentException('Invalid type for client options'); } + throw new InvalidArgumentException('Invalid type for client options'); } /** @@ -140,11 +139,10 @@ class Client implements ClientInterface, IteratorAggregate return $initializer($parameters, true); } elseif ($options->defined('aggregate') && $initializer = $options->aggregate) { return $initializer($parameters, false); - } else { - throw new InvalidArgumentException( - 'Array of connection parameters requires `cluster`, `replication` or `aggregate` client option' - ); } + throw new InvalidArgumentException( + 'Array of connection parameters requires `cluster`, `replication` or `aggregate` client option' + ); } if (is_callable($parameters)) { diff --git a/src/Command/Argument/Search/HybridSearch/VectorSearch/BaseVectorSearchConfig.php b/src/Command/Argument/Search/HybridSearch/VectorSearch/BaseVectorSearchConfig.php index ea262cdc..6633e282 100644 --- a/src/Command/Argument/Search/HybridSearch/VectorSearch/BaseVectorSearchConfig.php +++ b/src/Command/Argument/Search/HybridSearch/VectorSearch/BaseVectorSearchConfig.php @@ -13,7 +13,6 @@ namespace Predis\Command\Argument\Search\HybridSearch\VectorSearch; use Predis\Command\Argument\ArrayableArgument; -use Predis\Command\Redis\Utils\VectorUtility; abstract class BaseVectorSearchConfig implements ArrayableArgument { @@ -44,17 +43,13 @@ abstract class BaseVectorSearchConfig implements ArrayableArgument /** * Vector to perform search against. * - * @param string $field The vector field name to search against. Must start with "@". - * @param string|float[] $value Binary vector representation or array of floats as vector. + * @param string $field The vector field name to search against. Must start with "@". + * @param string $value Name of the parameter to use in the query. Must start with "$". * @return self */ - public function vector(string $field, $value): self + public function vector(string $field, string $value): self { - if (is_array($value)) { - array_push($this->vector, $field, VectorUtility::toBlob($value)); - } else { - array_push($this->vector, $field, $value); - } + array_push($this->vector, $field, $value); return $this; } diff --git a/src/Command/Redis/INFO.php b/src/Command/Redis/INFO.php index 90f3ca81..05df3d70 100644 --- a/src/Command/Redis/INFO.php +++ b/src/Command/Redis/INFO.php @@ -38,9 +38,9 @@ class INFO extends RedisCommand if (strpos($lines[0], '#') === 0) { return $this->parseNewResponseFormat($lines); - } else { - return $this->parseOldResponseFormat($lines); } + + return $this->parseOldResponseFormat($lines); } /** diff --git a/src/Command/Redis/VINFO.php b/src/Command/Redis/VINFO.php index 8ee5bc6d..01c92ff0 100644 --- a/src/Command/Redis/VINFO.php +++ b/src/Command/Redis/VINFO.php @@ -34,9 +34,9 @@ class VINFO extends RedisCommand if (!is_null($data)) { if ($data === array_values($data)) { return CommandUtility::arrayToDictionary($data); - } else { - return $data; // Relay } + + return $data; // Relay } return $data; diff --git a/src/Configuration/Option/Aggregate.php b/src/Configuration/Option/Aggregate.php index 13d71984..84815e12 100644 --- a/src/Configuration/Option/Aggregate.php +++ b/src/Configuration/Option/Aggregate.php @@ -109,6 +109,5 @@ class Aggregate implements OptionInterface */ public function getDefault(OptionsInterface $options) { - return; } } diff --git a/src/Configuration/Option/CRC16.php b/src/Configuration/Option/CRC16.php index e99ca1ee..88cf7dd8 100644 --- a/src/Configuration/Option/CRC16.php +++ b/src/Configuration/Option/CRC16.php @@ -34,11 +34,10 @@ class CRC16 implements OptionInterface { if ($description === 'predis') { return new Hash\CRC16(); - } else { - throw new InvalidArgumentException( - 'String value for the crc16 option must be either `predis`' - ); } + throw new InvalidArgumentException( + 'String value for the crc16 option must be either `predis`' + ); } /** @@ -54,10 +53,9 @@ class CRC16 implements OptionInterface return $this->getHashGeneratorByDescription($options, $value); } elseif ($value instanceof Hash\HashGeneratorInterface) { return $value; - } else { - $class = get_class($this); - throw new InvalidArgumentException("$class expects a valid hash generator"); } + $class = get_class($this); + throw new InvalidArgumentException("$class expects a valid hash generator"); } /** diff --git a/src/Configuration/Option/Cluster.php b/src/Configuration/Option/Cluster.php index 7c3b4196..3fea5741 100644 --- a/src/Configuration/Option/Cluster.php +++ b/src/Configuration/Option/Cluster.php @@ -37,13 +37,12 @@ class Cluster extends Aggregate if (is_callable($value)) { return $this->getConnectionInitializer($options, $value); - } else { - throw new InvalidArgumentException(sprintf( - '%s expects either a string or a callable value, %s given', - static::class, - is_object($value) ? get_class($value) : gettype($value) - )); } + throw new InvalidArgumentException(sprintf( + '%s expects either a string or a callable value, %s given', + static::class, + is_object($value) ? get_class($value) : gettype($value) + )); } /** diff --git a/src/Configuration/Option/Commands.php b/src/Configuration/Option/Commands.php index 376ccc17..59deec87 100644 --- a/src/Configuration/Option/Commands.php +++ b/src/Configuration/Option/Commands.php @@ -39,12 +39,11 @@ class Commands implements OptionInterface return $this->createFactoryByArray($options, $value); } elseif (is_string($value)) { return $this->createFactoryByString($options, $value); - } else { - throw new InvalidArgumentException(sprintf( - '%s expects a valid command factory', - static::class - )); } + throw new InvalidArgumentException(sprintf( + '%s expects a valid command factory', + static::class + )); } /** diff --git a/src/Configuration/Option/Connections.php b/src/Configuration/Option/Connections.php index a96068c5..1f91f25b 100644 --- a/src/Configuration/Option/Connections.php +++ b/src/Configuration/Option/Connections.php @@ -44,11 +44,10 @@ class Connections implements OptionInterface return $this->createFactoryByArray($options, $value); } elseif (is_string($value)) { return $this->createFactoryByString($options, $value); - } else { - throw new InvalidArgumentException(sprintf( - '%s expects a valid connection factory', static::class - )); } + throw new InvalidArgumentException(sprintf( + '%s expects a valid connection factory', static::class + )); } /** diff --git a/src/Configuration/Option/Replication.php b/src/Configuration/Option/Replication.php index 99077407..127194b7 100644 --- a/src/Configuration/Option/Replication.php +++ b/src/Configuration/Option/Replication.php @@ -35,13 +35,12 @@ class Replication extends Aggregate if (is_callable($value)) { return $this->getConnectionInitializer($options, $value); - } else { - throw new InvalidArgumentException(sprintf( - '%s expects either a string or a callable value, %s given', - static::class, - is_object($value) ? get_class($value) : gettype($value) - )); } + throw new InvalidArgumentException(sprintf( + '%s expects either a string or a callable value, %s given', + static::class, + is_object($value) ? get_class($value) : gettype($value) + )); } /** diff --git a/src/Configuration/Options.php b/src/Configuration/Options.php index 403bd7a5..00fec0eb 100644 --- a/src/Configuration/Options.php +++ b/src/Configuration/Options.php @@ -110,8 +110,6 @@ class Options implements OptionsInterface if (isset($this->handlers[$option])) { return $this->options[$option] = $this->getDefault($option); } - - return; } /** diff --git a/src/Connection/Cluster/RedisCluster.php b/src/Connection/Cluster/RedisCluster.php index bac1d533..401b210c 100644 --- a/src/Connection/Cluster/RedisCluster.php +++ b/src/Connection/Cluster/RedisCluster.php @@ -383,9 +383,9 @@ class RedisCluster extends AbstractAggregateConnection implements ClusterInterfa if (isset($this->slots[$slot])) { return $this->slots[$slot]; - } else { - return $this->getConnectionBySlot($slot); } + + return $this->getConnectionBySlot($slot); } /** diff --git a/src/Connection/Replication/MasterSlaveReplication.php b/src/Connection/Replication/MasterSlaveReplication.php index 9e186ee8..14be4201 100644 --- a/src/Connection/Replication/MasterSlaveReplication.php +++ b/src/Connection/Replication/MasterSlaveReplication.php @@ -405,9 +405,8 @@ class MasterSlaveReplication extends AbstractAggregateConnection implements Repl } elseif ($connection = $this->pickSlave()) { $this->discoverFromSlave($connection, $this->connectionFactory); break; - } else { - throw new ClientException('No connection available for discovery'); } + throw new ClientException('No connection available for discovery'); } catch (ConnectionException $exception) { $this->remove($connection); } @@ -606,11 +605,10 @@ class MasterSlaveReplication extends AbstractAggregateConnection implements Repl // when the command represents a read-only operation, unless // automatic discovery has been enabled. throw $exception; - } else { - // Otherwise remove the failing slave and attempt to execute - // the command again on one of the remaining slaves... - $this->remove($connection); } + // Otherwise remove the failing slave and attempt to execute + // the command again on one of the remaining slaves... + $this->remove($connection); // ... that is, unless we have no more connections to use. if (!$this->slaves && !$this->master) { diff --git a/src/Connection/Replication/SentinelReplication.php b/src/Connection/Replication/SentinelReplication.php index c742c436..0da3b92b 100644 --- a/src/Connection/Replication/SentinelReplication.php +++ b/src/Connection/Replication/SentinelReplication.php @@ -368,9 +368,8 @@ class SentinelReplication extends AbstractAggregateConnection implements Replica { if ($error->getErrorType() === 'IDONTKNOW') { throw new ConnectionException($sentinel, $error->getMessage()); - } else { - throw new ServerException($error->getMessage()); } + throw new ServerException($error->getMessage()); } /** @@ -624,9 +623,9 @@ class SentinelReplication extends AbstractAggregateConnection implements Replica return $this->pickSlave(); } elseif ($role === 'sentinel') { return $this->getSentinelConnection(); - } else { - return null; } + + return null; } /** diff --git a/src/Pipeline/ConnectionErrorProof.php b/src/Pipeline/ConnectionErrorProof.php index 890d1472..4064215d 100644 --- a/src/Pipeline/ConnectionErrorProof.php +++ b/src/Pipeline/ConnectionErrorProof.php @@ -42,11 +42,10 @@ class ConnectionErrorProof extends Pipeline return $this->executeSingleNode($connection, $commands); } elseif ($connection instanceof ClusterInterface) { return $this->executeCluster($connection, $commands); - } else { - $class = get_class($connection); - - throw new NotSupportedException("The connection class '$class' is not supported."); } + $class = get_class($connection); + + throw new NotSupportedException("The connection class '$class' is not supported."); } /** diff --git a/src/Protocol/Text/Handler/BulkResponse.php b/src/Protocol/Text/Handler/BulkResponse.php index f83a95a7..223f7130 100644 --- a/src/Protocol/Text/Handler/BulkResponse.php +++ b/src/Protocol/Text/Handler/BulkResponse.php @@ -48,7 +48,5 @@ class BulkResponse implements ResponseHandlerInterface CommunicationException::handle(new ProtocolException( $connection, "Value '$payload' is not a valid length for a bulk response [{$connection->getParameters()}]" )); - - return; } } diff --git a/src/Protocol/Text/Handler/IntegerResponse.php b/src/Protocol/Text/Handler/IntegerResponse.php index 5acd5097..887b17e6 100644 --- a/src/Protocol/Text/Handler/IntegerResponse.php +++ b/src/Protocol/Text/Handler/IntegerResponse.php @@ -40,7 +40,5 @@ class IntegerResponse implements ResponseHandlerInterface $connection, "Cannot parse '$payload' as a valid numeric response [{$connection->getParameters()}]" )); } - - return; } } diff --git a/src/Protocol/Text/ResponseReader.php b/src/Protocol/Text/ResponseReader.php index 698a11d2..f7806384 100644 --- a/src/Protocol/Text/ResponseReader.php +++ b/src/Protocol/Text/ResponseReader.php @@ -63,15 +63,13 @@ class ResponseReader implements ResponseReaderInterface * * @param string $prefix Identifier of the type of response. * - * @return Handler\ResponseHandlerInterface + * @return Handler\ResponseHandlerInterface|void */ public function getHandler($prefix) { if (isset($this->handlers[$prefix])) { return $this->handlers[$prefix]; } - - return; } /** diff --git a/tests/PHPUnit/PredisTestCase.php b/tests/PHPUnit/PredisTestCase.php index 9d6042ca..0a1ad099 100644 --- a/tests/PHPUnit/PredisTestCase.php +++ b/tests/PHPUnit/PredisTestCase.php @@ -292,6 +292,7 @@ abstract class PredisTestCase extends PHPUnit\Framework\TestCase 'cafile' => getenv('CLUSTER_CA_CERT_PATH'), 'verify_peer' => true, 'verify_peer_name' => false, + 'allow_self_signed' => false, ], ], ]); @@ -303,6 +304,7 @@ abstract class PredisTestCase extends PHPUnit\Framework\TestCase 'cafile' => getenv('STANDALONE_CA_CERT_PATH'), 'verify_peer' => true, 'verify_peer_name' => false, + 'allow_self_signed' => false, ], ]); } diff --git a/tests/Predis/Command/Argument/Search/HybridSearch/HybridSearchQueryTest.php b/tests/Predis/Command/Argument/Search/HybridSearch/HybridSearchQueryTest.php index e9c85fa3..39d729c6 100644 --- a/tests/Predis/Command/Argument/Search/HybridSearch/HybridSearchQueryTest.php +++ b/tests/Predis/Command/Argument/Search/HybridSearch/HybridSearchQueryTest.php @@ -17,7 +17,6 @@ use Predis\Command\Argument\Search\HybridSearch\Combine\LinearCombineConfig; use Predis\Command\Argument\Search\HybridSearch\Combine\RRFCombineConfig; use Predis\Command\Argument\Search\HybridSearch\VectorSearch\KNNVectorSearchConfig; use Predis\Command\Argument\Search\HybridSearch\VectorSearch\RangeVectorSearchConfig; -use Predis\Command\Redis\Utils\VectorUtility; class HybridSearchQueryTest extends TestCase { @@ -43,11 +42,11 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10], ], 'with RANGE vector search' => [ (new HybridSearchQuery(RangeVectorSearchConfig::class)) @@ -59,11 +58,11 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (RangeVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->radius(5) ->epsilon(0.2); }), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'RANGE', 4, 'RADIUS', 5, 'EPSILON', 0.2], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'RANGE', 4, 'RADIUS', 5, 'EPSILON', 0.2], ], 'with COMBINE config - RRF' => [ (new HybridSearchQuery()) @@ -75,7 +74,7 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }) @@ -84,7 +83,7 @@ class HybridSearchQueryTest extends TestCase ->window(5) ->rrfConstant(10); }), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'COMBINE', 'RRF', 4, 'WINDOW', 5, 'CONSTANT', 10], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'COMBINE', 'RRF', 4, 'WINDOW', 5, 'CONSTANT', 10], ], 'with COMBINE config - LINEAR' => [ (new HybridSearchQuery(KNNVectorSearchConfig::class, LinearCombineConfig::class)) @@ -96,7 +95,7 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }) @@ -105,7 +104,7 @@ class HybridSearchQueryTest extends TestCase ->alpha(0.2) ->beta(0.3); }), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'COMBINE', 'LINEAR', 4, 'ALPHA', 0.2, 'BETA', 0.3], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'COMBINE', 'LINEAR', 4, 'ALPHA', 0.2, 'BETA', 0.3], ], 'with LOAD' => [ (new HybridSearchQuery()) @@ -117,12 +116,12 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }) ->load(['field1', 'field2']), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'LOAD', 2, 'field1', 'field2'], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'LOAD', 2, 'field1', 'field2'], ], 'with GROUPBY' => [ (new HybridSearchQuery()) @@ -134,7 +133,7 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }) @@ -145,7 +144,7 @@ class HybridSearchQueryTest extends TestCase new Reducer(Reducer::REDUCE_MAX, ['prop1', 'prop2']), ] ), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'GROUPBY', 2, 'field1', 'field2', 'REDUCE', 'COUNT', 2, 'prop1', 'prop2', 'AS', 'alias', 'REDUCE', 'MAX', 2, 'prop1', 'prop2'], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'GROUPBY', 2, 'field1', 'field2', 'REDUCE', 'COUNT', 2, 'prop1', 'prop2', 'AS', 'alias', 'REDUCE', 'MAX', 2, 'prop1', 'prop2'], ], 'with APPLY' => [ (new HybridSearchQuery()) @@ -157,12 +156,12 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }) ->apply(['field' => 'expr']), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'APPLY', 'expr', 'AS', 'field'], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'APPLY', 'expr', 'AS', 'field'], ], 'with SORTBY' => [ (new HybridSearchQuery()) @@ -174,12 +173,12 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }) ->sortBy(['field' => 'DESC']), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'SORTBY', 2, 'field', 'DESC'], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'SORTBY', 2, 'field', 'DESC'], ], 'with FILTER' => [ (new HybridSearchQuery()) @@ -191,12 +190,12 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }) ->filter('expr'), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'FILTER', 'expr'], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'FILTER', 'expr'], ], 'with LIMIT' => [ (new HybridSearchQuery()) @@ -208,12 +207,12 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }) ->limit(0, 10), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'LIMIT', 0, 10], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'LIMIT', 0, 10], ], 'with PARAMS' => [ (new HybridSearchQuery()) @@ -225,12 +224,12 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }) ->params(['param1' => 'value1', 'param2' => 'value2']), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'PARAMS', 4, 'param1', 'value1', 'param2', 'value2'], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'PARAMS', 4, 'param1', 'value1', 'param2', 'value2'], ], 'with EXPLAINSCORE' => [ (new HybridSearchQuery()) @@ -242,12 +241,12 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }) ->explainScore(), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'EXPLAINSCORE'], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'EXPLAINSCORE'], ], 'with TIMEOUT' => [ (new HybridSearchQuery()) @@ -259,12 +258,12 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }) ->timeout(), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'TIMEOUT'], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'TIMEOUT'], ], 'with WITHCURSOR' => [ (new HybridSearchQuery()) @@ -276,12 +275,12 @@ class HybridSearchQueryTest extends TestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); }) ->withCursor(10, 10), - ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'WITHCURSOR', 'COUNT', 10, 'MAXIDLE', 10], + ['SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'WITHCURSOR', 'COUNT', 10, 'MAXIDLE', 10], ], ]; } diff --git a/tests/Predis/Command/Argument/Search/HybridSearch/VectorSearch/KNNVectorSearchConfigTest.php b/tests/Predis/Command/Argument/Search/HybridSearch/VectorSearch/KNNVectorSearchConfigTest.php index abaa567e..1a81249b 100644 --- a/tests/Predis/Command/Argument/Search/HybridSearch/VectorSearch/KNNVectorSearchConfigTest.php +++ b/tests/Predis/Command/Argument/Search/HybridSearch/VectorSearch/KNNVectorSearchConfigTest.php @@ -13,7 +13,6 @@ namespace Predis\Command\Argument\Search\HybridSearch\VectorSearch; use PHPUnit\Framework\TestCase; -use Predis\Command\Redis\Utils\VectorUtility; use ValueError; class KNNVectorSearchConfigTest extends TestCase @@ -48,29 +47,29 @@ class KNNVectorSearchConfigTest extends TestCase return [ 'with vector and K' => [ (new KNNVectorSearchConfig()) - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5), - ['VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 2, 'K', 5]], + ['VSIM', 'vector', '$vector', 'KNN', 2, 'K', 5]], 'with vector, K and EF_RUNTIME' => [ (new KNNVectorSearchConfig()) - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(5), - ['VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 5]], + ['VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 5]], 'with vector, K and FILTER' => [ (new KNNVectorSearchConfig()) - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->filter('*'), - ['VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 2, 'K', 5, 'FILTER', '*']], + ['VSIM', 'vector', '$vector', 'KNN', 2, 'K', 5, 'FILTER', '*']], 'with all' => [ (new KNNVectorSearchConfig()) - ->vector('vector', VectorUtility::toBlob([0.1, 0.2, 0.3])) + ->vector('vector', '$vector') ->k(5) ->ef(5) ->filter('*') ->as('alias'), - ['VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 5, 'FILTER', '*', 'YIELD_SCORE_AS', 'alias']], + ['VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 5, 'FILTER', '*', 'YIELD_SCORE_AS', 'alias']], ]; } } diff --git a/tests/Predis/Command/Argument/Search/HybridSearch/VectorSearch/RangeVectorSearchConfigTest.php b/tests/Predis/Command/Argument/Search/HybridSearch/VectorSearch/RangeVectorSearchConfigTest.php index 6a2035f0..38b46bd4 100644 --- a/tests/Predis/Command/Argument/Search/HybridSearch/VectorSearch/RangeVectorSearchConfigTest.php +++ b/tests/Predis/Command/Argument/Search/HybridSearch/VectorSearch/RangeVectorSearchConfigTest.php @@ -13,7 +13,6 @@ namespace Predis\Command\Argument\Search\HybridSearch\VectorSearch; use PHPUnit\Framework\TestCase; -use Predis\Command\Redis\Utils\VectorUtility; use ValueError; class RangeVectorSearchConfigTest extends TestCase @@ -58,29 +57,29 @@ class RangeVectorSearchConfigTest extends TestCase return [ 'with vector and RADIUS' => [ (new RangeVectorSearchConfig()) - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->radius(5), - ['VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'RANGE', 2, 'RADIUS', 5]], + ['VSIM', 'vector', '$vector', 'RANGE', 2, 'RADIUS', 5]], 'with vector, RADIUS and EPSILON' => [ (new RangeVectorSearchConfig()) - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->radius(5) ->epsilon(0.2), - ['VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'RANGE', 4, 'RADIUS', 5, 'EPSILON', 0.2]], + ['VSIM', 'vector', '$vector', 'RANGE', 4, 'RADIUS', 5, 'EPSILON', 0.2]], 'with vector, RADIUS and FILTER' => [ (new RangeVectorSearchConfig()) - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->radius(5) ->filter('*'), - ['VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'RANGE', 2, 'RADIUS', 5, 'FILTER', '*']], + ['VSIM', 'vector', '$vector', 'RANGE', 2, 'RADIUS', 5, 'FILTER', '*']], 'with all arguments' => [ (new RangeVectorSearchConfig()) - ->vector('vector', VectorUtility::toBlob([0.1, 0.2, 0.3])) + ->vector('vector', '$vector') ->radius(5) ->epsilon(0.2) ->as('alias') ->filter('*'), - ['VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'RANGE', 4, 'RADIUS', 5, 'EPSILON', 0.2, 'FILTER', '*', 'YIELD_SCORE_AS', 'alias']], + ['VSIM', 'vector', '$vector', 'RANGE', 4, 'RADIUS', 5, 'EPSILON', 0.2, 'FILTER', '*', 'YIELD_SCORE_AS', 'alias']], ]; } } diff --git a/tests/Predis/Command/Redis/Search/FTHYBRID_Test.php b/tests/Predis/Command/Redis/Search/FTHYBRID_Test.php index e593dcbd..dce076ba 100644 --- a/tests/Predis/Command/Redis/Search/FTHYBRID_Test.php +++ b/tests/Predis/Command/Redis/Search/FTHYBRID_Test.php @@ -61,16 +61,19 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('vector', [0.1, 0.2, 0.3]) + ->vector('vector', '$vector') ->k(5) ->ef(10); - }); + }) + ->params([ + 'vector' => VectorUtility::toBlob([0.1, 0.2, 0.3]), + ]); $index = 'idx'; $command->setArguments([$index, $query]); $this->assertSameValues( - ['idx', 'SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3]), 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10], + ['idx', 'SEARCH', '*', 'SCORER', ScorerConfig::TYPE_DISMAX, 'VSIM', 'vector', '$vector', 'KNN', 4, 'K', 5, 'EF_RUNTIME', 10, 'PARAMS', 2, 'vector', VectorUtility::toBlob([0.1, 0.2, 0.3])], $command->getArguments() ); } @@ -110,8 +113,11 @@ class FTHYBRID_Test extends PredisCommandTestCase }); }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { - $config->vector('@embedding', [-100, -200, -200, -300]); - }); + $config->vector('@embedding', '$vector'); + }) + ->params([ + 'vector' => VectorUtility::toBlob([-100, -200, -200, -300]), + ]); $this->assertGreaterThan(0, $redis->fthybrid('idx', $query)['total_results']); } @@ -137,8 +143,11 @@ class FTHYBRID_Test extends PredisCommandTestCase }); }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { - $config->vector('@embedding', [-100, -200, -200, -300]); - }); + $config->vector('@embedding', '$vector'); + }) + ->params([ + 'vector' => VectorUtility::toBlob([-100, -200, -200, -300]), + ]); $this->assertGreaterThan(0, $redis->fthybrid('idx', $query)['total_results']); } @@ -161,8 +170,11 @@ class FTHYBRID_Test extends PredisCommandTestCase ->query('@color:{red} @color:{green}'); }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { - $config->vector('@embedding', [-100, -200, -200, -300]); - }); + $config->vector('@embedding', '$vector'); + }) + ->params([ + 'vector' => VectorUtility::toBlob([-100, -200, -200, -300]), + ]); $response = $redis->fthybrid('idx', $query); @@ -190,8 +202,11 @@ class FTHYBRID_Test extends PredisCommandTestCase ->query('@color:{red} @color:{green}'); }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { - $config->vector('@embedding', [-100, -200, -200, -300]); - }); + $config->vector('@embedding', '$vector'); + }) + ->params([ + 'vector' => VectorUtility::toBlob([-100, -200, -200, -300]), + ]); $response = $redis->fthybrid('idx', $query); @@ -222,7 +237,7 @@ class FTHYBRID_Test extends PredisCommandTestCase }); }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { - $config->vector('@embedding', [1, 2, 2, 3]); + $config->vector('@embedding', '$vector'); }) ->buildCombineConfig(function (LinearCombineConfig $config) { $config @@ -230,7 +245,10 @@ class FTHYBRID_Test extends PredisCommandTestCase ->beta(0); }) ->load(['@description', '@color', '@price', '@size', '@__score', '@__item']) - ->limit(0, 2); + ->limit(0, 2) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 2, 3]), + ]); $expectedResultsTFIDF = [ [ @@ -261,7 +279,7 @@ class FTHYBRID_Test extends PredisCommandTestCase }); }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { - $config->vector('@embedding', [1, 2, 2, 3]); + $config->vector('@embedding', '$vector'); }) ->buildCombineConfig(function (LinearCombineConfig $config) { $config @@ -269,7 +287,10 @@ class FTHYBRID_Test extends PredisCommandTestCase ->beta(0); }) ->load(['@description', '@color', '@price', '@size', '@__score', '@__item']) - ->limit(0, 2); + ->limit(0, 2) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 2, 3]), + ]); $expectedResultsBM25 = [ [ @@ -311,10 +332,13 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding-hnsw', 'abcd1234efgh5678') + ->vector('@embedding-hnsw', '$vector') ->k(3) ->ef(1); - }); + }) + ->params([ + 'vector' => 'abcd1234efgh5678', + ]); $response = $redis->fthybrid('idx', $query); $this->assertGreaterThan(0, count($response['results'])); } @@ -338,10 +362,13 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding', 'abcd1234efgh5678') + ->vector('@embedding', '$vector') ->filter('@price:[15 16] @size:[10 11]'); }) - ->load(['@price', '@size']); + ->load(['@price', '@size']) + ->params([ + 'vector' => 'abcd1234efgh5678', + ]); $response = $redis->fthybrid('idx', $query); $this->assertGreaterThan(0, count($response['results'])); @@ -372,8 +399,11 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding', 'abcd1234efgh5678'); - }); + ->vector('@embedding', '$vector'); + }) + ->params([ + 'vector' => 'abcd1234efgh5678', + ]); $response = $redis->fthybrid('idx', $query); $this->assertGreaterThan(0, count($response['results'])); @@ -405,11 +435,14 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding-hnsw', 'abcd1234efgh5678') + ->vector('@embedding-hnsw', '$vector') ->k(3) ->ef(1) ->as('vsim_score'); - }); + }) + ->params([ + 'vector' => 'abcd1234efgh5678', + ]); $response = $redis->fthybrid('idx', $query); $this->assertGreaterThan(0, count($response['results'])); @@ -442,7 +475,7 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding-hnsw', 'abcd1234efgh5678') + ->vector('@embedding-hnsw', '$vector') ->k(3) ->ef(1) ->as('vsim_score'); @@ -452,7 +485,10 @@ class FTHYBRID_Test extends PredisCommandTestCase ->alpha(0.5) ->beta(0.5) ->as('combine_score'); - }); + }) + ->params([ + 'vector' => 'abcd1234efgh5678', + ]); $response = $redis->fthybrid('idx', $query); $this->assertGreaterThan(0, count($response['results'])); @@ -495,7 +531,7 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding-hnsw', 'abcd1234efgh5678') + ->vector('@embedding-hnsw', '$vector') ->k(3) ->ef(1) ->as('vsim_score'); @@ -505,7 +541,10 @@ class FTHYBRID_Test extends PredisCommandTestCase ->alpha(0.5) ->beta(0.5) ->as('combine_score'); - }); + }) + ->params([ + 'vector' => 'abcd1234efgh5678', + ]); $response = $redis->fthybrid('idx', $query); $this->assertGreaterThan(0, count($response['results'])); @@ -535,9 +574,12 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding', [1, 2, 2, 3]) + ->vector('@embedding', '$vector') ->k(3); - }); + }) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 2, 3]), + ]); $expected_results = [ ['__key' => 'item:2', '__score' => '0.016393442623'], @@ -555,10 +597,13 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding-hnsw', [1, 2, 2, 3]) + ->vector('@embedding-hnsw', '$vector') ->k(3) ->ef(1); - }); + }) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 2, 3]), + ]); $expected_results = [ ['__key' => 'item:12', '__score' => '0.016393442623'], @@ -589,9 +634,12 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (RangeVectorSearchConfig $config) { $config - ->vector('@embedding', [1, 2, 7, 6]); + ->vector('@embedding', '$vector'); }) - ->limit(0, 3); + ->limit(0, 3) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 7, 6]), + ]); $expected_results = [ ['__key' => 'item:2', '__score' => '0.016393442623'], @@ -609,11 +657,14 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (RangeVectorSearchConfig $config) { $config - ->vector('@embedding-hnsw', [1, 2, 7, 6]) + ->vector('@embedding-hnsw', '$vector') ->radius(2) ->epsilon(0.5); }) - ->limit(0, 3); + ->limit(0, 3) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 7, 6]), + ]); $expected_results = [ ['__key' => 'item:27', '__score' => '0.016393442623'], @@ -644,14 +695,17 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding', [1, 2, 7, 6]); + ->vector('@embedding', '$vector'); }) ->buildCombineConfig(function (LinearCombineConfig $config) { $config ->alpha(0.5) ->beta(0.5); }) - ->limit(0, 3); + ->limit(0, 3) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 7, 6]), + ]); $expected_results = [ ['__key' => 'item:2', '__score' => '0.166666666667'], @@ -669,14 +723,17 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding', [1, 2, 7, 6]); + ->vector('@embedding', '$vector'); }) ->buildCombineConfig(function (RRFCombineConfig $config) { $config ->window(3) ->rrfConstant(0.5); }) - ->limit(0, 3); + ->limit(0, 3) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 7, 6]), + ]); $expected_results = [ ['__key' => 'item:2', '__score' => '1.5'], @@ -707,7 +764,7 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding', [1, 2, 7, 6]); + ->vector('@embedding', '$vector'); }) ->buildCombineConfig(function (LinearCombineConfig $config) { $config @@ -715,7 +772,10 @@ class FTHYBRID_Test extends PredisCommandTestCase ->beta(0.5); }) ->load(['@description', '@color', '@price', '@size', '@__key']) - ->limit(0, 1); + ->limit(0, 1) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 7, 6]), + ]); $expected_results = [ 'description' => 'red dress', @@ -748,14 +808,17 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding', [1, 2, 7, 6]); + ->vector('@embedding', '$vector'); }) ->load(['@color', '@price', '@size']) ->apply([ 'price_discount' => '@price - (@price * 0.1)', 'tax_discount' => '@price_discount * 0.2', ]) - ->limit(0, 3); + ->limit(0, 3) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 7, 6]), + ]); $expected_results = [ [ @@ -804,11 +867,14 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding', [1, 2, 7, 6]); + ->vector('@embedding', '$vector'); }) ->load(['@description', '@color', '@price', '@size']) ->filter('@price=="15"') - ->limit(0, 3); + ->limit(0, 3) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 7, 6]), + ]); $response = $redis->fthybrid('idx', $query); $this->assertCount(3, $response['results']); @@ -893,7 +959,7 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding', [1, 2, 7, 6]); + ->vector('@embedding', '$vector'); }) ->load(['@color', '@price']) ->apply([ @@ -903,7 +969,10 @@ class FTHYBRID_Test extends PredisCommandTestCase '@price_discount' => 'DESC', '@color' => 'ASC', ]) - ->limit(0, 5); + ->limit(0, 5) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 7, 6]), + ]); $expected_results = [ [ @@ -956,7 +1025,7 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding', [1, 2, 7, 6]); + ->vector('@embedding', '$vector'); }) ->load(['@color', '@price', '@size', '@item_type']) ->groupBy( @@ -969,7 +1038,10 @@ class FTHYBRID_Test extends PredisCommandTestCase ->sortBy([ '@price' => 'ASC', ]) - ->limit(0, 4); + ->limit(0, 4) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 7, 6]), + ]); $expected_results = [ [ @@ -1021,9 +1093,12 @@ class FTHYBRID_Test extends PredisCommandTestCase }) ->buildVectorSearchConfig(function (KNNVectorSearchConfig $config) { $config - ->vector('@embedding', [1, 2, 7, 6]); + ->vector('@embedding', '$vector'); }) - ->withCursor(5, 100); + ->withCursor(5, 100) + ->params([ + 'vector' => VectorUtility::toBlob([1, 2, 7, 6]), + ]); $response = $redis->fthybrid('idx', $query); $this->assertGreaterThan(0, $response['SEARCH']); diff --git a/tests/Predis/Command/Redis/TDigest/TDIGESTINFO_Test.php b/tests/Predis/Command/Redis/TDigest/TDIGESTINFO_Test.php index 1a413544..a8fd028d 100644 --- a/tests/Predis/Command/Redis/TDigest/TDIGESTINFO_Test.php +++ b/tests/Predis/Command/Redis/TDigest/TDIGESTINFO_Test.php @@ -111,12 +111,13 @@ class TDIGESTINFO_Test extends PredisCommandTestCase 'Unmerged weight' => 0, 'Observations' => 0, 'Total compressions' => 0, - 'Memory usage' => 9768, ]; $redis->tdigestcreate('key'); - $this->assertSame($expectedResponse, $redis->tdigestinfo('key')); + foreach ($expectedResponse as $value) { + $this->assertContains($value, $redis->tdigestinfo('key')); + } } /** @@ -137,12 +138,13 @@ class TDIGESTINFO_Test extends PredisCommandTestCase 'Unmerged weight' => 0, 'Observations' => 0, 'Total compressions' => 0, - 'Memory usage' => 9768, ]; $redis->tdigestcreate('key'); - $this->assertSame($expectedResponse, $redis->tdigestinfo('key')); + foreach ($expectedResponse as $value) { + $this->assertContains($value, $redis->tdigestinfo('key')); + } } /** diff --git a/tests/Predis/Command/Redis/XINFO_Test.php b/tests/Predis/Command/Redis/XINFO_Test.php index c47fb8ab..40065940 100644 --- a/tests/Predis/Command/Redis/XINFO_Test.php +++ b/tests/Predis/Command/Redis/XINFO_Test.php @@ -172,7 +172,11 @@ class XINFO_Test extends PredisCommandTestCase $options = new XInfoStreamOptions(); $options->full(5); - $this->assertSame($expectedResponse, $redis->xinfo->stream('stream', $options)); + $response = $redis->xinfo->stream('stream', $options); + + foreach ($expectedResponse as $value) { + $this->assertContains($value, $response); + } } /** @@ -271,7 +275,9 @@ class XINFO_Test extends PredisCommandTestCase ], ]; - $this->assertSame($expectedResponse, $result); + foreach ($expectedResponse as $value) { + $this->assertContains($value, $result); + } } /** diff --git a/tests/Predis/Retry/RetryTest.php b/tests/Predis/Retry/RetryTest.php index ea4f24dd..eddd26a0 100644 --- a/tests/Predis/Retry/RetryTest.php +++ b/tests/Predis/Retry/RetryTest.php @@ -78,9 +78,8 @@ class RetryTest extends TestCase throw new ConnectionException( $this->getMockBuilder(NodeConnectionInterface::class)->getMock() ); - } else { - throw new StreamInitException(); } + throw new StreamInitException(); }; $failCallable = function () use (&$retriesCount) {