The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
Community: RankLLMRerank AttributeError (Handle list-based rerank results) (#29840)
Brayden Zhonga70f31de5ffb
diff --git a/docs/docs/integrations/document_transformers/rankllm-reranker.ipynb b/docs/docs/integrations/document_transformers/rankllm-reranker.ipynbindex 764b33edb8..6875e86fe8 100644--- a/docs/docs/integrations/document_transformers/rankllm-reranker.ipynb+++ b/docs/docs/integrations/document_transformers/rankllm-reranker.ipynb@@ -88,13 +88,13 @@"from langchain_openai import OpenAIEmbeddings\n","from langchain_text_splitters import RecursiveCharacterTextSplitter\n","\n",- "documents = TextLoader(\"../../modules/state_of_the_union.txt\").load()\n",+ "documents = TextLoader(\"../document_loaders/example_data/state_of_the_union.txt\").load()\n","text_splitter = RecursiveCharacterTextSplitter(chunk_size=500, chunk_overlap=100)\n","texts = text_splitter.split_documents(documents)\n","for idx, text in enumerate(texts):\n"," text.metadata[\"id\"] = idx\n","\n",- "embedding = OpenAIEmbeddings(model=\"text-embedding-ada-002\")\n",+ "embedding = OpenAIEmbeddings(model=\"text-embedding-3-large\")\n","retriever = FAISS.from_documents(texts, embedding).as_retriever(search_kwargs={\"k\": 20})"]},@@ -114,25 +114,22 @@},{"cell_type": "code",- "execution_count": 7,+ "execution_count": 23,"metadata": {},"outputs": [+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "2025-02-17 04:37:08,458 - INFO - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n"+ ]+ },{"name": "stdout","output_type": "stream","text": ["Document 1:\n","\n",- "And with an unwavering resolve that freedom will always triumph over tyranny. \n",- "\n",- "Six days ago, Russia’s Vladimir Putin sought to shake the foundations of the free world thinking he could make it bend to his menacing ways. But he badly miscalculated. \n",- "\n",- "He thought he could roll into Ukraine and the world would roll over. Instead he met a wall of strength he never imagined. \n",- "\n",- "He met the Ukrainian people.\n",- "----------------------------------------------------------------------------------------------------\n",- "Document 2:\n",- "\n","Together with our allies –we are right now enforcing powerful economic sanctions. \n","\n","We are cutting off Russia’s largest banks from the international financial system. \n",@@ -141,12 +138,22 @@"\n","We are choking off Russia’s access to technology that will sap its economic strength and weaken its military for years to come.\n","----------------------------------------------------------------------------------------------------\n",- "Document 3:\n",+ "Document 2:\n","\n","And tonight I am announcing that we will join our allies in closing off American air space to all Russian flights – further isolating Russia – and adding an additional squeeze –on their economy. The Ruble has lost 30% of its value. \n","\n","The Russian stock market has lost 40% of its value and trading remains suspended. Russia’s economy is reeling and Putin alone is to blame.\n","----------------------------------------------------------------------------------------------------\n",+ "Document 3:\n",+ "\n",+ "And now that he has acted the free world is holding him accountable. \n",+ "\n",+ "Along with twenty-seven members of the European Union including France, Germany, Italy, as well as countries like the United Kingdom, Canada, Japan, Korea, Australia, New Zealand, and many others, even Switzerland. \n",+ "\n",+ "We are inflicting pain on Russia and supporting the people of Ukraine. Putin is now isolated from the world more than ever. \n",+ "\n",+ "Together with our allies –we are right now enforcing powerful economic sanctions.\n",+ "----------------------------------------------------------------------------------------------------\n","Document 4:\n","\n","I spent countless hours unifying our European allies. We shared with the world in advance what we knew Putin was planning and precisely how he would try to falsely justify his aggression. \n",@@ -167,37 +174,43 @@"----------------------------------------------------------------------------------------------------\n","Document 6:\n","\n",- "And now that he has acted the free world is holding him accountable. \n",- "\n",- "Along with twenty-seven members of the European Union including France, Germany, Italy, as well as countries like the United Kingdom, Canada, Japan, Korea, Australia, New Zealand, and many others, even Switzerland. \n",+ "To all Americans, I will be honest with you, as I’ve always promised. A Russian dictator, invading a foreign country, has costs around the world. \n","\n",- "We are inflicting pain on Russia and supporting the people of Ukraine. Putin is now isolated from the world more than ever. \n",+ "And I’m taking robust action to make sure the pain of our sanctions is targeted at Russia’s economy. And I will use every tool at our disposal to protect American businesses and consumers. \n","\n",- "Together with our allies –we are right now enforcing powerful economic sanctions.\n",+ "Tonight, I can announce that the United States has worked with 30 other countries to release 60 Million barrels of oil from reserves around the world.\n","----------------------------------------------------------------------------------------------------\n","Document 7:\n","\n",- "To all Americans, I will be honest with you, as I’ve always promised. A Russian dictator, invading a foreign country, has costs around the world. \n",+ "And with an unwavering resolve that freedom will always triumph over tyranny. \n","\n",- "And I’m taking robust action to make sure the pain of our sanctions is targeted at Russia’s economy. And I will use every tool at our disposal to protect American businesses and consumers. \n",+ "Six days ago, Russia’s Vladimir Putin sought to shake the foundations of the free world thinking he could make it bend to his menacing ways. But he badly miscalculated. \n","\n",- "Tonight, I can announce that the United States has worked with 30 other countries to release 60 Million barrels of oil from reserves around the world.\n",+ "He thought he could roll into Ukraine and the world would roll over. Instead he met a wall of strength he never imagined. \n",+ "\n",+ "He met the Ukrainian people.\n","----------------------------------------------------------------------------------------------------\n","Document 8:\n","\n",- "And we remain clear-eyed. The Ukrainians are fighting back with pure courage. But the next few days weeks, months, will be hard on them. \n",+ "They keep moving. \n","\n",- "Putin has unleashed violence and chaos. But while he may make gains on the battlefield – he will pay a continuing high price over the long run. \n",+ "And the costs and the threats to America and the world keep rising. \n","\n",- "And a proud Ukrainian people, who have known 30 years of independence, have repeatedly shown that they will not tolerate anyone who tries to take their country backwards.\n",+ "That’s why the NATO Alliance was created to secure peace and stability in Europe after World War 2. \n",+ "\n",+ "The United States is a member along with 29 other nations. \n",+ "\n",+ "It matters. American diplomacy matters. American resolve matters. \n",+ "\n",+ "Putin’s latest attack on Ukraine was premeditated and unprovoked. \n",+ "\n",+ "He rejected repeated efforts at diplomacy.\n","----------------------------------------------------------------------------------------------------\n","Document 9:\n","\n",- "Tonight I say to the Russian oligarchs and corrupt leaders who have bilked billions of dollars off this violent regime no more. \n",- "\n",- "The U.S. Department of Justice is assembling a dedicated task force to go after the crimes of Russian oligarchs. \n",+ "While it shouldn’t have taken something so terrible for people around the world to see what’s at stake now everyone sees it clearly. \n","\n",- "We are joining with our European allies to find and seize your yachts your luxury apartments your private jets. We are coming for your ill-begotten gains.\n",+ "We see the unity among leaders of nations and a more unified Europe a more unified West. And we see unity among the people who are gathering in cities in large crowds around the world even in Russia to demonstrate their support for Ukraine.\n","----------------------------------------------------------------------------------------------------\n","Document 10:\n","\n",@@ -211,103 +224,100 @@"----------------------------------------------------------------------------------------------------\n","Document 11:\n","\n",- "They keep moving. \n",- "\n",- "And the costs and the threats to America and the world keep rising. \n",- "\n",- "That’s why the NATO Alliance was created to secure peace and stability in Europe after World War 2. \n",- "\n",- "The United States is a member along with 29 other nations. \n",- "\n",- "It matters. American diplomacy matters. American resolve matters. \n",+ "Tonight I say to the Russian oligarchs and corrupt leaders who have bilked billions of dollars off this violent regime no more. \n","\n",- "Putin’s latest attack on Ukraine was premeditated and unprovoked. \n",+ "The U.S. Department of Justice is assembling a dedicated task force to go after the crimes of Russian oligarchs. \n","\n",- "He rejected repeated efforts at diplomacy.\n",+ "We are joining with our European allies to find and seize your yachts your luxury apartments your private jets. We are coming for your ill-begotten gains.\n","----------------------------------------------------------------------------------------------------\n","Document 12:\n","\n",- "Our forces are not going to Europe to fight in Ukraine, but to defend our NATO Allies – in the event that Putin decides to keep moving west. \n",+ "And we remain clear-eyed. The Ukrainians are fighting back with pure courage. But the next few days weeks, months, will be hard on them. \n","\n",- "For that purpose we’ve mobilized American ground forces, air squadrons, and ship deployments to protect NATO countries including Poland, Romania, Latvia, Lithuania, and Estonia. \n",+ "Putin has unleashed violence and chaos. But while he may make gains on the battlefield – he will pay a continuing high price over the long run. \n","\n",- "As I have made crystal clear the United States and our Allies will defend every inch of territory of NATO countries with the full force of our collective power.\n",+ "And a proud Ukrainian people, who have known 30 years of independence, have repeatedly shown that they will not tolerate anyone who tries to take their country backwards.\n","----------------------------------------------------------------------------------------------------\n","Document 13:\n","\n",- "While it shouldn’t have taken something so terrible for people around the world to see what’s at stake now everyone sees it clearly. \n",+ "Let each of us here tonight in this Chamber send an unmistakable signal to Ukraine and to the world. \n","\n",- "We see the unity among leaders of nations and a more unified Europe a more unified West. And we see unity among the people who are gathering in cities in large crowds around the world even in Russia to demonstrate their support for Ukraine.\n",+ "Please rise if you are able and show that, Yes, we the United States of America stand with the Ukrainian people. \n",+ "\n",+ "Throughout our history we’ve learned this lesson when dictators do not pay a price for their aggression they cause more chaos. \n",+ "\n",+ "They keep moving. \n",+ "\n",+ "And the costs and the threats to America and the world keep rising.\n","----------------------------------------------------------------------------------------------------\n","Document 14:\n","\n",- "He met the Ukrainian people. \n",+ "Together with our allies we are providing support to the Ukrainians in their fight for freedom. Military assistance. Economic assistance. Humanitarian assistance. \n","\n",- "From President Zelenskyy to every Ukrainian, their fearlessness, their courage, their determination, inspires the world. \n",+ "We are giving more than $1 Billion in direct assistance to Ukraine. \n","\n",- "Groups of citizens blocking tanks with their bodies. Everyone from students to retirees teachers turned soldiers defending their homeland. \n",+ "And we will continue to aid the Ukrainian people as they defend their country and to help ease their suffering. \n","\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",+ "Let me be clear, our forces are not engaged and will not engage in conflict with Russian forces in Ukraine.\n","----------------------------------------------------------------------------------------------------\n","Document 15:\n","\n",- "In the battle between democracy and autocracy, democracies are rising to the moment, and the world is clearly choosing the side of peace and security. \n",- "\n",- "This is a real test. It’s going to take time. So let us continue to draw inspiration from the iron will of the Ukrainian people. \n",+ "It fueled our efforts to vaccinate the nation and combat COVID-19. It delivered immediate economic relief for tens of millions of Americans. \n","\n",- "To our fellow Ukrainian Americans who forge a deep bond that connects our two nations we stand with you. \n",+ "Helped put food on their table, keep a roof over their heads, and cut the cost of health insurance. \n","\n",- "Putin may circle Kyiv with tanks, but he will never gain the hearts and souls of the Ukrainian people.\n",+ "And as my Dad used to say, it gave people a little breathing room.\n","----------------------------------------------------------------------------------------------------\n","Document 16:\n","\n",- "Together with our allies we are providing support to the Ukrainians in their fight for freedom. Military assistance. Economic assistance. Humanitarian assistance. \n",+ "In the battle between democracy and autocracy, democracies are rising to the moment, and the world is clearly choosing the side of peace and security. \n","\n",- "We are giving more than $1 Billion in direct assistance to Ukraine. \n",+ "This is a real test. It’s going to take time. So let us continue to draw inspiration from the iron will of the Ukrainian people. \n","\n",- "And we will continue to aid the Ukrainian people as they defend their country and to help ease their suffering. \n",+ "To our fellow Ukrainian Americans who forge a deep bond that connects our two nations we stand with you. \n","\n",- "Let me be clear, our forces are not engaged and will not engage in conflict with Russian forces in Ukraine.\n",+ "Putin may circle Kyiv with tanks, but he will never gain the hearts and souls of the Ukrainian people.\n","----------------------------------------------------------------------------------------------------\n","Document 17:\n","\n",- "Let each of us here tonight in this Chamber send an unmistakable signal to Ukraine and to the world. \n",- "\n",- "Please rise if you are able and show that, Yes, we the United States of America stand with the Ukrainian people. \n",+ "He met the Ukrainian people. \n","\n",- "Throughout our history we’ve learned this lesson when dictators do not pay a price for their aggression they cause more chaos. \n",+ "From President Zelenskyy to every Ukrainian, their fearlessness, their courage, their determination, inspires the world. \n","\n",- "They keep moving. \n",+ "Groups of citizens blocking tanks with their bodies. Everyone from students to retirees teachers turned soldiers defending their homeland. \n","\n",- "And the costs and the threats to America and the world keep rising.\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 18:\n","\n",- "It fueled our efforts to vaccinate the nation and combat COVID-19. It delivered immediate economic relief for tens of millions of Americans. \n",+ "Our forces are not going to Europe to fight in Ukraine, but to defend our NATO Allies – in the event that Putin decides to keep moving west. \n","\n",- "Helped put food on their table, keep a roof over their heads, and cut the cost of health insurance. \n",+ "For that purpose we’ve mobilized American ground forces, air squadrons, and ship deployments to protect NATO countries including Poland, Romania, Latvia, Lithuania, and Estonia. \n","\n",- "And as my Dad used to say, it gave people a little breathing room.\n",+ "As I have made crystal clear the United States and our Allies will defend every inch of territory of NATO countries with the full force of our collective power.\n","----------------------------------------------------------------------------------------------------\n","Document 19:\n","\n",- "My administration is providing assistance with job training and housing, and now helping lower-income veterans get VA care debt-free. \n",+ "I understand. \n","\n",- "Our troops in Iraq and Afghanistan faced many dangers. \n",+ "I remember when my Dad had to leave our home in Scranton, Pennsylvania to find work. I grew up in a family where if the price of food went up, you felt it. \n","\n",- "One was stationed at bases and breathing in toxic smoke from “burn pits” that incinerated wastes of war—medical and hazard material, jet fuel, and more. \n",+ "That’s why one of the first things I did as President was fight to pass the American Rescue Plan. \n","\n",- "When they came home, many of the world’s fittest and best trained warriors were never the same. \n",+ "Because people were hurting. We needed to act, and we did. \n","\n",- "Headaches. Numbness. Dizziness.\n",+ "Few pieces of legislation have done more in a critical moment in our history to lift us out of crisis.\n","----------------------------------------------------------------------------------------------------\n","Document 20:\n","\n",- "Every Administration says they’ll do it, but we are actually doing it. \n",+ "And as my Dad used to say, it gave people a little breathing room. \n",+ "\n",+ "And unlike the $2 Trillion tax cut passed in the previous administration that benefitted the top 1% of Americans, the American Rescue Plan helped working people—and left no one behind. \n","\n",- "We will buy American to make sure everything from the deck of an aircraft carrier to the steel on highway guardrails are made in America. \n",+ "And it worked. It created jobs. Lots of jobs. \n","\n",- "But to compete for the best jobs of the future, we also need to level the playing field with China and other competitors.\n"+ "In fact—our economy created over 6.5 Million new jobs just last year, more jobs created in one year \n",+ "than ever before in the history of America.\n"]}],@@ -456,34 +466,35 @@"----------------------------------------------------------------------------------------------------\n","Document 2:\n","\n",- "As I said last year, especially to our younger transgender Americans, I will always have your back as your President, so you can be yourself and reach your God-given potential. \n",+ "A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since she’s been nominated, she’s received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans. \n","\n",- "While it often appears that we never agree, that isn’t true. I signed 80 bipartisan bills into law last year. From preventing government shutdowns to protecting Asian-Americans from still-too-common hate crimes to reforming military justice.\n",+ "And if we are to advance liberty and justice, we need to secure the Border and fix the immigration system.\n","----------------------------------------------------------------------------------------------------\n","Document 3:\n","\n",- "A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since she’s been nominated, she’s received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans. \n",+ "We cannot let this happen. \n","\n",- "And if we are to advance liberty and justice, we need to secure the Border and fix the immigration system.\n",+ "Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \n",+ "\n",+ "Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service.\n","----------------------------------------------------------------------------------------------------\n","Document 4:\n","\n",- "He met the Ukrainian people. \n",- "\n",- "From President Zelenskyy to every Ukrainian, their fearlessness, their courage, their determination, inspires the world. \n",- "\n",- "Groups of citizens blocking tanks with their bodies. Everyone from students to retirees teachers turned soldiers defending their homeland. \n",+ "As I said last year, especially to our younger transgender Americans, I will always have your back as your President, so you can be yourself and reach your God-given potential. \n","\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",+ "While it often appears that we never agree, that isn’t true. I signed 80 bipartisan bills into law last year. From preventing government shutdowns to protecting Asian-Americans from still-too-common hate crimes to reforming military justice.\n","----------------------------------------------------------------------------------------------------\n","Document 5:\n","\n",- "But that trickle-down theory led to weaker economic growth, lower wages, bigger deficits, and the widest gap between those at the top and everyone else in nearly a century. \n",+ "Madam Speaker, Madam Vice President, our First Lady and Second Gentleman. Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans. \n",+ "\n",+ "Last year COVID-19 kept us apart. This year we are finally together again. \n",+ "\n",+ "Tonight, we meet as Democrats Republicans and Independents. But most importantly as Americans. \n","\n",- "Vice President Harris and I ran for office with a new economic vision for America. \n",+ "With a duty to one another to the American people to the Constitution. \n","\n",- "Invest in America. Educate Americans. Grow the workforce. Build the economy from the bottom up \n",- "and the middle out, not from the top down.\n",+ "And with an unwavering resolve that freedom will always triumph over tyranny.\n","----------------------------------------------------------------------------------------------------\n","Document 6:\n","\n",@@ -501,153 +512,159 @@"----------------------------------------------------------------------------------------------------\n","Document 7:\n","\n",- "I spoke with their families and told them that we are forever in debt for their sacrifice, and we will carry on their mission to restore the trust and safety every community deserves. \n",+ "So that’s my plan. It will grow the economy and lower costs for families. \n","\n",- "I’ve worked on these issues a long time. \n",+ "So what are we waiting for? Let’s get this done. And while you’re at it, confirm my nominees to the Federal Reserve, which plays a critical role in fighting inflation. \n","\n",- "I know what works: Investing in crime prevention and community police officers who’ll walk the beat, who’ll know the neighborhood, and who can restore trust and safety. \n",- "\n",- "So let’s not abandon our streets. Or choose between safety and equal justice.\n",+ "My plan will not only lower costs to give families a fair shot, it will lower the deficit.\n","----------------------------------------------------------------------------------------------------\n","Document 8:\n","\n",- "As I’ve told Xi Jinping, it is never a good bet to bet against the American people. \n",+ "I spoke with their families and told them that we are forever in debt for their sacrifice, and we will carry on their mission to restore the trust and safety every community deserves. \n","\n",- "We’ll create good jobs for millions of Americans, modernizing roads, airports, ports, and waterways all across America. \n",+ "I’ve worked on these issues a long time. \n","\n",- "And we’ll do it all to withstand the devastating effects of the climate crisis and promote environmental justice.\n",+ "I know what works: Investing in crime prevention and community police officers who’ll walk the beat, who’ll know the neighborhood, and who can restore trust and safety. \n",+ "\n",+ "So let’s not abandon our streets. Or choose between safety and equal justice.\n","----------------------------------------------------------------------------------------------------\n","Document 9:\n","\n",- "Madam Speaker, Madam Vice President, our First Lady and Second Gentleman. Members of Congress and the Cabinet. Justices of the Supreme Court. My fellow Americans. \n",- "\n",- "Last year COVID-19 kept us apart. This year we are finally together again. \n",- "\n",- "Tonight, we meet as Democrats Republicans and Independents. But most importantly as Americans. \n",+ "So let’s not abandon our streets. Or choose between safety and equal justice. \n","\n",- "With a duty to one another to the American people to the Constitution. \n",+ "Let’s come together to protect our communities, restore trust, and hold law enforcement accountable. \n","\n",- "And with an unwavering resolve that freedom will always triumph over tyranny.\n",+ "That’s why the Justice Department required body cameras, banned chokeholds, and restricted no-knock warrants for its officers.\n","----------------------------------------------------------------------------------------------------\n","Document 10:\n","\n",- "As Ohio Senator Sherrod Brown says, “It’s time to bury the label “Rust Belt.” \n",- "\n",- "It’s time. \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",+ "As I’ve told Xi Jinping, it is never a good bet to bet against the American people. \n","\n",- "Inflation is robbing them of the gains they might otherwise feel. \n",+ "We’ll create good jobs for millions of Americans, modernizing roads, airports, ports, and waterways all across America. \n","\n",- "I get it. That’s why my top priority is getting prices under control.\n",+ "And we’ll do it all to withstand the devastating effects of the climate crisis and promote environmental justice.\n","----------------------------------------------------------------------------------------------------\n","Document 11:\n","\n",- "I’m also calling on Congress: pass a law to make sure veterans devastated by toxic exposures in Iraq and Afghanistan finally get the benefits and comprehensive health care they deserve. \n",+ "Let’s pass the Paycheck Fairness Act and paid leave. \n","\n",- "And fourth, let’s end cancer as we know it. \n",+ "Raise the minimum wage to $15 an hour and extend the Child Tax Credit, so no one has to raise a family in poverty. \n","\n",- "This is personal to me and Jill, to Kamala, and to so many of you. \n",+ "Let’s increase Pell Grants and increase our historic support of HBCUs, and invest in what Jill—our First Lady who teaches full-time—calls America’s best-kept secret: community colleges. \n","\n",- "Cancer is the #2 cause of death in America–second only to heart disease.\n",+ "And let’s pass the PRO Act when a majority of workers want to form a union—they shouldn’t be stopped.\n","----------------------------------------------------------------------------------------------------\n","Document 12:\n","\n",- "Headaches. Numbness. Dizziness. \n",+ "He will never extinguish their love of freedom. He will never weaken the resolve of the free world. \n","\n",- "A cancer that would put them in a flag-draped coffin. \n",+ "We meet tonight in an America that has lived through two of the hardest years this nation has ever faced. \n","\n",- "I know. \n",+ "The pandemic has been punishing. \n","\n",- "One of those soldiers was my son Major Beau Biden. \n",+ "And so many families are living paycheck to paycheck, struggling to keep up with the rising cost of food, gas, housing, and so much more. \n","\n",- "We don’t know for sure if a burn pit was the cause of his brain cancer, or the diseases of so many of our troops. \n",+ "I understand.\n",+ "----------------------------------------------------------------------------------------------------\n",+ "Document 13:\n","\n",- "But I’m committed to finding out everything we can. \n",+ "Well I know this nation. \n","\n",- "Committed to military families like Danielle Robinson from Ohio. \n",+ "We will meet the test. \n","\n",- "The widow of Sergeant First Class Heath Robinson.\n",- "----------------------------------------------------------------------------------------------------\n",- "Document 13:\n",+ "To protect freedom and liberty, to expand fairness and opportunity. \n","\n",- "He will never extinguish their love of freedom. He will never weaken the resolve of the free world. \n",+ "We will save democracy. \n","\n",- "We meet tonight in an America that has lived through two of the hardest years this nation has ever faced. \n",+ "As hard as these times have been, I am more optimistic about America today than I have been my whole life. \n","\n",- "The pandemic has been punishing. \n",+ "Because I see the future that is within our grasp. \n","\n",- "And so many families are living paycheck to paycheck, struggling to keep up with the rising cost of food, gas, housing, and so much more. \n",+ "Because I know there is simply nothing beyond our capacity. \n","\n",- "I understand.\n",+ "We are the only nation on Earth that has always turned every crisis we have faced into an opportunity.\n","----------------------------------------------------------------------------------------------------\n","Document 14:\n","\n",- "When we invest in our workers, when we build the economy from the bottom up and the middle out together, we can do something we haven’t done in a long time: build a better America. \n",- "\n",- "For more than two years, COVID-19 has impacted every decision in our lives and the life of the nation. \n",+ "If we want to go forward—not backward—we must protect access to health care. Preserve a woman’s right to choose. And let’s continue to advance maternal health care in America. \n","\n",- "And I know you’re tired, frustrated, and exhausted. \n",- "\n",- "But I also know this.\n",+ "And for our LGBTQ+ Americans, let’s finally get the bipartisan Equality Act to my desk. The onslaught of state laws targeting transgender Americans and their families is wrong.\n","----------------------------------------------------------------------------------------------------\n","Document 15:\n","\n",- "My plan to fight inflation will lower your costs and lower the deficit. \n",+ "He met the Ukrainian people. \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",+ "From President Zelenskyy to every Ukrainian, their fearlessness, their courage, their determination, inspires the world. \n",+ "\n",+ "Groups of citizens blocking tanks with their bodies. Everyone from students to retirees teachers turned soldiers defending their homeland. \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",+ "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 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",+ "Tonight I say to the Russian oligarchs and corrupt leaders who have bilked billions of dollars off this violent regime no more. \n","\n",- "First, beat the opioid epidemic. \n",+ "The U.S. Department of Justice is assembling a dedicated task force to go after the crimes of Russian oligarchs. \n","\n",- "There is so much we can do. Increase funding for prevention, treatment, harm reduction, and recovery.\n",+ "We are joining with our European allies to find and seize your yachts your luxury apartments your private jets. We are coming for your ill-begotten gains.\n","----------------------------------------------------------------------------------------------------\n","Document 17:\n","\n",- "My plan will not only lower costs to give families a fair shot, it will lower the deficit. \n",+ "It’s not only the right thing to do—it’s the economically smart thing to do. \n",+ "\n",+ "That’s why immigration reform is supported by everyone from labor unions to religious leaders to the U.S. Chamber of Commerce. \n","\n",- "The previous Administration not only ballooned the deficit with tax cuts for the very wealthy and corporations, it undermined the watchdogs whose job was to keep pandemic relief funds from being wasted. \n",+ "Let’s get it done once and for all. \n","\n",- "But in my administration, the watchdogs have been welcomed back. \n",+ "Advancing liberty and justice also requires protecting the rights of women. \n","\n",- "We’re going after the criminals who stole billions in relief money meant for small businesses and millions of Americans.\n",+ "The constitutional right affirmed in Roe v. Wade—standing precedent for half a century—is under attack as never before.\n","----------------------------------------------------------------------------------------------------\n","Document 18:\n","\n",- "So let’s not abandon our streets. Or choose between safety and equal justice. \n",+ "Smartphones. The Internet. Technology we have yet to invent. \n","\n",- "Let’s come together to protect our communities, restore trust, and hold law enforcement accountable. \n",+ "But that’s just the beginning. \n","\n",- "That’s why the Justice Department required body cameras, banned chokeholds, and restricted no-knock warrants for its officers.\n",+ "Intel’s CEO, Pat Gelsinger, who is here tonight, told me they are ready to increase their investment from \n",+ "$20 billion to $100 billion. \n",+ "\n",+ "That would be one of the biggest investments in manufacturing in American history. \n",+ "\n",+ "And all they’re waiting for is for you to pass this bill. \n",+ "\n",+ "So let’s not wait any longer. Send it to my desk. I’ll sign it. \n",+ "\n",+ "And we will really take off.\n","----------------------------------------------------------------------------------------------------\n","Document 19:\n","\n",- "I understand. \n",+ "And as my Dad used to say, it gave people a little breathing room. \n","\n",- "I remember when my Dad had to leave our home in Scranton, Pennsylvania to find work. I grew up in a family where if the price of food went up, you felt it. \n",+ "And unlike the $2 Trillion tax cut passed in the previous administration that benefitted the top 1% of Americans, the American Rescue Plan helped working people—and left no one behind. \n","\n",- "That’s why one of the first things I did as President was fight to pass the American Rescue Plan. \n",+ "And it worked. It created jobs. Lots of jobs. \n","\n",- "Because people were hurting. We needed to act, and we did. \n",- "\n",- "Few pieces of legislation have done more in a critical moment in our history to lift us out of crisis.\n",+ "In fact—our economy created over 6.5 Million new jobs just last year, more jobs created in one year \n",+ "than ever before in the history of America.\n","----------------------------------------------------------------------------------------------------\n","Document 20:\n","\n",- "And we will, as one people. \n",+ "The only nation that can be defined by a single word: possibilities. \n",+ "\n",+ "So on this night, in our 245th year as a nation, I have come to report on the State of the Union. \n",+ "\n",+ "And my report is this: the State of the Union is strong—because you, the American people, are strong. \n",+ "\n",+ "We are stronger today than we were a year ago. \n","\n",- "One America. \n",+ "And we will be stronger a year from now than we are today. \n","\n",- "The United States of America. \n",+ "Now is our moment to meet and overcome the challenges of our time. \n","\n",- "May God bless you all. May God protect our troops.\n"+ "And we will, as one people. \n",+ "\n",+ "One America.\n"]}],@@ -666,14 +683,14 @@},{"cell_type": "code",- "execution_count": 12,+ "execution_count": 20,"metadata": {},"outputs": [],"source": ["from langchain.retrievers.contextual_compression import ContextualCompressionRetriever\n","from langchain_community.document_compressors.rankllm_rerank import RankLLMRerank\n","\n",- "compressor = RankLLMRerank(top_n=3, model=\"gpt\", gpt_model=\"gpt-3.5-turbo\")\n",+ "compressor = RankLLMRerank(top_n=3, model=\"gpt\", gpt_model=\"gpt-4o-mini\")\n","compression_retriever = ContextualCompressionRetriever(\n"," base_compressor=compressor, base_retriever=retriever\n",")"@@ -702,9 +719,11 @@"----------------------------------------------------------------------------------------------------\n","Document 3:\n","\n",- "As I said last year, especially to our younger transgender Americans, I will always have your back as your President, so you can be yourself and reach your God-given potential. \n",+ "We cannot let this happen. \n","\n",- "While it often appears that we never agree, that isn’t true. I signed 80 bipartisan bills into law last year. From preventing government shutdowns to protecting Asian-Americans from still-too-common hate crimes to reforming military justice.\n"+ "Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \n",+ "\n",+ "Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service.\n"]},{@@ -729,17 +748,29 @@},{"cell_type": "code",- "execution_count": 14,+ "execution_count": 22,"metadata": {},"outputs": [+ {+ "name": "stderr",+ "output_type": "stream",+ "text": [+ "/tmp/ipykernel_2153001/1437145854.py:10: LangChainDeprecationWarning: The method `Chain.__call__` was deprecated in langchain 0.1.0 and will be removed in 1.0. Use :meth:`~invoke` instead.\n",+ " chain({\"query\": query})\n",+ "2025-02-17 04:30:00,016 - INFO - HTTP Request: POST https://api.openai.com/v1/embeddings \"HTTP/1.1 200 OK\"\n",+ " 0%| | 0/1 [00:00<?, ?it/s]2025-02-17 04:30:01,649 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n",+ "100%|██████████| 1/1 [00:01<00:00, 1.63s/it]\n",+ "2025-02-17 04:30:02,415 - INFO - HTTP Request: POST https://api.openai.com/v1/chat/completions \"HTTP/1.1 200 OK\"\n"+ ]+ },{"data": {"text/plain": ["{'query': 'What did the president say about Ketanji Brown Jackson',\n",- " 'result': \"The President mentioned that Ketanji Brown Jackson is one of the nation's top legal minds and that she will continue Justice Breyer's legacy of excellence. He highlighted her background as a former top litigator in private practice and a former federal public defender, as well as coming from a family of public school educators and police officers. He also mentioned that since her nomination, she has received broad support from various groups, including the Fraternal Order of Police and former judges appointed by Democrats and Republicans.\"}"+ " 'result': \"The President mentioned that Ketanji Brown Jackson is one of the nation's top legal minds, a former top litigator in private practice, a former federal public defender, and comes from a family of public school educators and police officers. He also highlighted her as a consensus builder and noted the broad range of support she has received since being nominated.\"}"]},- "execution_count": 14,+ "execution_count": 22,"metadata": {},"output_type": "execute_result"}diff --git a/libs/community/langchain_community/document_compressors/rankllm_rerank.py b/libs/community/langchain_community/document_compressors/rankllm_rerank.pyindex fb5a92ba00..db5e96b233 100644--- a/libs/community/langchain_community/document_compressors/rankllm_rerank.py+++ b/libs/community/langchain_community/document_compressors/rankllm_rerank.py@@ -130,10 +130,17 @@ class RankLLMRerank(BaseDocumentCompressor):)final_results = []- for res in rerank_results.candidates:- doc = documents[int(res.docid)]- doc_copy = Document(doc.page_content, metadata=deepcopy(doc.metadata))- final_results.append(doc_copy)+ if hasattr(rerank_results, "candidates"):+ # Old API format+ for res in rerank_results.candidates:+ doc = documents[int(res.docid)]+ doc_copy = Document(doc.page_content, metadata=deepcopy(doc.metadata))+ final_results.append(doc_copy)+ else:+ for res in rerank_results:+ doc = documents[int(res.docid)]+ doc_copy = Document(doc.page_content, metadata=deepcopy(doc.metadata))+ final_results.append(doc_copy)return final_results[: self.top_n]