WIP: Harrison/base retriever (#1765)

This commit is contained in:
Harrison Chase
2023-03-24 07:46:49 -07:00
committed by GitHub
parent 4f364db9a9
commit 47d37db2d2
25 changed files with 509 additions and 339 deletions

View File

@@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 1,
"id": "2e87c10a",
"metadata": {},
"outputs": [],
@@ -30,13 +30,14 @@
"from langchain.embeddings.openai import OpenAIEmbeddings\n",
"from langchain.vectorstores import Chroma\n",
"from langchain.text_splitter import CharacterTextSplitter\n",
"from langchain import OpenAI, VectorDBQA\n",
"from langchain.llms import OpenAI\n",
"from langchain.chains import RetrievalQA\n",
"llm = OpenAI(temperature=0)"
]
},
{
"cell_type": "code",
"execution_count": 37,
"execution_count": 2,
"id": "f2675861",
"metadata": {},
"outputs": [
@@ -62,17 +63,17 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 4,
"id": "bc5403d4",
"metadata": {},
"outputs": [],
"source": [
"state_of_union = VectorDBQA.from_chain_type(llm=llm, chain_type=\"stuff\", vectorstore=docsearch)"
"state_of_union = RetrievalQA.from_chain_type(llm=llm, chain_type=\"stuff\", retriever=docsearch.as_retriever())"
]
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 5,
"id": "1431cded",
"metadata": {},
"outputs": [],
@@ -82,7 +83,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 6,
"id": "915d3ff3",
"metadata": {},
"outputs": [],
@@ -92,7 +93,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 7,
"id": "96a2edf8",
"metadata": {},
"outputs": [
@@ -109,7 +110,7 @@
"docs = loader.load()\n",
"ruff_texts = text_splitter.split_documents(docs)\n",
"ruff_db = Chroma.from_documents(ruff_texts, embeddings, collection_name=\"ruff\")\n",
"ruff = VectorDBQA.from_chain_type(llm=llm, chain_type=\"stuff\", vectorstore=ruff_db)"
"ruff = RetrievalQA.from_chain_type(llm=llm, chain_type=\"stuff\", retriever=ruff_db.as_retriever())"
]
},
{
@@ -264,9 +265,9 @@
"id": "9161ba91",
"metadata": {},
"source": [
"You can also set `return_direct=True` if you intend to use the agent as a router and just want to directly return the result of the VectorDBQaChain.\n",
"You can also set `return_direct=True` if you intend to use the agent as a router and just want to directly return the result of the RetrievalQAChain.\n",
"\n",
"Notice that in the above examples the agent did some extra work after querying the VectorDBQAChain. You can avoid that and just return the result directly."
"Notice that in the above examples the agent did some extra work after querying the RetrievalQAChain. You can avoid that and just return the result directly."
]
},
{