tfidf retriever (#5114)

Co-authored-by: vempaliakhil96 <vempaliakhil96@gmail.com>
This commit is contained in:
Davis Chase
2023-05-24 10:02:09 -07:00
committed by GitHub
parent b00c77dc62
commit 2b2176a3c1
5 changed files with 80 additions and 26 deletions

View File

@@ -16,17 +16,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "a801b57c",
"metadata": {},
"outputs": [],
"source": [
"# !pip install scikit-learn"
"# !pip install scikit-learn\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "393ac030",
"metadata": {
"tags": []
@@ -46,7 +46,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "98b1c017",
"metadata": {
"tags": []
@@ -56,6 +56,27 @@
"retriever = TFIDFRetriever.from_texts([\"foo\", \"bar\", \"world\", \"hello\", \"foo bar\"])"
]
},
{
"cell_type": "markdown",
"id": "c016b266",
"metadata": {},
"source": [
"## Create a New Retriever with Documents\n",
"\n",
"You can now create a new retriever with the documents you created."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "53af4f00",
"metadata": {},
"outputs": [],
"source": [
"from langchain.schema import Document\n",
"retriever = TFIDFRetriever.from_documents([Document(page_content=\"foo\"), Document(page_content=\"bar\"), Document(page_content=\"world\"), Document(page_content=\"hello\"), Document(page_content=\"foo bar\")])"
]
},
{
"cell_type": "markdown",
"id": "08437fa2",
@@ -68,7 +89,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 6,
"id": "c0455218",
"metadata": {
"tags": []
@@ -80,7 +101,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 7,
"id": "7dfa5c29",
"metadata": {
"tags": []
@@ -95,7 +116,7 @@
" Document(page_content='world', metadata={})]"
]
},
"execution_count": 6,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
@@ -103,14 +124,6 @@
"source": [
"result"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "74bd9256",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
@@ -129,7 +142,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.6"
"version": "3.11.3"
}
},
"nbformat": 4,