From 6a45db5ef59db94d7b7f200eb5c179d7b4635ab9 Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Tue, 17 Mar 2026 21:42:47 +0100 Subject: [PATCH] [Store] Split query string into words for TextQuery and HybridQuery in Retriever --- src/Retriever.php | 6 +++--- tests/RetrieverTest.php | 14 ++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Retriever.php b/src/Retriever.php index 680a9bc..d2491b7 100644 --- a/src/Retriever.php +++ b/src/Retriever.php @@ -113,19 +113,19 @@ final class Retriever implements RetrieverInterface if (null === $this->vectorizer) { $this->logger->debug('No vectorizer configured, using TextQuery if supported'); - return new TextQuery($query); + return new TextQuery(explode(' ', $query)); } if (!$this->store->supports(VectorQuery::class)) { $this->logger->debug('Store does not support vector queries, falling back to TextQuery'); - return new TextQuery($query); + return new TextQuery(explode(' ', $query)); } if ($this->store->supports(HybridQuery::class)) { $this->logger->debug('Store supports hybrid queries, using HybridQuery with semantic ratio', ['semanticRatio' => $options['semanticRatio'] ?? 0.5]); - return new HybridQuery($this->vectorizer->vectorize($query), $query, $options['semanticRatio'] ?? 0.5); + return new HybridQuery($this->vectorizer->vectorize($query), explode(' ', $query), $options['semanticRatio'] ?? 0.5); } $this->logger->debug('Store supports vector queries, using VectorQuery'); diff --git a/tests/RetrieverTest.php b/tests/RetrieverTest.php index 4bf31a8..841e4c5 100644 --- a/tests/RetrieverTest.php +++ b/tests/RetrieverTest.php @@ -124,7 +124,9 @@ final class RetrieverTest extends TestCase $store->expects($this->once()) ->method('query') ->with( - $this->isInstanceOf(TextQuery::class), + $this->callback(static function ($query) { + return $query instanceof TextQuery && ['test', 'query'] === $query->getTexts(); + }), $this->anything() ) ->willReturn([$document]); @@ -160,7 +162,9 @@ final class RetrieverTest extends TestCase $store->expects($this->once()) ->method('query') ->with( - $this->isInstanceOf(TextQuery::class), + $this->callback(static function ($query) { + return $query instanceof TextQuery && ['test', 'query'] === $query->getTexts(); + }), $this->anything() ) ->willReturn([$document]); @@ -196,7 +200,9 @@ final class RetrieverTest extends TestCase $store->expects($this->once()) ->method('query') ->with( - $this->isInstanceOf(HybridQuery::class), + $this->callback(static function ($query) { + return $query instanceof HybridQuery && ['test', 'query'] === $query->getTexts(); + }), $this->anything() ) ->willReturn([$document]); @@ -403,7 +409,7 @@ final class RetrieverTest extends TestCase ->method('query') ->with( $this->callback(static function ($query) { - return $query instanceof HybridQuery && 'expanded query terms' === $query->getText(); + return $query instanceof HybridQuery && ['expanded', 'query', 'terms'] === $query->getTexts(); }), $this->anything() )