Skip to content

Commit 8f283d2

Browse files
Renames HybridQuery to AggregateHybridQuery (#112)
* renames HybridQuery to AggregateHybridQuery * updates minimum redisvl version
1 parent 1a3a4a8 commit 8f283d2

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

python-recipes/vector-search/01_redisvl.ipynb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
},
8383
"outputs": [],
8484
"source": [
85-
"%pip install -q \"redisvl>=0.6.0\" sentence-transformers pandas nltk"
85+
"%pip install -q \"redisvl>=0.11.0\" sentence-transformers pandas nltk"
8686
]
8787
},
8888
{
@@ -4431,9 +4431,9 @@
44314431
}
44324432
],
44334433
"source": [
4434-
"from redisvl.query import HybridQuery\n",
4434+
"from redisvl.query import AggregateHybridQuery\n",
44354435
"\n",
4436-
"hybrid_query = HybridQuery(\n",
4436+
"hybrid_query = AggregateHybridQuery(\n",
44374437
" text=user_query,\n",
44384438
" text_field_name=\"description\",\n",
44394439
" text_scorer=\"BM25\",\n",
@@ -4482,6 +4482,7 @@
44824482
},
44834483
"kernelspec": {
44844484
"display_name": "Python 3",
4485+
"language": "python",
44854486
"name": "python3"
44864487
},
44874488
"language_info": {

python-recipes/vector-search/02_hybrid_search.ipynb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"\n",
1010
"Hybrid search is all about combining lexical search with semantic vector search to improve result relevancy. This notebook will cover 3 different hybrid search strategies with Redis:\n",
1111
"\n",
12-
"1. Linear combination of scores from lexical search (BM25) and vector search (Cosine Distance) with the HybridQuery class\n",
12+
"1. Linear combination of scores from lexical search (BM25) and vector search (Cosine Distance) with the AggregateHybridQuery class\n",
1313
"2. Client-Side Reciprocal Rank Fusion (RRF)\n",
1414
"3. Client-Side Reranking with a cross encoder model\n",
1515
"\n",
@@ -32,7 +32,7 @@
3232
"metadata": {},
3333
"outputs": [],
3434
"source": [
35-
"%pip install sentence-transformers pandas nltk \"redisvl>=0.6.0\""
35+
"%pip install sentence-transformers pandas nltk \"redisvl>=0.11.0\""
3636
]
3737
},
3838
{
@@ -653,18 +653,18 @@
653653
"\n",
654654
"Now that our search index is populated and ready, we will build out a few different hybrid search techniques in Redis.\n",
655655
"\n",
656-
"To start, we will use our `HybridQuery` class that accepts a text string and vector to automatically combine text similarity and vector similarity scores."
656+
"To start, we will use our `AggregateHybridQuery` class that accepts a text string and vector to automatically combine text similarity and vector similarity scores."
657657
]
658658
},
659659
{
660660
"cell_type": "markdown",
661661
"metadata": {},
662662
"source": [
663-
"## 1. Linear Combination using HybridQuery\n",
663+
"## 1. Linear Combination using AggregateHybridQuery\n",
664664
"\n",
665665
"The goal of this technique is to calculate a weighted sum of the text similarity score for our provided text search and the cosine distance between vectors calculated via a KNN vector query. Under the hood this is possible in Redis using the [aggregations API](https://redis.io/docs/latest/develop/interact/search-and-query/advanced-concepts/aggregations/), as of `Redis 7.4.x` (search version `2.10.5`), within a single database call.\n",
666666
"\n",
667-
"As of RedisVl 0.5.0 all of this is nicely encapsulated in your `HybridQuery` class, which behaves much like our other query classes."
667+
"As of RedisVl 0.5.0 all of this is nicely encapsulated in your `AggregateHybridQuery` class, which behaves much like our other query classes."
668668
]
669669
},
670670
{
@@ -681,10 +681,10 @@
681681
"cell_type": "markdown",
682682
"metadata": {},
683683
"source": [
684-
"First, we will import our `HybridQuery` and understand its parameters.\n",
685-
"At a minimum, the `HybridQuery` needs 4 arguments:\n",
684+
"First, we will import our `AggregateHybridQuery` and understand its parameters.\n",
685+
"At a minimum, the `AggregateHybridQuery` needs 4 arguments:\n",
686686
"```python\n",
687-
"query = HybridQuery(\n",
687+
"query = AggregateHybridQuery(\n",
688688
" text = \"your query string here\",\n",
689689
" text_field_name = \"<name of the text field in the index to do text search in>\",\n",
690690
" vector = <bytes or numeric array, ex: [0.1, 0.2, 0.3]>,\n",
@@ -738,11 +738,11 @@
738738
}
739739
],
740740
"source": [
741-
"from redisvl.query import HybridQuery\n",
741+
"from redisvl.query import AggregateHybridQuery\n",
742742
"\n",
743743
"vector = model.embed(user_query, as_buffer=True)\n",
744744
"\n",
745-
"query = HybridQuery(\n",
745+
"query = AggregateHybridQuery(\n",
746746
" text=user_query,\n",
747747
" text_field_name=\"description\",\n",
748748
" vector=vector,\n",
@@ -760,7 +760,7 @@
760760
"metadata": {},
761761
"source": [
762762
"That's it! That is all it takes to perform a hybrid text matching and vector query with RedisVL.\n",
763-
"Of course there are many more configurations and things we can do with the `HybridQuery` class. Let's investigate.\n",
763+
"Of course there are many more configurations and things we can do with the `AggregateHybridQuery` class. Let's investigate.\n",
764764
"\n",
765765
"First, let's look at just the text query part that is being run:"
766766
]
@@ -828,7 +828,7 @@
828828
"# translate our user query to French and use nltk french stopwords\n",
829829
"french_query_text = \"Film d'action et d'aventure avec de superbes scènes de combat, des enquêtes criminelles, des super-héros et de la magie\"\n",
830830
"\n",
831-
"french_film_query = HybridQuery(\n",
831+
"french_film_query = AggregateHybridQuery(\n",
832832
" text=french_query_text,\n",
833833
" text_field_name=\"description\",\n",
834834
" vector=model.embed(french_query_text, as_buffer=True),\n",
@@ -845,7 +845,7 @@
845845
" \"then\", \"there\", \"these\", \"they\", \"this\", \"to\", \"was\", \"will\", \"with\"\n",
846846
"])\n",
847847
"\n",
848-
"stopwords_query = HybridQuery(\n",
848+
"stopwords_query = AggregateHybridQuery(\n",
849849
" text=user_query,\n",
850850
" text_field_name=\"description\",\n",
851851
" vector=vector,\n",
@@ -856,7 +856,7 @@
856856
"print(stopwords_query._build_query_string())\n",
857857
"\n",
858858
"# don't use any stopwords\n",
859-
"no_stopwords_query = HybridQuery(\n",
859+
"no_stopwords_query = AggregateHybridQuery(\n",
860860
" text=user_query,\n",
861861
" text_field_name=\"description\",\n",
862862
" vector=vector,\n",
@@ -919,7 +919,7 @@
919919
}
920920
],
921921
"source": [
922-
"tfidf_query = HybridQuery(\n",
922+
"tfidf_query = AggregateHybridQuery(\n",
923923
" text=user_query,\n",
924924
" text_field_name=\"description\",\n",
925925
" vector=vector,\n",
@@ -1333,7 +1333,7 @@
13331333
"source": [
13341334
"def hybrid_query(text, alpha, num_results) -> List[Dict[str, Any]]:\n",
13351335
"\n",
1336-
" query = HybridQuery(\n",
1336+
" query = AggregateHybridQuery(\n",
13371337
" text,\n",
13381338
" text_field_name=\"description\",\n",
13391339
" vector=model.embed(text, as_buffer=True),\n",

0 commit comments

Comments
 (0)