Skip to content

Commit 1605b88

Browse files
rbs333Copilot
andauthored
Feat/raae 1322/hybrid support (#639)
Adds ft.hybrid support to SQL query. This ships as part of sql-redis 0.7.0 release. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Introduces a new search path (FT.HYBRID) behind stricter Redis/redis-py/sql-redis version requirements; incorrect docs or dependency pins could mislead adopters, but runtime code changes are minimal. > > **Overview** > Documents **SQL hybrid search** via `hybrid_vector_search(cosine_distance(...), fulltext(...), rrf()|linear())`, which maps to Redis **`FT.HYBRID`** through the upgraded **`sql-redis`** dependency (now **`>=0.7.1`** in `pyproject.toml` and the lockfile). > > Coverage spans the **`SQLQuery`** docstring, API/concepts docs, and a new notebook section with an executable example. **Integration tests** exercise RRF and linear fusion, `WHERE` filters, RRF knobs, `redis_query_string()` output, and async `AsyncSearchIndex`—all gated on Redis **8.4+** and **redis-py >= 7.1.0**. > > No new RedisVL translation logic in this PR; behavior comes from **sql-redis 0.7.x** on the existing `SQLQuery` → `index.query()` path. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit 1e5bad8. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 12e6357 commit 1605b88

7 files changed

Lines changed: 2198 additions & 1849 deletions

File tree

docs/api/query.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,3 +261,9 @@ SQLQuery
261261
narrow queries cheaper.
262262
- ``"load_all"`` eagerly loads all schemas up front, which can help when
263263
running many SQL queries across many indexes.
264+
265+
.. note::
266+
SQLQuery supports hybrid search via ``hybrid_vector_search(cosine_distance(...), fulltext(...), rrf())``, which translates to a native Redis ``FT.HYBRID`` command
267+
fusing a text and a vector query server-side. This is the SQL front-end to
268+
:class:`HybridQuery` and requires ``sql-redis >= 0.7.0``, Redis 8.4+, and
269+
redis-py >= 7.1.0.

docs/concepts/queries.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,27 @@ query = SQLQuery("""
273273
""", params={"vec": embedding_bytes})
274274
```
275275

276+
**Hybrid search (FT.HYBRID)** fuses a text query and a vector query server-side
277+
with `hybrid_vector_search()`, composing `cosine_distance()` (vector leg) and
278+
`fulltext()` (text leg) with `rrf()` or `linear()` fusion. This is the SQL
279+
front-end to the native `HybridQuery` (above):
280+
281+
```python
282+
query = SQLQuery("""
283+
SELECT title,
284+
hybrid_vector_search(
285+
cosine_distance(embedding, :vec),
286+
fulltext(description, 'gaming laptop'),
287+
rrf()
288+
) AS hybrid_score
289+
FROM products
290+
ORDER BY hybrid_score DESC
291+
LIMIT 5
292+
""", params={"vec": embedding_bytes})
293+
```
294+
295+
Requires Redis 8.4+ and `redis-py >= 7.1.0`.
296+
276297
Use when your team is more comfortable with SQL syntax, or when integrating with tools that generate SQL.
277298

278299
```{note}

0 commit comments

Comments
 (0)