Harrison/new search (#4359)

Co-authored-by: Jiaping(JP) Zhang <vincentzhangv@gmail.com>
This commit is contained in:
Harrison Chase
2023-05-10 17:09:16 -07:00
committed by GitHub
parent 545ae8b756
commit 3ce29cb4a6
2 changed files with 77 additions and 13 deletions

View File

@@ -25,18 +25,10 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 2,
"id": "9fbcc58f",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Exiting: Cleaning up .chroma directory\n"
]
}
],
"outputs": [],
"source": [
"from langchain.text_splitter import CharacterTextSplitter\n",
"from langchain.vectorstores import FAISS\n",
@@ -74,6 +66,7 @@
"id": "79b783de",
"metadata": {},
"source": [
"## Maximum Marginal Relevance Retrieval\n",
"By default, the vectorstore retriever uses similarity search. If the underlying vectorstore support maximum marginal relevance search, you can specify that as the search type."
]
},
@@ -97,11 +90,42 @@
"docs = retriever.get_relevant_documents(\"what did he say abotu ketanji brown jackson\")"
]
},
{
"cell_type": "markdown",
"id": "2d958271",
"metadata": {},
"source": [
"## Similarity Score Threshold Retrieval\n",
"\n",
"You can also a retrieval method that sets a similarity score threshold and only returns documents with a score above that threshold"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d4272ad8",
"metadata": {},
"outputs": [],
"source": [
"retriever = db.as_retriever(search_type=\"similarity_score_threshold\", search_kwargs={\"score_threshold\": .5})"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "438e761d",
"metadata": {},
"outputs": [],
"source": [
"docs = retriever.get_relevant_documents(\"what did he say abotu ketanji brown jackson\")"
]
},
{
"cell_type": "markdown",
"id": "c23b7698",
"metadata": {},
"source": [
"## Specifying top k\n",
"You can also specify search kwargs like `k` to use when doing retrieval."
]
},
@@ -171,7 +195,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
"version": "3.9.1"
}
},
"nbformat": 4,