Skip to content

Commit

Permalink
docs: fix import path for FlashrankRerank example notebook (langcha…
Browse files Browse the repository at this point in the history
…in-ai#19146)

**Description:** Fixes the import paths for the `FlashrankRerank`
example notebook.
 **Issue:** langchain-ai#19139 
 **Dependencies:** None
 **Twitter handle:** n/a

---------

Co-authored-by: Simon Stone <[email protected]>
Co-authored-by: Bagatur <[email protected]>
  • Loading branch information
3 people authored Mar 19, 2024
1 parent bde199d commit dc4ce82
Showing 1 changed file with 48 additions and 41 deletions.
89 changes: 48 additions & 41 deletions docs/docs/integrations/retrievers/flashrank-reranker.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@
},
"outputs": [],
"source": [
"% pip install --upgrade --quiet flashrank\n",
"% pip install --upgrade --quiet faiss\n",
"%pip install --upgrade --quiet flashrank\n",
"%pip install --upgrade --quiet faiss\n",
"\n",
"# OR (depending on Python version)\n",
"\n",
"% pip install --upgrade --quiet faiss_cpu"
"%pip install --upgrade --quiet faiss_cpu"
]
},
{
"cell_type": "code",
"execution_count": 13,
"execution_count": 2,
"metadata": {
"collapsed": false,
"jupyter": {
Expand Down Expand Up @@ -73,7 +73,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {
"collapsed": false,
"jupyter": {
Expand All @@ -90,7 +90,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 4,
"metadata": {
"collapsed": false,
"jupyter": {
Expand Down Expand Up @@ -247,14 +247,6 @@
"----------------------------------------------------------------------------------------------------\n",
"Document 15:\n",
"\n",
"My plan to fight inflation will lower your costs and lower the deficit. \n",
"\n",
"17 Nobel laureates in economics say my plan will ease long-term inflationary pressures. Top business leaders and most Americans support my plan. And here’s the plan: \n",
"\n",
"First – cut the cost of prescription drugs. Just look at insulin. One in ten Americans has diabetes. In Virginia, I met a 13-year-old boy named Joshua Davis.\n",
"----------------------------------------------------------------------------------------------------\n",
"Document 16:\n",
"\n",
"And soon, we’ll strengthen the Violence Against Women Act that I first wrote three decades ago. It is important for us to show the nation that we can come together and do big things. \n",
"\n",
"So tonight I’m offering a Unity Agenda for the Nation. Four big things we can do together. \n",
Expand All @@ -263,15 +255,15 @@
"\n",
"There is so much we can do. Increase funding for prevention, treatment, harm reduction, and recovery.\n",
"----------------------------------------------------------------------------------------------------\n",
"Document 17:\n",
"Document 16:\n",
"\n",
"So let’s not abandon our streets. Or choose between safety and equal justice. \n",
"My plan to fight inflation will lower your costs and lower the deficit. \n",
"\n",
"Let’s come together to protect our communities, restore trust, and hold law enforcement accountable. \n",
"17 Nobel laureates in economics say my plan will ease long-term inflationary pressures. Top business leaders and most Americans support my plan. And here’s the plan: \n",
"\n",
"That’s why the Justice Department required body cameras, banned chokeholds, and restricted no-knock warrants for its officers.\n",
"First – cut the cost of prescription drugs. Just look at insulin. One in ten Americans has diabetes. In Virginia, I met a 13-year-old boy named Joshua Davis.\n",
"----------------------------------------------------------------------------------------------------\n",
"Document 18:\n",
"Document 17:\n",
"\n",
"My plan will not only lower costs to give families a fair shot, it will lower the deficit. \n",
"\n",
Expand All @@ -281,6 +273,14 @@
"\n",
"We’re going after the criminals who stole billions in relief money meant for small businesses and millions of Americans.\n",
"----------------------------------------------------------------------------------------------------\n",
"Document 18:\n",
"\n",
"So let’s not abandon our streets. Or choose between safety and equal justice. \n",
"\n",
"Let’s come together to protect our communities, restore trust, and hold law enforcement accountable. \n",
"\n",
"That’s why the Justice Department required body cameras, banned chokeholds, and restricted no-knock warrants for its officers.\n",
"----------------------------------------------------------------------------------------------------\n",
"Document 19:\n",
"\n",
"I understand. \n",
Expand Down Expand Up @@ -340,16 +340,25 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {
"collapsed": false,
"jupyter": {
"outputs_hidden": false
}
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[0, 5, 3]\n"
]
}
],
"source": [
"from langchain.retrievers import ContextualCompressionRetriever, FlashrankRerank\n",
"from langchain.retrievers import ContextualCompressionRetriever\n",
"from langchain.retrievers.document_compressors import FlashrankRerank\n",
"from langchain_openai import ChatOpenAI\n",
"\n",
"llm = ChatOpenAI(temperature=0)\n",
Expand Down Expand Up @@ -379,7 +388,7 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 6,
"metadata": {
"collapsed": false,
"jupyter": {
Expand All @@ -399,29 +408,27 @@
"----------------------------------------------------------------------------------------------------\n",
"Document 2:\n",
"\n",
"And tonight, I’m announcing that the Justice Department will name a chief prosecutor for pandemic fraud. \n",
"\n",
"By the end of this year, the deficit will be down to less than half what it was before I took office. \n",
"\n",
"The only president ever to cut the deficit by more than one trillion dollars in a single year. \n",
"He met the Ukrainian people. \n",
"\n",
"Lowering your costs also means demanding more competition. \n",
"From President Zelenskyy to every Ukrainian, their fearlessness, their courage, their determination, inspires the world. \n",
"\n",
"I’m a capitalist, but capitalism without competition isn’t capitalism. \n",
"Groups of citizens blocking tanks with their bodies. Everyone from students to retirees teachers turned soldiers defending their homeland. \n",
"\n",
"It’s exploitation—and it drives up prices.\n",
"In this struggle as President Zelenskyy said in his speech to the European Parliament “Light will win over darkness.” The Ukrainian Ambassador to the United States is here tonight.\n",
"----------------------------------------------------------------------------------------------------\n",
"Document 3:\n",
"\n",
"As Ohio Senator Sherrod Brown says, “It’s time to bury the label “Rust Belt.” \n",
"And tonight, I’m announcing that the Justice Department will name a chief prosecutor for pandemic fraud. \n",
"\n",
"It’s time. \n",
"By the end of this year, the deficit will be down to less than half what it was before I took office. \n",
"\n",
"But with all the bright spots in our economy, record job growth and higher wages, too many families are struggling to keep up with the bills. \n",
"The only president ever to cut the deficit by more than one trillion dollars in a single year. \n",
"\n",
"Inflation is robbing them of the gains they might otherwise feel. \n",
"Lowering your costs also means demanding more competition. \n",
"\n",
"I’m a capitalist, but capitalism without competition isn’t capitalism. \n",
"\n",
"I get it. That’s why my top priority is getting prices under control.\n"
"It’s exploitation—and it drives up prices.\n"
]
}
],
Expand All @@ -443,7 +450,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 7,
"metadata": {
"collapsed": false,
"jupyter": {
Expand All @@ -459,7 +466,7 @@
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 8,
"metadata": {
"collapsed": false,
"jupyter": {
Expand All @@ -471,10 +478,10 @@
"data": {
"text/plain": [
"{'query': 'What did the president say about Ketanji Brown Jackson',\n",
" 'result': \"The President said that Ketanji Brown Jackson is one of our nation's top legal minds and will continue Justice Breyer's legacy of excellence.\"}"
" 'result': \"The President mentioned that Ketanji Brown Jackson is one of the nation's top legal minds and will continue Justice Breyer's legacy of excellence.\"}"
]
},
"execution_count": 19,
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -500,7 +507,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.12.2"
}
},
"nbformat": 4,
Expand Down

0 comments on commit dc4ce82

Please sign in to comment.