Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions python-recipes/vector-search/01_redisvl.ipynb
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably on your checklist but we will need to change the pin version for redisvl in this notebook for the new release otherwise it'll bomb on import.

Original file line number Diff line number Diff line change
Expand Up @@ -4431,9 +4431,9 @@
}
],
"source": [
"from redisvl.query import HybridQuery\n",
"from redisvl.query import AggregateHybridQuery\n",
"\n",
"hybrid_query = HybridQuery(\n",
"hybrid_query = AggregateHybridQuery(\n",
" text=user_query,\n",
" text_field_name=\"description\",\n",
" text_scorer=\"BM25\",\n",
Expand Down
30 changes: 15 additions & 15 deletions python-recipes/vector-search/02_hybrid_search.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"\n",
"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",
"\n",
"1. Linear combination of scores from lexical search (BM25) and vector search (Cosine Distance) with the HybridQuery class\n",
"1. Linear combination of scores from lexical search (BM25) and vector search (Cosine Distance) with the AggregateHybridQuery class\n",
"2. Client-Side Reciprocal Rank Fusion (RRF)\n",
"3. Client-Side Reranking with a cross encoder model\n",
"\n",
Expand Down Expand Up @@ -653,18 +653,18 @@
"\n",
"Now that our search index is populated and ready, we will build out a few different hybrid search techniques in Redis.\n",
"\n",
"To start, we will use our `HybridQuery` class that accepts a text string and vector to automatically combine text similarity and vector similarity scores."
"To start, we will use our `AggregateHybridQuery` class that accepts a text string and vector to automatically combine text similarity and vector similarity scores."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1. Linear Combination using HybridQuery\n",
"## 1. Linear Combination using AggregateHybridQuery\n",
"\n",
"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",
"\n",
"As of RedisVl 0.5.0 all of this is nicely encapsulated in your `HybridQuery` class, which behaves much like our other query classes."
"As of RedisVl 0.5.0 all of this is nicely encapsulated in your `AggregateHybridQuery` class, which behaves much like our other query classes."
]
},
{
Expand All @@ -681,10 +681,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"First, we will import our `HybridQuery` and understand its parameters.\n",
"At a minimum, the `HybridQuery` needs 4 arguments:\n",
"First, we will import our `AggregateHybridQuery` and understand its parameters.\n",
"At a minimum, the `AggregateHybridQuery` needs 4 arguments:\n",
"```python\n",
"query = HybridQuery(\n",
"query = AggregateHybridQuery(\n",
" text = \"your query string here\",\n",
" text_field_name = \"<name of the text field in the index to do text search in>\",\n",
" vector = <bytes or numeric array, ex: [0.1, 0.2, 0.3]>,\n",
Expand Down Expand Up @@ -738,11 +738,11 @@
}
],
"source": [
"from redisvl.query import HybridQuery\n",
"from redisvl.query import AggregateHybridQuery\n",
"\n",
"vector = model.embed(user_query, as_buffer=True)\n",
"\n",
"query = HybridQuery(\n",
"query = AggregateHybridQuery(\n",
" text=user_query,\n",
" text_field_name=\"description\",\n",
" vector=vector,\n",
Expand All @@ -760,7 +760,7 @@
"metadata": {},
"source": [
"That's it! That is all it takes to perform a hybrid text matching and vector query with RedisVL.\n",
"Of course there are many more configurations and things we can do with the `HybridQuery` class. Let's investigate.\n",
"Of course there are many more configurations and things we can do with the `AggregateHybridQuery` class. Let's investigate.\n",
"\n",
"First, let's look at just the text query part that is being run:"
]
Expand Down Expand Up @@ -828,7 +828,7 @@
"# translate our user query to French and use nltk french stopwords\n",
"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",
"\n",
"french_film_query = HybridQuery(\n",
"french_film_query = AggregateHybridQuery(\n",
" text=french_query_text,\n",
" text_field_name=\"description\",\n",
" vector=model.embed(french_query_text, as_buffer=True),\n",
Expand All @@ -845,7 +845,7 @@
" \"then\", \"there\", \"these\", \"they\", \"this\", \"to\", \"was\", \"will\", \"with\"\n",
"])\n",
"\n",
"stopwords_query = HybridQuery(\n",
"stopwords_query = AggregateHybridQuery(\n",
" text=user_query,\n",
" text_field_name=\"description\",\n",
" vector=vector,\n",
Expand All @@ -856,7 +856,7 @@
"print(stopwords_query._build_query_string())\n",
"\n",
"# don't use any stopwords\n",
"no_stopwords_query = HybridQuery(\n",
"no_stopwords_query = AggregateHybridQuery(\n",
" text=user_query,\n",
" text_field_name=\"description\",\n",
" vector=vector,\n",
Expand Down Expand Up @@ -919,7 +919,7 @@
}
],
"source": [
"tfidf_query = HybridQuery(\n",
"tfidf_query = AggregateHybridQuery(\n",
" text=user_query,\n",
" text_field_name=\"description\",\n",
" vector=vector,\n",
Expand Down Expand Up @@ -1333,7 +1333,7 @@
"source": [
"def hybrid_query(text, alpha, num_results) -> List[Dict[str, Any]]:\n",
"\n",
" query = HybridQuery(\n",
" query = AggregateHybridQuery(\n",
" text,\n",
" text_field_name=\"description\",\n",
" vector=model.embed(text, as_buffer=True),\n",
Expand Down
Loading