From 0f74cee42e687b1f0c00842363ff8da5d7dcac6a 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/store/src/Retriever.php | 6 +++--- src/store/tests/RetrieverTest.php | 14 ++++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/store/src/Retriever.php b/src/store/src/Retriever.php index 680a9bc3..d2491b70 100644 --- a/src/store/src/Retriever.php +++ b/src/store/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/src/store/tests/RetrieverTest.php b/src/store/tests/RetrieverTest.php index 4bf31a8b..841e4c50 100644 --- a/src/store/tests/RetrieverTest.php +++ b/src/store/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() )