-
-
Notifications
You must be signed in to change notification settings - Fork 172
[Store] Add query abstraction with filter support #1570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Store] Add query abstraction with filter support #1570
Conversation
cc6d736 to
ccd1d40
Compare
Implement query abstraction pattern to support multiple query types (Vector, Text, Hybrid) with integrated filter system. Key changes: - Add QueryInterface with VectorQuery, TextQuery, and HybridQuery implementations - Add FilterInterface with EqualFilter implementation - Update StoreInterface with new query() signature and supports() method - Implement filter support in all reference stores (Postgres, ChromaDB, Pinecone, Redis, Qdrant, Cache) - Extend Postgres to support Vector, Text, and Hybrid queries with PostgreSQL FTS - Update Retriever to use query abstraction with capability checking Breaking change: Store::query() now accepts QueryInterface instead of Vector. Migration: Wrap Vector in VectorQuery constructor.
ccd1d40 to
ae3ba15
Compare
| $this->logger->debug('Document retrieval completed', ['retrieved_count' => $count]); | ||
| } | ||
|
|
||
| private function createQuery(string $query, array $options): QueryInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the most important part of this PR - it selects the right type of query
| { | ||
| public function getType(): QueryType; | ||
|
|
||
| public function getFilter(): ?FilterInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure how the filter should look like and how we could validate them in the store. @chr-hertel for equal its easy but for more complex filters it could be hard to implement that in the stores
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's go incremental and skip the filter part for the first PR - we can slice that, right?
|
for all who take a look at this PR this is a POC as a discussion base |
chr-hertel
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @wachterjohannes for jumping on that - much appreciated 🙏
I left some comments to also slim down the diff here a bit.
| public function getType(): QueryType | ||
| { | ||
| return QueryType::Text; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we only use that at exceptions right now? let's drop it then or do i miss something?
| 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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the assumption fair to use $query for both parts?
| * | ||
| * @author Johannes Wachter <johannes@sulu.io> | ||
| */ | ||
| enum QueryType: string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure we need that, do we?
| { | ||
| public function getType(): QueryType; | ||
|
|
||
| public function getFilter(): ?FilterInterface; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's go incremental and skip the filter part for the first PR - we can slice that, right?
| private readonly ?FilterInterface $filter = null, | ||
| ) { | ||
| if ($semanticRatio < 0.0 || $semanticRatio > 1.0) { | ||
| throw new \InvalidArgumentException(\sprintf('Semantic ratio must be between 0.0 and 1.0, got %.2f', $semanticRatio)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Symfony\AI\Store\Exception\InvalidArgumentException instead of native one
Description
This PR implements a query abstraction pattern for the Store component, enabling support for multiple query types (Vector, Text, Hybrid) with an integrated filter system. This addresses RFC #1562 and provides a flexible foundation for advanced retrieval use cases.
Summary of Changes
Query Abstraction
getType()andgetFilter()methodsVectorQuery: Classic vector similarity search (supported by all stores)TextQuery: Full-text search or internal vectorization (ChromaDB, Postgres, Cache)HybridQuery: Combined vector + text search with configurablesemanticRatioparameter (Postgres, ChromaDB, Cache)Filter System
getType()andtoArray()methodsStore Updates
Postgres Store - Extended to support all three query types:
ChromaDB Store - Extended to support all three query types:
Pinecone, Redis, Qdrant Stores - Vector only with filter support:
Cache Store - All query types with filter support:
API Changes
query(QueryInterface $query, array $options = [])signaturesupports(string $queryClass): boolmethod to check store capabilitiesUnsupportedQueryTypeExceptionthrown for unsupported query typesBreaking Changes
Store::query() Signature Change
Before:
After:
All existing code needs to wrap Vector objects in VectorQuery constructor.
Usage Examples
Vector Query with Filter
Text Query
Hybrid Query
Capability Checking