Implemented MMR search for Redis (#10140)

Description: Implemented MMR search for Redis. Pretty straightforward,
just using the already implemented MMR method on similarity
search–fetched docs.
Issue: #10059
Dependencies: None
Twitter handle: @hamza_tahboub

---------

Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
Hamza Tahboub
2023-09-08 15:14:44 -07:00
committed by GitHub
parent 5d8a689d5e
commit 8c0f391815
4 changed files with 179 additions and 14 deletions

View File

@@ -413,7 +413,8 @@
"- ``similarity_search``: Find the most similar vectors to a given vector.\n",
"- ``similarity_search_with_score``: Find the most similar vectors to a given vector and return the vector distance\n",
"- ``similarity_search_limit_score``: Find the most similar vectors to a given vector and limit the number of results to the ``score_threshold``\n",
"- ``similarity_search_with_relevance_scores``: Find the most similar vectors to a given vector and return the vector similarities"
"- ``similarity_search_with_relevance_scores``: Find the most similar vectors to a given vector and return the vector similarities\n",
"- ``max_marginal_relevance_search``: Find the most similar vectors to a given vector while also optimizing for diversity"
]
},
{
@@ -596,6 +597,26 @@
"print(results[0].metadata)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# use maximal marginal relevance search to diversify results\n",
"results = rds.max_marginal_relevance_search(\"foo\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# the lambda_mult parameter controls the diversity of the results, the lower the more diverse\n",
"results = rds.max_marginal_relevance_search(\"foo\", lambda_mult=0.1)"
]
},
{
"cell_type": "markdown",
"metadata": {},