Skip to content

feat(hybrid): support facets on fused hybrid results - #4932

Open
donhardman wants to merge 3 commits into
mainfrom
fix/facet-combo
Open

donhardman wants to merge 3 commits into
mainfrom
fix/facet-combo

Conversation

@donhardman

Copy link
Copy Markdown
Member

FACET / aggs in hybrid search (fusion_method='rrf') — closes #4928

CREATE TABLE t (title text, cat int, vec float_vector knn_type='hnsw' knn_dims='4' hnsw_similarity='l2');
INSERT INTO t (id,title,cat,vec) VALUES
 (1,'machine learning basics',1,(0.1,0.1,0.1,0.1)),(2,'deep learning',1,(0.2,0.1,0.1,0.1)),
 (3,'cooking pasta',2,(0.1,0.1,0.1,0.15)),(4,'machine repair',2,(0.9,0.9,0.9,0.9)),
 (5,'gardening',3,(0.5,0.5,0.5,0.5)),(6,'learning to cook',3,(0.8,0.8,0.8,0.8));

SELECT id FROM t WHERE match('learning') AND knn(vec,(0.1,0.1,0.1,0.1)) LIMIT 3
OPTION fusion_method='rrf' FACET cat;

SELECT id, hybrid_score() hs FROM t WHERE match('learning') AND knn(vec,(0.1,0.1,0.1,0.1)) AND hs > 0.02
OPTION fusion_method='rrf' FACET cat;

Before

ERROR 1064 (42000): table t: hybrid search does not support multiple sorters
ERROR 1064 (42000): table t: HYBRID_SCORE() is only allowed for hybrid search queries

JSON aggs in a hybrid /search request failed the same way.

After: facets count all fused documents (not only the LIMIT page), after post-fusion filters:

+------+----------+          +------+----------+
| cat  | count(*) |          | cat  | count(*) |
+------+----------+          +------+----------+
|    1 |        2 |          |    1 |        2 |
|    2 |        2 |          |    3 |        1 |
|    3 |        2 |          +------+----------+
+------+----------+          (hs > 0.02 keeps docs 1, 2, 6)

facet_filter_mode, FILTERS/EXCLUDE FILTERS, GROUP BY, DISTINCT, JOIN, and distributed tables are supported. Test: test/test_537. Manual: Searching → Hybrid search → Facets.

Hybrid queries now execute facets and JSON aggregations over fused
documents, with counts reflecting post-fusion filtering. Facet
processing runs after RRF fusion completes.

- Execute facet and JSON aggregation passes after hybrid fusion
- Restrict facet candidates to documents passing post-fusion filters
- Run hybrid facet processing sequentially and propagate query settings
- Document hybrid facet behavior, filtering, and execution examples
@sanikolaev
sanikolaev requested a review from glookka September 24, 2026 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FACET can't be used in a hybrid query (fusion_method='rrf')

3 participants