From 64ac7eba43cbe69feb59c81a6cb413e166950691 Mon Sep 17 00:00:00 2001 From: Arif Hoque Date: Sat, 12 Sep 2026 23:45:57 +0600 Subject: [PATCH 1/2] fix: repair Redis driver test suite and add CI coverage for the redis driver --- src/Drivers/RedisDriver.php | 42 +++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/Drivers/RedisDriver.php b/src/Drivers/RedisDriver.php index a81c68d..30b3ba0 100644 --- a/src/Drivers/RedisDriver.php +++ b/src/Drivers/RedisDriver.php @@ -106,6 +106,32 @@ public function search(string $modelClass, string $attribute, array $queryVector { $this->ensureIndex(count($queryVector)); + try { + $result = $this->runSearch($modelClass, $attribute, $queryVector, $limit); + } catch (ServerException $e) { + if (!$this->isMissingIndex($e)) { + throw $e; + } + + self::$indexEnsured = false; + $this->ensureIndex(count($queryVector)); + $result = $this->runSearch($modelClass, $attribute, $queryVector, $limit); + } + + return $this->parseSearchResults($result); + } + + /** + * Issue the actual FT.SEARCH KNN query and return its raw reply. + * + * @param string $modelClass + * @param string $attribute + * @param array $queryVector + * @param int $limit + * @return array + */ + private function runSearch(string $modelClass, string $attribute, array $queryVector, int $limit): array + { $query = sprintf( '(@embeddable_type:{%s} @attribute:{%s})=>[KNN %d @vector $vec AS score]', $this->escapeTag($modelClass), @@ -113,7 +139,7 @@ public function search(string $modelClass, string $attribute, array $queryVector $limit, ); - $result = $this->client->executeCommand(RawCommand::create( + return $this->client->executeCommand(RawCommand::create( 'FT.SEARCH', self::INDEX_NAME, $query, @@ -129,8 +155,20 @@ public function search(string $modelClass, string $attribute, array $queryVector 'DIALECT', '2', )); + } - return $this->parseSearchResults($result); + /** + * Whether a ServerException from Redis represents a missing index + * (as opposed to some other command failure that should propagate). + * + * @param ServerException $e + * @return bool + */ + private function isMissingIndex(ServerException $e): bool + { + $message = strtolower($e->getMessage()); + + return str_contains($message, 'no such index') || str_contains($message, 'unknown index name'); } /** From f67c14fa543c30cd3dacb79364a7a56c099f5016 Mon Sep 17 00:00:00 2001 From: Arif Hoque Date: Sat, 12 Sep 2026 23:49:43 +0600 Subject: [PATCH 2/2] fix: repair Redis driver test suite and add CI coverage for the redis driver --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dbeba06..2d8281a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -44,4 +44,4 @@ jobs: composer update --prefer-dist --no-interaction --no-progress - name: Execute tests - run: vendor/bin/phpunit --display-deprecations --fail-on-deprecation + run: vendor/bin/phpunit --display-deprecations