From b3ef4e3ad3ea851ec9fe669e2927be8c527d20e2 Mon Sep 17 00:00:00 2001 From: joeywhelan Date: Thu, 11 May 2023 13:48:24 -0600 Subject: [PATCH] Add Redis Q&A example --- .../redis/redisqna/assets/001.txt | 11 + .../redis/redisqna/assets/002.txt | 7 + .../redis/redisqna/assets/003.txt | 7 + .../redis/redisqna/assets/004.txt | 11 + .../redis/redisqna/assets/005.txt | 7 + .../redis/redisqna/assets/006.txt | 7 + .../redis/redisqna/assets/007.txt | 9 + .../redis/redisqna/assets/008.txt | 7 + .../redis/redisqna/assets/009.txt | 9 + .../redis/redisqna/assets/010.txt | 7 + .../redis/redisqna/assets/011.txt | 60 +++ .../redis/redisqna/assets/012.txt | 53 +++ .../redis/redisqna/assets/013.txt | 72 ++++ .../redis/redisqna/docker-compose.yml | 5 + .../redis/redisqna/redisqna.ipynb | 381 ++++++++++++++++++ .../redis/redisqna/requirements.txt | 105 +++++ 16 files changed, 758 insertions(+) create mode 100644 examples/vector_databases/redis/redisqna/assets/001.txt create mode 100644 examples/vector_databases/redis/redisqna/assets/002.txt create mode 100644 examples/vector_databases/redis/redisqna/assets/003.txt create mode 100644 examples/vector_databases/redis/redisqna/assets/004.txt create mode 100644 examples/vector_databases/redis/redisqna/assets/005.txt create mode 100644 examples/vector_databases/redis/redisqna/assets/006.txt create mode 100644 examples/vector_databases/redis/redisqna/assets/007.txt create mode 100644 examples/vector_databases/redis/redisqna/assets/008.txt create mode 100644 examples/vector_databases/redis/redisqna/assets/009.txt create mode 100644 examples/vector_databases/redis/redisqna/assets/010.txt create mode 100644 examples/vector_databases/redis/redisqna/assets/011.txt create mode 100644 examples/vector_databases/redis/redisqna/assets/012.txt create mode 100644 examples/vector_databases/redis/redisqna/assets/013.txt create mode 100644 examples/vector_databases/redis/redisqna/docker-compose.yml create mode 100644 examples/vector_databases/redis/redisqna/redisqna.ipynb create mode 100644 examples/vector_databases/redis/redisqna/requirements.txt diff --git a/examples/vector_databases/redis/redisqna/assets/001.txt b/examples/vector_databases/redis/redisqna/assets/001.txt new file mode 100644 index 00000000..f4e22427 --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/001.txt @@ -0,0 +1,11 @@ +Ad sales boost Time Warner profit + +Quarterly profits at US media giant TimeWarner jumped 76% to $1.13bn (£600m) for the three months to December, from $639m year-earlier. + +The firm, which is now one of the biggest investors in Google, benefited from sales of high-speed internet connections and higher advert sales. TimeWarner said fourth quarter sales rose 2% to $11.1bn from $10.9bn. Its profits were buoyed by one-off gains which offset a profit dip at Warner Bros, and less users for AOL. + +Time Warner said on Friday that it now owns 8% of search-engine Google. But its own internet business, AOL, had has mixed fortunes. It lost 464,000 subscribers in the fourth quarter profits were lower than in the preceding three quarters. However, the company said AOL's underlying profit before exceptional items rose 8% on the back of stronger internet advertising revenues. It hopes to increase subscribers by offering the online service free to TimeWarner internet customers and will try to sign up AOL's existing customers for high-speed broadband. TimeWarner also has to restate 2000 and 2003 results following a probe by the US Securities Exchange Commission (SEC), which is close to concluding. + +Time Warner's fourth quarter profits were slightly better than analysts' expectations. But its film division saw profits slump 27% to $284m, helped by box-office flops Alexander and Catwoman, a sharp contrast to year-earlier, when the third and final film in the Lord of the Rings trilogy boosted results. For the full-year, TimeWarner posted a profit of $3.36bn, up 27% from its 2003 performance, while revenues grew 6.4% to $42.09bn. "Our financial performance was strong, meeting or exceeding all of our full-year objectives and greatly enhancing our flexibility," chairman and chief executive Richard Parsons said. For 2005, TimeWarner is projecting operating earnings growth of around 5%, and also expects higher revenue and wider profit margins. + +TimeWarner is to restate its accounts as part of efforts to resolve an inquiry into AOL by US market regulators. It has already offered to pay $300m to settle charges, in a deal that is under review by the SEC. The company said it was unable to estimate the amount it needed to set aside for legal reserves, which it previously set at $500m. It intends to adjust the way it accounts for a deal with German music publisher Bertelsmann's purchase of a stake in AOL Europe, which it had reported as advertising revenue. It will now book the sale of its stake in AOL Europe as a loss on the value of that stake. diff --git a/examples/vector_databases/redis/redisqna/assets/002.txt b/examples/vector_databases/redis/redisqna/assets/002.txt new file mode 100644 index 00000000..0aa9c6f7 --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/002.txt @@ -0,0 +1,7 @@ +Dollar gains on Greenspan speech + +The dollar has hit its highest level against the euro in almost three months after the Federal Reserve head said the US trade deficit is set to stabilise. + +And Alan Greenspan highlighted the US government's willingness to curb spending and rising household savings as factors which may help to reduce it. In late trading in New York, the dollar reached $1.2871 against the euro, from $1.2974 on Thursday. Market concerns about the deficit has hit the greenback in recent months. On Friday, Federal Reserve chairman Mr Greenspan's speech in London ahead of the meeting of G7 finance ministers sent the dollar higher after it had earlier tumbled on the back of worse-than-expected US jobs data. "I think the chairman's taking a much more sanguine view on the current account deficit than he's taken for some time," said Robert Sinche, head of currency strategy at Bank of America in New York. "He's taking a longer-term view, laying out a set of conditions under which the current account deficit can improve this year and next." + +Worries about the deficit concerns about China do, however, remain. China's currency remains pegged to the dollar and the US currency's sharp falls in recent months have therefore made Chinese export prices highly competitive. But calls for a shift in Beijing's policy have fallen on deaf ears, despite recent comments in a major Chinese newspaper that the "time is ripe" for a loosening of the peg. The G7 meeting is thought unlikely to produce any meaningful movement in Chinese policy. In the meantime, the US Federal Reserve's decision on 2 February to boost interest rates by a quarter of a point - the sixth such move in as many months - has opened up a differential with European rates. The half-point window, some believe, could be enough to keep US assets looking more attractive, and could help prop up the dollar. The recent falls have partly been the result of big budget deficits, as well as the US's yawning current account gap, both of which need to be funded by the buying of US bonds and assets by foreign firms and governments. The White House will announce its budget on Monday, and many commentators believe the deficit will remain at close to half a trillion dollars. diff --git a/examples/vector_databases/redis/redisqna/assets/003.txt b/examples/vector_databases/redis/redisqna/assets/003.txt new file mode 100644 index 00000000..dd696552 --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/003.txt @@ -0,0 +1,7 @@ +Yukos unit buyer faces loan claim + +The owners of embattled Russian oil giant Yukos are to ask the buyer of its former production unit to pay back a $900m (£479m) loan. + +State-owned Rosneft bought the Yugansk unit for $9.3bn in a sale forced by Russia to part settle a $27.5bn tax claim against Yukos. Yukos' owner Menatep Group says it will ask Rosneft to repay a loan that Yugansk had secured on its assets. Rosneft already faces a similar $540m repayment demand from foreign banks. Legal experts said Rosneft's purchase of Yugansk would include such obligations. "The pledged assets are with Rosneft, so it will have to pay real money to the creditors to avoid seizure of Yugansk assets," said Moscow-based US lawyer Jamie Firestone, who is not connected to the case. Menatep Group's managing director Tim Osborne told the Reuters news agency: "If they default, we will fight them where the rule of law exists under the international arbitration clauses of the credit." + +Rosneft officials were unavailable for comment. But the company has said it intends to take action against Menatep to recover some of the tax claims and debts owed by Yugansk. Yukos had filed for bankruptcy protection in a US court in an attempt to prevent the forced sale of its main production arm. The sale went ahead in December and Yugansk was sold to a little-known shell company which in turn was bought by Rosneft. Yukos claims its downfall was punishment for the political ambitions of its founder Mikhail Khodorkovsky and has vowed to sue any participant in the sale. diff --git a/examples/vector_databases/redis/redisqna/assets/004.txt b/examples/vector_databases/redis/redisqna/assets/004.txt new file mode 100644 index 00000000..f03a2c14 --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/004.txt @@ -0,0 +1,11 @@ +High fuel prices hit BA's profits + +British Airways has blamed high fuel prices for a 40% drop in profits. + +Reporting its results for the three months to 31 December 2004, the airline made a pre-tax profit of £75m ($141m) compared with £125m a year earlier. Rod Eddington, BA's chief executive, said the results were "respectable" in a third quarter when fuel costs rose by £106m or 47.3%. BA's profits were still better than market expectation of £59m, and it expects a rise in full-year revenues. + +To help offset the increased price of aviation fuel, BA last year introduced a fuel surcharge for passengers. + +In October, it increased this from £6 to £10 one-way for all long-haul flights, while the short-haul surcharge was raised from £2.50 to £4 a leg. Yet aviation analyst Mike Powell of Dresdner Kleinwort Wasserstein says BA's estimated annual surcharge revenues - £160m - will still be way short of its additional fuel costs - a predicted extra £250m. Turnover for the quarter was up 4.3% to £1.97bn, further benefiting from a rise in cargo revenue. Looking ahead to its full year results to March 2005, BA warned that yields - average revenues per passenger - were expected to decline as it continues to lower prices in the face of competition from low-cost carriers. However, it said sales would be better than previously forecast. "For the year to March 2005, the total revenue outlook is slightly better than previous guidance with a 3% to 3.5% improvement anticipated," BA chairman Martin Broughton said. BA had previously forecast a 2% to 3% rise in full-year revenue. + +It also reported on Friday that passenger numbers rose 8.1% in January. Aviation analyst Nick Van den Brul of BNP Paribas described BA's latest quarterly results as "pretty modest". "It is quite good on the revenue side and it shows the impact of fuel surcharges and a positive cargo development, however, operating margins down and cost impact of fuel are very strong," he said. Since the 11 September 2001 attacks in the United States, BA has cut 13,000 jobs as part of a major cost-cutting drive. "Our focus remains on reducing controllable costs and debt whilst continuing to invest in our products," Mr Eddington said. "For example, we have taken delivery of six Airbus A321 aircraft and next month we will start further improvements to our Club World flat beds." BA's shares closed up four pence at 274.5 pence. diff --git a/examples/vector_databases/redis/redisqna/assets/005.txt b/examples/vector_databases/redis/redisqna/assets/005.txt new file mode 100644 index 00000000..ac7bf0be --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/005.txt @@ -0,0 +1,7 @@ +Pernod takeover talk lifts Domecq + +Shares in UK drinks and food firm Allied Domecq have risen on speculation that it could be the target of a takeover by France's Pernod Ricard. + +Reports in the Wall Street Journal and the Financial Times suggested that the French spirits firm is considering a bid, but has yet to contact its target. Allied Domecq shares in London rose 4% by 1200 GMT, while Pernod shares in Paris slipped 1.2%. Pernod said it was seeking acquisitions but refused to comment on specifics. + +Pernod's last major purchase was a third of US giant Seagram in 2000, the move which propelled it into the global top three of drinks firms. The other two-thirds of Seagram was bought by market leader Diageo. In terms of market value, Pernod - at 7.5bn euros ($9.7bn) - is about 9% smaller than Allied Domecq, which has a capitalisation of £5.7bn ($10.7bn; 8.2bn euros). Last year Pernod tried to buy Glenmorangie, one of Scotland's premier whisky firms, but lost out to luxury goods firm LVMH. Pernod is home to brands including Chivas Regal Scotch whisky, Havana Club rum and Jacob's Creek wine. Allied Domecq's big names include Malibu rum, Courvoisier brandy, Stolichnaya vodka and Ballantine's whisky - as well as snack food chains such as Dunkin' Donuts and Baskin-Robbins ice cream. The WSJ said that the two were ripe for consolidation, having each dealt with problematic parts of their portfolio. Pernod has reduced the debt it took on to fund the Seagram purchase to just 1.8bn euros, while Allied has improved the performance of its fast-food chains. diff --git a/examples/vector_databases/redis/redisqna/assets/006.txt b/examples/vector_databases/redis/redisqna/assets/006.txt new file mode 100644 index 00000000..fa78492a --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/006.txt @@ -0,0 +1,7 @@ +Japan narrowly escapes recession + +Japan's economy teetered on the brink of a technical recession in the three months to September, figures show. + +Revised figures indicated growth of just 0.1% - and a similar-sized contraction in the previous quarter. On an annual basis, the data suggests annual growth of just 0.2%, suggesting a much more hesitant recovery than had previously been thought. A common technical definition of a recession is two successive quarters of negative growth. + +The government was keen to play down the worrying implications of the data. "I maintain the view that Japan's economy remains in a minor adjustment phase in an upward climb, and we will monitor developments carefully," said economy minister Heizo Takenaka. But in the face of the strengthening yen making exports less competitive and indications of weakening economic conditions ahead, observers were less sanguine. "It's painting a picture of a recovery... much patchier than previously thought," said Paul Sheard, economist at Lehman Brothers in Tokyo. Improvements in the job market apparently have yet to feed through to domestic demand, with private consumption up just 0.2% in the third quarter. diff --git a/examples/vector_databases/redis/redisqna/assets/007.txt b/examples/vector_databases/redis/redisqna/assets/007.txt new file mode 100644 index 00000000..4147eb0b --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/007.txt @@ -0,0 +1,9 @@ +Jobs growth still slow in the US + +The US created fewer jobs than expected in January, but a fall in jobseekers pushed the unemployment rate to its lowest level in three years. + +According to Labor Department figures, US firms added only 146,000 jobs in January. The gain in non-farm payrolls was below market expectations of 190,000 new jobs. Nevertheless it was enough to push down the unemployment rate to 5.2%, its lowest level since September 2001. The job gains mean that President Bush can celebrate - albeit by a very fine margin - a net growth in jobs in the US economy in his first term in office. He presided over a net fall in jobs up to last November's Presidential election - the first President to do so since Herbert Hoover. As a result, job creation became a key issue in last year's election. However, when adding December and January's figures, the administration's first term jobs record ended in positive territory. + +The Labor Department also said it had revised down the jobs gains in December 2004, from 157,000 to 133,000. + +Analysts said the growth in new jobs was not as strong as could be expected given the favourable economic conditions. "It suggests that employment is continuing to expand at a moderate pace," said Rick Egelton, deputy chief economist at BMO Financial Group. "We are not getting the boost to employment that we would have got given the low value of the dollar and the still relatively low interest rate environment." "The economy is producing a moderate but not a satisfying amount of job growth," said Ken Mayland, president of ClearView Economics. "That means there are a limited number of new opportunities for workers." diff --git a/examples/vector_databases/redis/redisqna/assets/008.txt b/examples/vector_databases/redis/redisqna/assets/008.txt new file mode 100644 index 00000000..6657036a --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/008.txt @@ -0,0 +1,7 @@ +India calls for fair trade rules + +India, which attends the G7 meeting of seven leading industrialised nations on Friday, is unlikely to be cowed by its newcomer status. + +In London on Thursday ahead of the meeting, India's finance minister, lashed out at the restrictive trade policies of the G7 nations. He objected to subsidies on agriculture that make it hard for developing nations like India to compete. He also called for reform of the United Nations, the World Bank and the IMF. + +Palaniappan Chidambaram, India's finance minister, argued that these organisations need to take into account the changing world order, given India and China's integration into the global economy. He said the issue is not globalisation but "the terms of engagement in globalisation." Mr Chidambaram is attending the G7 meeting as part of the G20 group of nations, which account for two thirds of the world's population. At a conference on developing enterprise hosted by UK finance minister Gordon Brown on Friday, he said that he was in favour of floating exchange rates because they help countries cope with economic shocks. "A flexible exchange rate is one more channel for absorbing both positive and negative shocks," he told the conference. India, along with China, Brazil, South Africa and Russia, has been invited to take part in the G7 meeting taking place in London on Friday and Saturday. China is expected to face renewed pressure to abandon its fixed exchange rate, which G7 nations, in particular the US, have blamed for a surge in cheap Chinese exports. "Some countries have tried to use fixed exchange rates. I do not wish to make any judgements," Mr Chidambaram said. Separately, the IMF warned on Thursday that India's budget deficit was too large and would hamper the country's economic growth, which it forecast to be around 6.5% in the year to March 2005. In the year to March 2004, the Indian economy grew by 8.5%. diff --git a/examples/vector_databases/redis/redisqna/assets/009.txt b/examples/vector_databases/redis/redisqna/assets/009.txt new file mode 100644 index 00000000..7345c8da --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/009.txt @@ -0,0 +1,9 @@ +Ethiopia's crop production up 24% + +Ethiopia produced 14.27 million tonnes of crops in 2004, 24% higher than in 2003 and 21% more than the average of the past five years, a report says. + +In 2003, crop production totalled 11.49 million tonnes, the joint report from the Food and Agriculture Organisation and the World Food Programme said. Good rains, increased use of fertilizers and improved seeds contributed to the rise in production. Nevertheless, 2.2 million Ethiopians will still need emergency assistance. + +The report calculated emergency food requirements for 2005 to be 387,500 tonnes. On top of that, 89,000 tonnes of fortified blended food and vegetable oil for "targeted supplementary food distributions for a survival programme for children under five and pregnant and lactating women" will be needed. + +In eastern and southern Ethiopia, a prolonged drought has killed crops and drained wells. Last year, a total of 965,000 tonnes of food assistance was needed to help seven million Ethiopians. The Food and Agriculture Organisation (FAO) recommend that the food assistance is bought locally. "Local purchase of cereals for food assistance programmes is recommended as far as possible, so as to assist domestic markets and farmers," said Henri Josserand, chief of FAO's Global Information and Early Warning System. Agriculture is the main economic activity in Ethiopia, representing 45% of gross domestic product. About 80% of Ethiopians depend directly or indirectly on agriculture. diff --git a/examples/vector_databases/redis/redisqna/assets/010.txt b/examples/vector_databases/redis/redisqna/assets/010.txt new file mode 100644 index 00000000..078b6e94 --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/010.txt @@ -0,0 +1,7 @@ +Court rejects $280bn tobacco case + +A US government claim accusing the country's biggest tobacco companies of covering up the effects of smoking has been thrown out by an appeal court. + +The demand for $280bn (£155bn) - filed by the Clinton administration in 1999 - was rejected in a 2-1 decision. The court in Washington found that the case could not be brought under federal anti-racketeering laws. Among the accused were Altria Group, RJ Reynolds Tobacco, Lorillard Tobacco, Liggett Group and Brown and Williamson. In its case, the government claimed tobacco firms manipulated nicotine levels to increase addiction, targeted teenagers with multi-billion dollar advertising campaigns, lied about the dangers of smoking and ignored research to the contrary. + +Prosecutors wanted the cigarette firms to surrender $280bn in profits accumulated over the past 50 years and impose tougher rules on marketing their products. But the Court of Appeals for the District of Columbia ruled that the US government could not sue the firms under legislation drawn up to counteract Mafia infiltration of business. The tobacco companies deny that they illegally conspired to promote smoking and defraud the public. They also say they have already met many of the government's demands in a landmark $206bn settlement reached with 46 states in 1998. Shares of tobacco companies closed higher after the ruling, with Altria rising 5% and Reynolds showing gains of 4.5%. diff --git a/examples/vector_databases/redis/redisqna/assets/011.txt b/examples/vector_databases/redis/redisqna/assets/011.txt new file mode 100644 index 00000000..6845d62a --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/011.txt @@ -0,0 +1,60 @@ +Embattled Crypto Exchange FTX Files for Bankruptcy + +Nov. 11, 2022 +On Monday, Sam Bankman-Fried, the chief executive of the cryptocurrency exchange FTX, took to Twitter to reassure his customers: “FTX is fine,” he wrote. “Assets are fine.” + +On Friday, FTX announced that it was filing for bankruptcy, capping an extraordinary week of corporate drama that has upended crypto markets, sent shock waves through an industry struggling to gain mainstream credibility and sparked government investigations that could lead to more damaging revelations or even criminal charges. + +In a statement on Twitter, the company said that Mr. Bankman-Fried had resigned, with John J. Ray III, a corporate turnaround specialist, taking over as chief executive. + +The speed of FTX’s downfall has left crypto insiders stunned. Just days ago, Mr. Bankman-Fried was considered one of the smartest leaders in the crypto industry, an influential figure in Washington who was lobbying to shape regulations. And FTX was widely viewed as one of the most stable and responsible companies in the freewheeling, loosely regulated crypto industry. + +“Here we are, with one of the richest people in the world, his net worth dropping to zero, his business dropping to zero,” said Jared Ellias, a bankruptcy professor at Harvard Law School. “The velocity of this failure is just unbelievable.” + +Now, the bankruptcy has set up a rush among investors and customers to salvage funds from what remains of FTX. A surge of customers tried to withdraw funds from the platform this week, and the company couldn’t meet the demand. The exchange owes as much as $8 billion, according to people familiar with its finances. + +FTX’s collapse has destabilized the crypto industry, which was already reeling from a crash in the spring that drained $1 trillion from the market. The prices of the leading cryptocurrencies, Bitcoin and Ether, have plummeted. The crypto lender BlockFi, which was closely entangled with FTX, announced on Thursday that it was suspending operations as a result of FTX’s collapse. + +Mr. Bankman-Fried was backed by some of the highest-profile venture capital investors in Silicon Valley, including Sequoia Capital and Lightspeed Venture Partners. Some of those investors, facing questions about how closely they scrutinized FTX before they put money into it, have said that their nine-figure investments in the crypto exchange are now essentially worthless. + +The company’s demise has also set off a reckoning over risky practices that have become pervasive in crypto, an industry that was founded partly as a corrective to the type of dangerous financial engineering that caused the 2008 economic crisis. + +“I’m really sorry, again, that we ended up here,” Mr. Bankman-Fried said on Twitter on Friday. “Hopefully this can bring some amount of transparency, trust, and governance.” + +The bankruptcy filing marks the start of what will probably be months or even years of legal fallout, as lawyers try to work out whether the exchange can ever continue to operate in some form and customers demand compensation. FTX is already the target of investigations by the Securities and Exchange Commission and the Justice Department, with investigators focused on whether the company improperly used customer funds to prop up Alameda Research, a trading firm that Mr. Bankman-Fried also founded. + +The bankruptcy filing included FTX, its U.S. arm and Alameda. According to a bare-bones legal filing in U.S. Bankruptcy Court in Delaware, FTX has assets valued between $10 billion and $50 billion, with the size of its liabilities in the same range. The company has more than 100,000 creditors, the filing said. + +The bankruptcy is a stunning fall from grace for the 30-year-old Mr. Bankman-Fried, who cultivated a reputation as a boy genius with a host of endearing quirks, including a habit of sleeping on a beanbag at the office. At one point, he was one of the richest people in the industry, with an estimated fortune of $24 billion. He hobnobbed with actors, professional athletes and former world leaders. + +Mr. Bankman-Fried’s crypto empire had an elaborate structure. The bankruptcy filing lists more than 130 corporate entities affiliated with FTX and Alameda. But as of June, FTX had only about 300 employees, a point of pride for Mr. Bankman-Fried, who said he had resisted calls from venture investors to hire more staff. + +“We told them additional employees added too quickly were net negative,” Mr. Bankman-Fried said on Twitter in June. “They could take it or leave it.” + +Unusually for a major start-up, none of FTX’s investors had seats on the board, which instead consisted of Mr. Bankman-Fried, another FTX executive and a lawyer in Antigua and Barbuda. + +FTX and Alameda were based in the Bahamas, where Mr. Bankman-Fried and a small circle of top executives called most of the shots and lived together in a luxury resort. Officially, Alameda was run by Caroline Ellison, a former trader for the hedge fund Jane Street, but Mr. Bankman-Fried was heavily involved, contributing to the decision-making on big trades, according to a person familiar with the matter. + +In addition to Mr. Bankman-Fried and Ms. Ellison, the circle of executives running FTX included Nishad Singh, FTX’s director of engineering, and Gary Wang, the chief technology officer. Few others had visibility into how the company was run: When the firm collapsed this week, lower-ranking employees were left confused and blindsided, according to people familiar with the matter. Mr. Singh and Ms. Ellison did not respond to requests for comment; Mr. Wang could not immediately be reached. + +As a crypto exchange, FTX provided a marketplace for customers to buy, sell and store a wide range of digital currencies. Most of its revenue stemmed from a risky type of trade — in which crypto investors borrowed money to make huge bets on the future prices of cryptocurrencies — that remains illegal in the United States. But Mr. Bankman-Fried also ran a smaller U.S. affiliate that offered more basic trading options. + +Mr. Bankman-Fried’s problems started over the weekend, when the chief executive of Binance, the largest crypto exchange, suggested publicly that FTX might be on shaky financial footing. A rush of customers tried to withdraw their crypto holdings from the platform, and FTX was unable to meet the demand. + +On Tuesday, Mr. Bankman-Fried said he had struck a deal to sell FTX to Binance. But after reviewing the company’s financial documents, Binance’s chief executive, Changpeng Zhao, pulled out of the agreement, leaving Mr. Bankman-Fried with limited options. + +In calls with investors and messages to employees this week, he apologized repeatedly and stressed that he was working hard to raise money and resolve the situation. But the hole was ultimately too big to fill. + +FTX’s bankruptcy is the latest — and by far the biggest — in a series of bankruptcies that have shaken the crypto world this year. After a market crash in the spring, two crypto lending companies, Celsius Network and Voyager Digital, filed for bankruptcy, kicking off months of legal maneuvering over how their remaining assets should be divided. In an ironic twist, FTX had recently won an auction to buy Voyager’s remaining assets. + +As it enters its own bankruptcy process, FTX will be led by Mr. Ray, who has ample experience managing distressed situations. He helped manage Enron after the collapse of its business in an accounting fraud scandal in 2001. And he helped liquidate the trust of the subprime mortgage company ResCap after its 2012 bankruptcy. + +The bankruptcy proceedings may be only the beginning of Mr. Bankman-Fried’s legal troubles. Federal investigators are examining the relationship between FTX and Alameda, and customers are likely to file lawsuits. + +Mr. Bankman-Fried’s old allies have quickly abandoned him. On Thursday night, the team running the FTX Future Fund, a charitable group that Mr. Bankman-Fried bankrolled, announced that they were resigning. + +“We were shocked and immensely saddened to learn of the recent events at FTX,” they wrote in a statement. “We have fundamental questions about the legitimacy and integrity of the business operations that were funding the FTX Foundation and the Future Fund.” + +Not long ago, Mr. Bankman-Fried was performing a comedy routine onstage at a conference with Anthony Scaramucci, the former White House communications director and a business partner of FTX. + +“I’m disappointed,” Mr. Scaramucci said in an interview on CNBC on Friday. “Duped, I guess, is the right word.” diff --git a/examples/vector_databases/redis/redisqna/assets/012.txt b/examples/vector_databases/redis/redisqna/assets/012.txt new file mode 100644 index 00000000..f1226564 --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/012.txt @@ -0,0 +1,53 @@ +FTX founder Sam Bankman-Fried hit with four new criminal charges +PUBLISHED THU, FEB 23 202310:11 AM ESTUPDATED THU, FEB 23 20232:06 PM EST + +FTX co-founder Sam Bankman-Fried was hit Thursday with four new criminal charges, including ones related to commodities fraud and making unlawful political contributions, in a superseding indictment filed in New York federal court. + +A source familiar with the new counts said that SBF, as he is popularly known, could face an additional 40 years in prison if convicted in the case, where he is accused of “multiple schemes to defraud.” + +The new charging document lays out in greater detail Bankman-Fried’s allegedly fraudulent conduct related to his cryptocurrency exchange FTX and an associated hedge fund, Alameda Research, both of which went bust in late 2022. + +The 12-count indictment also provides new details of hundreds of political donations that Bankman-Fried allegedly directed in violation of federal campaign finance laws. + +Bankman-Fried is accused of stealing FTX customer deposits and using billions of dollars of those stolen funds to support FTX’s and Alameda’s operations and investments, to fund speculative investments, to make charitable contributions, and to enrich himself, the indictment notes. + +He also tried “to purchase influence over cryptocurrency regulation in Washington, D.C., by steering tens of millions of dollars in illegal campaign contributions to both Democrats and Republicans,” according to the new indictment, which was was unsealed in U.S. District Court in Manhattan. + +Before the criminal case, SBF was known as a major donor to Democrats. + +Bankman-Fried, who remains free on a $250 million personal recognizance bond after being first charged in late 2022, has pleaded not guilty in the case. + +The new indictment adds yet more legal pressure on SBF, whose close associates, FTX co-founder Gary Wang and ex-Alameda CEO Caroline Ellison, pleaded guilty in December to multiple fraud and other charges. Both Wang and Ellison are cooperating with the U.S. attorney’s office in Manhattan against Bankman-Fried. + +The new indictment accuses him of securities fraud, wire fraud, and multiple conspiracy counts related to wire fraud on FTX customers and Alameda’s lenders; illegal campaign contributions; money laundering; operating an unlicensed money transmitting business; and bank fraud. + +Manhattan U.S. Attorney Damian Williams, in a statement on the new indictment said, “We are hard at work and will remain so until justice is done.” + +The charging document lays out how Bankman-Fried allegedly operated an illegal straw donor scheme as he moved to use customers funds to run a multimillion-dollar political influence campaign. + +Bankman-Fried and fellow FTX executives combined to contribute more than $70 million toward the 2022 midterm elections, according to campaign finance watchdog OpenSecrets. + +The indictment claims that Bankman-Fried and his co-conspirators “made over 300 political contributions, totaling tens of millions of dollars, that were unlawful because they were made in the name of a straw donor or paid for with corporate funds.” + +“To avoid certain contributions being publicly reported in his name, Bankman-Fried conspired to and did have certain political contributions made in the names of two other FTX executives,” the new filing claims. + +The document refers to one such example, in 2022, when Bankman-Fried and “others agreed that he and his co-conspirators should contribute at least a million dollars to a super PAC that was supporting a candidate running for a United States Congressional seat and appeared to be affiliated with pro-LGBTQ issues.” + +The group of conspirators, according to the document, selected an individual only identified in the document as “CC-1” or co-conspirator 1, to be the donor. + +However, in 2022, then-FTX Director of Engineering Nishad Singh contributed $1.1 million to the LGBTQ Victory Fund Federal PAC, according to Federal Election Commission filings. + +Singh, who did not immediately respond to a request for comment, has not been charged with any wrongdoing. Albert Fujii, a spokesman for the PAC, told CNBC “we have set aside funds and will take appropriate action once we receive guidance from authorities.” + +SBF’s alleged campaign finance scheme included efforts to keep his contributions to Republicans “dark,” according to the new indictment. + +And, the alleged straw donor scheme was coordinated, at least in part, “through an encrypted, auto-deleting Signal chat called ‘Donation Processing,’” according to the indictment. + +The document says another unnamed co-conspirator “who publicly aligned himself with conservatives, made contributions to Republican candidates that were directed by Bankman-Fried and funded by Alameda,” the crypto tycoon’s hedge fund. + +Again, the document does do not name the alleged second FTX co-conspirator who contributed to Republican candidates. + +Ryan Salame, the co-CEO of FTX Digital Markets, a subsidiary of FTX, donated more than $20 million to Republicans during the 2022 election cycle, according to OpenSecrets. Salame has not been charged with any wrongdoing. + +Salame could not be reached for comment. A spokeswoman for Salame did not return a request for comment. + diff --git a/examples/vector_databases/redis/redisqna/assets/013.txt b/examples/vector_databases/redis/redisqna/assets/013.txt new file mode 100644 index 00000000..df386e37 --- /dev/null +++ b/examples/vector_databases/redis/redisqna/assets/013.txt @@ -0,0 +1,72 @@ +FTX Trading Ltd., commonly known as FTX (short for "Futures Exchange"),[5] is a bankrupt company that formerly operated a cryptocurrency exchange and crypto hedge fund.[6][7] The exchange was founded in 2019 by Sam Bankman-Fried and Gary Wang and, at its peak in July 2021, had over one million users and was the third-largest cryptocurrency exchange by volume.[8][9] FTX is incorporated in Antigua and Barbuda and headquartered in the Bahamas.[10] FTX is closely associated with FTX.US, a separate exchange available to US residents.[11] + +Since November 11, 2022, FTX has been in Chapter 11 bankruptcy proceedings in the US court system.[12][13][14][15] Public concern began when a November 2022 CoinDesk article stated that FTX's partner firm Alameda Research held a significant portion of its assets in FTX's native token (FTT).[16][17] Following this revelation, rival exchange Binance's CEO Changpeng Zhao announced that Binance would sell its holdings of the token, which was quickly followed by a spike in customer withdrawals from FTX.[18] FTX was unable to meet the demand for customer withdrawals.[19] Binance signed a letter of intent to acquire the firm, with due diligence to follow, to ensure that customers could recover their assets from FTX in a timely manner, but Binance withdrew its offer the next day, citing reports of mishandled customer funds and U.S. agency investigations.[20] On December 12, 2022, founder Sam Bankman-Fried was arrested by the Bahamian authorities for financial offences, at the request of the US government.[21] + +The current CEO of FTX is John J. Ray III, who specializes in recovering funds from failed corporations. Speaking of its previous management, Ray stated: "Never in my career have I seen such a complete failure of corporate controls and such a complete absence of trustworthy financial information as occurred here." He added that "this situation is unprecedented." + +Sam Bankman-Fried and Zixiao "Gary" Wang[22] founded FTX in May 2019.[23] FTX began within Alameda Research, a trading firm founded by Bankman-Fried, Caroline Ellison, and other former employees of Jane Street in 2017, in Berkeley, California.[5][24][25] FTX is an abbreviation of "Futures Exchange".[5] Changpeng Zhao of Binance purchased a 20% stake in FTX for approximately $100 million, six months after Bankman-Fried and Wang started the firm.[26] + +In August 2020, FTX acquired Blockfolio, a cryptocurrency portfolio tracking app, for $150 million.[27] In July 2021, the venture raised $900 million at an $18 billion valuation from over 60 investors, including Softbank, Sequoia Capital, and other firms.[28][29] Bankman-Fried bought out Zhao's stake for approximately $2 billion.[26] In September of that year, FTX moved its headquarters from Hong Kong to The Bahamas.[30] + +On January 14, 2022, FTX announced a $2 billion venture fund named FTX Ventures,[31] raising $400 million in Series C funding at a $32 billion valuation that month.[32] The FTX Ventures website went offline in November 2022.[33] On February 11, 2022, FTX.US announced that the company would soon begin offering stock trading to its US customers.[34] + +In February 2022, it was reported that FTX was creating a gaming division that would help developers add cryptocurrency, NFTs, and other blockchain-related assets into video games.[35] + +In July 2022, FTX finalized a deal giving it the option to buy BlockFi for about $240 million. The deal included a $400 million credit facility for BlockFi.[36][37] + +In August 2022, the Federal Deposit Insurance Corporation (FDIC) issued a cease-and-desist order to FTX for making "false and misleading representations" about deposits being covered by FDIC insurance following FTX president Brett Harrison's tweet implying otherwise.[38] Following the regulatory action, Harrison deleted the tweet and Bankman-Fried clarified in another tweet that FTX deposits are not insured by the FDIC.[39] + +On September 26, 2022, FTX.US won its bid at auction for the digital assets of bankrupt crypto brokerage Voyager Digital. The value of the deal was approximately $1.42 billion, including $1.31 billion in Voyager-held cryptocurrency and $111 million in additional consideration. The deal was subject to approval by bankruptcy courts and Voyager's creditors.[40] Following the FTX bankruptcy, in December 2022, the US subsidiary of Binance won the bid to buy the assets of Voyager for approximately $1 billion.[41] + +On September 27, 2022, FTX.US President Brett Harrison announced he would be stepping down from an active role at the exchange but would stay on in an advisory capacity. The company did not immediately announce a replacement for Harrison, who had been FTX.US president since May 2021.[42] + +In October 2022, it was reported that FTX was under investigation in Texas for allegedly selling unregistered securities.[43] + +In September 2022, Bloomberg reported on the close relationship between Alameda Research and FTX. Bloomberg noted that Alameda had functioned as a market maker for FTX early in the exchange's history, and that the trading firm remained, in June and July 2022, the biggest known depositor of stable coins on FTX.[44] Bloomberg further stated that the regulatory oversight which applies to companies operating in traditional equities markets would have prohibited the relationship between the two firms were it applicable.[44] Alameda's trading on FTX meant the trading firm was potentially in a position to gain financially when others lost money on the exchange.[45] Bankman-Fried, at points, defended Alameda's use of FTX as a liquidity provider.[45] + +According to John J. Ray III, Alameda had a "secret exemption" from FTX's auto-liquidation protocol.[46] Later, the existence of such an undisclosed beneficial relationship was described by Ray, the new CEO of FTX, as a "complete failure of corporate controls"[47] and indicated gross mismanagement.[46] Between early 2021 and March 2022, Alameda Research amassed crypto tokens ahead of FTX announcing the decision to list them for trading.[48] + +According to anonymous sources cited by The Wall Street Journal, FTX had lent $10 billion of its customers' assets to Alameda Research in 2022.[49] Alameda CEO Caroline Ellison disclosed to other Alameda employees that she, Sam Bankman-Fried, Gary Wang, and Nishad Singh knew about that decision.[50] An anonymous source cited by the New York Times said the same.[51] According to the sources cited by The Wall Street Journal, Ellison said the funds were used in part to pay back loans Alameda had taken to make investments.[50] Ray said that FTX used software to conceal the misuse of customer funds.[46][47][52] + +Several months after Bloomberg's initial report on the relationship between the two firms, on November 2, 2022, CoinDesk reported that a significant portion of Alameda Research's assets were held in FTT, the exchange token issued by FTX. It said that there were $5.1 billion worth of FTT tokens in circulation, and that Alameda's balance sheet held $3.66 billion of "unlocked FTT", $2.16 billion of "FTT collateral", and $292 million of "locked FTT".[16] In the weeks immediately preceding the publication of the story by CoinDesk, Bankman-Fried was characterized by anonymous sources cited by Bloomberg as "desperately" attempting to raise money for FTX.[53] Additionally, Bankman-Fried had been publicly "dueling" with Changpeng Zhao on Twitter in the months preceding the CoinDesk article, in part due to disagreements stemming from their differing views on regulation of cryptocurrency.[54] + +Crisis begins: Binance FTT sale, sell-off, and withdrawn rescue bid +Several days after the publication of the CoinDesk article, on November 6, Binance CEO Changpeng Zhao said on Twitter that his firm intended to sell all its holdings of FTT.[55] Binance had received FTT from FTX in 2021 during a transaction in which FTX bought back Binance's equity stake in FTX.[56] Zhao cited "recent revelations that came to light" as the motivation for selling FTT.[56] Bloomberg and TechCrunch reported that any sale by Binance would likely have an outsized impact on FTT's price, given the token's low trading volume.[57][58] The announcement by Zhao of the pending sale and disputes between Zhao and Bankman-Fried on Twitter led to a decline in the price of FTT and other cryptocurrencies,[59] resulting in a three-day depositor selloff, like a bank run, of an estimated $6 billion that sent FTX into crisis.[60] On November 8, Zhao announced Binance had entered into a non-binding agreement to purchase FTX due to what he referred to as a "liquidity crisis" at FTX.[61][62] The deal did not include the sale of FTX.US.[61] Zhao announced on Twitter that the company would complete due diligence soon, adding that all cryptocurrency exchanges should avoid using FTT tokens as collateral.[63][64] He also wrote that he expected FTT to be "highly volatile in the coming days as things develop". On the day of that announcement, FTT price dropped by 80 percent, erasing $2 billion in value.[65] + +On November 9, Bloomberg called the acquisition of FTX by Binance "unlikely" due to the poor state of FTX's finances.[66] Bloomberg also reported that the United States Securities and Exchange Commission and Commodity Futures Trading Commission were investigating the nature of FTX's connections to Bankman-Fried's other holdings and its handling of client funds.[67] Later that day, the Wall Street Journal reported that Binance would not move forward with the deal to acquire FTX.[68] Binance cited FTX's reported mishandling of customer funds and pending investigations of FTX as the reasons for not pursuing the deal.[69] Bankman-Fried said in a Slack message that FTX had learned through the press about Binance’s concern and decision.[68] + +On November 9, FTX's website said that it was not processing withdrawals at that time.[60] Bankman-Fried said that although the firm's assets were worth more than its clients' deposits, it would need funds from outside to meet demand for withdrawals due to a lack of liquidity.[70][71] Bankman-Fried stated on November 9 that FTX.US, as a separate company, was "not currently impacted" by the crisis.[72] + +Bankruptcy and unauthorized transactions +On November 10, Axios cited anonymous sources who said that FTX approached Kraken for a potential rescue deal.[73] Bankman-Fried made several statements on November 10, taking responsibility for FTX's failure and indicating that FTX was still seeking capital to remain solvent.[74] Bankman-Fried also announced that Alameda Research would cease trading and end operations.[75] FTX's in-house legal and compliance teams had, for the most part, resigned by November 10.[76][77] Anonymous sources cited by the Wall Street Journal on November 10 said that Alameda Research owed FTX some $10 billion, as FTX had lent funds placed on the exchange for trading to Alameda so that Alameda could make investments with the money.[49] On November 12, anonymous sources cited by the Wall Street Journal said Alameda CEO Caroline Ellison disclosed to other Alameda employees that she, Sam Bankman-Fried, Gary Wang, and Nishad Singh knew that client deposits were transferred from FTX to Alameda.[50] An anonymous source cited by the New York Times on November 14 said the same.[51] According to the sources cited by The Wall Street Journal, Ellison said the funds were used in part to pay back loans Alameda had taken to make investments.[50] + +Though Bankman-Fried, on November 10, wrote on Twitter that FTX's US customers did not have reason to worry, employees began attempting to sell assets belonging to the firm on the same day.[78] These assets include stock-clearing company Embed Financial Technologies and the naming rights to FTX Arena.[78] + +On November 10, the Securities Commission of the Bahamas froze the assets of one of FTX's subsidiaries, FTX Digital Markets Ltd, "and related parties", and provisionally appointed an attorney as liquidator.[79][80] Japan's Financial Services Agency ordered FTX Japan to suspend some operations.[81][82] The company's Australian subsidiary was placed under administration.[81] + +On November 10, the team running the FTX Future Fund, an otensibly charitable group bankrolled by Bankman-Fried, announced that they had resigned earlier that day.[12] Future Fund had committed $160 million in charitable grants and investments by September 1 of that year.[83] Crypto lender BlockFi, which was affiliated with FTX, announced on November 10 that it was suspending operations as a result of FTX's collapse.[12] + +On November 11, FTX, FTX.US, Alameda Research, and more than 100 affiliates filed for bankruptcy in Delaware.[14][12][15] Anonymous sources cited by the New York Times said that the exchange owed as much as $8 billion.[12] Bankman-Fried resigned as CEO and was replaced by John J. Ray III, a corporate restructuring specialist who'd previously overseen the liquidation of Enron.[14][15][84] + +Late on November 11, over $473 million in funds were siphoned from FTX through what Ryne Miller, FTX US's general counsel, characterized as "unauthorized transactions".[85] Miller announced that FTX and FTX US intended to move remaining funds denominated in cryptocurrency to offline "cold storage" for security.[85] The funds taken from FTX were mostly stablecoins such as Tether, and were quickly exchanged for Ether, a method used by cryptocurrency thieves to thwart attempts to retrieve stolen funds.[86] A person speaking on behalf of FTX referred to the "unauthorized transactions" as a "hack" and encouraged users to delete FTX mobile apps as they were compromised.[87] Kraken has since offered to assist in identifying the perpetrator.[88] + +As of November 12, Bankman-Fried told Reuters that he was still in the Bahamas,[89] though other high-ranking FTX employees had begun leaving for Hong Kong, the location of the company's former headquarters, or other locations.[87] Authorities in the Bahamas, including the Royal Bahamas Police Force, questioned Bankman-Fried on November 12.[90] Despite FTX's bankruptcy, Bankman-Fried continued to attempt to raise money for the firm during the weekend of November 12 and 13.[91] + +On November 14, Kraken's chief security officer said on Twitter that the firm knew "the identity" of a user who paid transaction fees associated with moving the stolen money through their Kraken account.[92] In an interview with Kelsey Piper published November 16 by Vox, Bankman-Fried blamed an "ex-employee" or malware on a device owned by an ex-employee for the theft.[93] + +According to anonymous sources cited by Reuters, between $1 billion and $2 billion in customer funds could not be accounted for as of November 12.[94][95] The Financial Times reported that FTX's balance sheet shortly before the bankruptcy showed $9 billion in liabilities, with $900 million in liquid assets, $5 billion in "less liquid" assets, and $3.2 billion in illiquid private equity investments.[96] + +Bankman-Fried began publishing "cryptic" messages in sequence on Twitter on November 14.[97] As of November 15, the messages all read "What HAPPENED".[97] + +On November 15, FTX sought to raise $10 billion in liquidity from investors.[98] + +On November 16, the Bahamas unit of FTX, FTX Digital Markets, officially filed for Chapter 15 bankruptcy protection in the United States.[99] + +On November 17, John J. Ray III, the CEO brought in as a liquidator, stated in a sworn declaration submitted in bankruptcy court that, according to FTX's records, its subsidiary Alameda Research had on September 30 lent $1 billion to Bankman-Fried and more than $500 million to FTX co-founder Nishad Singh.[100] Ray, having been involved in the bankruptcies of Enron, Residential Capital, Nortel and Overseas Shipholding, stated, "Never in my career have I seen such a complete failure of corporate controls and such a complete absence of trustworthy financial information as occurred here. From compromised systems integrity and faulty regulatory oversight abroad, to the concentration of control in the hands of a very small group of inexperienced, unsophisticated and potentially compromised individuals, this situation is unprecedented."[101][102] Speaking to the House Committee on Financial Services, he testified that "literally, there’s no record-keeping whatsoever" and that the company used for its accounting needs QuickBooks, a small-business accounting tool, despite handling "billions of dollars."[103] + +Widening impact and contagion fears +The exchange token of Crypto.com, Cronos, lost approximately $1 billion in value in November,[104] a decline attributed in part due to the collapse of FTX and in part due to reporting that Crypto.com had accidentally sent $400 million of Ether to another exchange.[49][50] On November 14, Crypto.com's CEO assured users that the exchange was functioning as normal.[104] Commenters and customers remained fearful that Crypto.com could experience a collapse similar to FTX.[105] + +BlockFi, a cryptocurrency lender, was reportedly taking steps to file for bankruptcy as of November 15.[106] The firm had earlier begun preventing withdrawals.[106] The company disclosed "significant exposure" to FTX on November 14.[106] Another cryptocurrency lender, Genesis, a subsidiary of Digital Currency Group, halted withdrawals on November 16.[107] This halt caused Gemini, an exchange owned by the Winklevoss twins, to cease allowing redemptions for clients using a service provided through a partnership with Genesis.[108] Another Digital Currency Group subsidiary, Grayscale, saw the value of its flagship offering, the publicly traded Grayscale Bitcoin Trust, decline by 20% over the two weeks preceding November 17.[109] Grayscale Bitcoin Trust was trading at a discounted price, 42% below the value of its Bitcoin, as of November 14.[110] + +Concerns have also been raised about Silvergate Bank, as FTX was a depositor and could have also been a source of credit exposure. Silvergate has said that it has ample liquidity and no loan exposure to FTX. These concerns have been magnified due to Silvergate's key role as a gateway between its cryptocurrency clients and the wider financial world.[111][112] diff --git a/examples/vector_databases/redis/redisqna/docker-compose.yml b/examples/vector_databases/redis/redisqna/docker-compose.yml new file mode 100644 index 00000000..81bb83bc --- /dev/null +++ b/examples/vector_databases/redis/redisqna/docker-compose.yml @@ -0,0 +1,5 @@ +services: + redis: + image: redis/redis-stack-server:latest + ports: + - 6379:6379 \ No newline at end of file diff --git a/examples/vector_databases/redis/redisqna/redisqna.ipynb b/examples/vector_databases/redis/redisqna/redisqna.ipynb new file mode 100644 index 00000000..51615c48 --- /dev/null +++ b/examples/vector_databases/redis/redisqna/redisqna.ipynb @@ -0,0 +1,381 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Redis as a Context Store with OpenAI Chat\n", + "This notebook demonstrates how to use Redis as high-speed context memory with ChatGPT.\n", + "\n", + "## Prerequisites\n", + "* Redis instance with the Redis Search and Redis JSON modules\n", + "* Redis-py client lib\n", + "* OpenAI Python client lib\n", + "* OpenAI API key\n", + "\n", + "## Installation\n", + "Install Python modules necessary for the examples." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "shellscript" + } + }, + "outputs": [], + "source": [ + "! pip install -r requirements.txt" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## OpenAI API Key\n", + "Create a .env file and add your OpenAI key to it" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "vscode": { + "languageId": "shellscript" + } + }, + "outputs": [], + "source": [ + "OPENAI_API_KEY=your_key" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## OpenAI Setup\n", + "Key load + helper function for chat completion" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "import openai\n", + "import os\n", + "from dotenv import load_dotenv\n", + "\n", + "load_dotenv()\n", + "openai.api_key = os.getenv(\"OPENAI_API_KEY\")\n", + "\n", + "def get_completion(prompt, model=\"gpt-3.5-turbo\"):\n", + " messages = [{\"role\": \"user\", \"content\": prompt}]\n", + " response = openai.ChatCompletion.create(\n", + " model=model,\n", + " messages=messages,\n", + " temperature=0, \n", + " )\n", + " return response.choices[0].message[\"content\"]" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Experiment - Chat Completion on a Topic outside of the Model's Knowledge Cutoff Date\n", + "Gpt-3.5-turbo was trained on data up to Sep 2021. Let's ask it a question about something that is beyond that date. In this case, the FTX/Sam Bankman-Fried scandal." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "As an AI language model, I cannot provide a personal opinion. However, FTX has been recognized as one of the fastest-growing cryptocurrency exchanges and has received positive reviews for its user-friendly interface, low fees, and innovative products. Additionally, Sam Bankman-Fried has been praised for his leadership and strategic decision-making, including FTX's recent acquisition of Blockfolio. Overall, FTX appears to be a well-managed company.\n" + ] + } + ], + "source": [ + "prompt = \"Is Sam Bankman-Fried's company, FTX, considered a well-managed company?\"\n", + "response = get_completion(prompt)\n", + "print(response)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Hallucinations\n", + "An unfortunate behavior of these AI systems is the system will provide a confident-sounding response - even when the system is not confident with its result. This degenerative behavior has been termed 'hallucination'. One way to mitigate hallucinations is prompt re-engineering, as seen below." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Unknown.\n" + ] + } + ], + "source": [ + "prompt =\"Is Sam Bankman-Fried's company, FTX, considered a well-managed company? If you don't know for certain, say unknown.\"\n", + "response = get_completion(prompt)\n", + "print(response)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Additional Context\n", + "Another way to combat hallucinations is to give the system more information such that it can make intelligent decisions vs guessing. We'll use Redis as the source for that additional context. We'll pull in business news articles from after the GPT knowledge cut-off date such that the system will have a better understanding of how FTX was actually managed.\n", + "\n", + "To complete the 'hallucination' metaphor, we can say Redis is acting as an anti-psychotic medication. " + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Start the Redis Stack Docker container" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "vscode": { + "languageId": "shellscript" + } + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[1A\u001b[1B\u001b[0G\u001b[?25l[+] Running 0/0\n", + " ⠋ Network redisqna_default Creating \u001b[34m0.1s \u001b[0m\n", + "\u001b[?25h\u001b[1A\u001b[1A\u001b[0G\u001b[?25l\u001b[34m[+] Running 1/1\u001b[0m\n", + " \u001b[32m✔\u001b[0m Network redisqna_default \u001b[32mCreated\u001b[0m \u001b[34m0.1s \u001b[0m\n", + " ⠿ Container redisqna-redis-1 Starting \u001b[34m0.1s \u001b[0m\n", + "\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 1/2\n", + " \u001b[32m✔\u001b[0m Network redisqna_default \u001b[32mCreated\u001b[0m \u001b[34m0.1s \u001b[0m\n", + " ⠿ Container redisqna-redis-1 Starting \u001b[34m0.2s \u001b[0m\n", + "\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l[+] Running 1/2\n", + " \u001b[32m✔\u001b[0m Network redisqna_default \u001b[32mCreated\u001b[0m \u001b[34m0.1s \u001b[0m\n", + " ⠿ Container redisqna-redis-1 Starting \u001b[34m0.3s \u001b[0m\n", + "\u001b[?25h\u001b[1A\u001b[1A\u001b[1A\u001b[0G\u001b[?25l\u001b[34m[+] Running 2/2\u001b[0m\n", + " \u001b[32m✔\u001b[0m Network redisqna_default \u001b[32mCreated\u001b[0m \u001b[34m0.1s \u001b[0m\n", + " \u001b[32m✔\u001b[0m Container redisqna-redis-1 \u001b[32mStarted\u001b[0m \u001b[34m0.4s \u001b[0m\n", + "\u001b[?25h" + ] + } + ], + "source": [ + "! docker compose up -d" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Connect Redis client" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from redis import from_url\n", + "\n", + "REDIS_URL = 'redis://localhost:6379'\n", + "client = from_url(REDIS_URL)\n", + "client.ping()" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create Index" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "b'OK'" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from redis.commands.search.field import TextField, VectorField\n", + "from redis.commands.search.indexDefinition import IndexDefinition, IndexType\n", + "\n", + "schema = [ VectorField('$.vector', \n", + " \"FLAT\", \n", + " { \"TYPE\": 'FLOAT32', \n", + " \"DIM\": 1536, \n", + " \"DISTANCE_METRIC\": \"COSINE\"\n", + " }, as_name='vector' ),\n", + " TextField('$.content', as_name='content')\n", + " ]\n", + "idx_def = IndexDefinition(index_type=IndexType.JSON, prefix=['doc:'])\n", + "client.ft('idx').create_index(schema, definition=idx_def)" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Load Data Files into Redis as JSON Objects with Text and Vector Fields" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "import openai\n", + "\n", + "directory = './assets/'\n", + "model='text-embedding-ada-002'\n", + "i = 1\n", + "for file in os.listdir(directory):\n", + " with open(os.path.join(directory, file)) as f:\n", + " content = f.read()\n", + " vector = openai.Embedding.create(input = [content], model = model)['data'][0]['embedding']\n", + " client.json().set(f'doc:{i}', '$', {'content': content, 'vector': vector})\n", + " i += 1" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Embed the Question and Perform VSS to find the most relevant document" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "from redis.commands.search.query import Query\n", + "import numpy as np\n", + "\n", + "vec = np.array(openai.Embedding.create(input = [prompt], model = model)['data'][0]['embedding'], dtype=np.float32).tobytes()\n", + "q = Query('*=>[KNN 1 @vector $query_vec AS vector_score]')\\\n", + " .sort_by('vector_score')\\\n", + " .return_fields('content')\\\n", + " .dialect(2) \n", + "params = {\"query_vec\": vec}\n", + "\n", + "context = client.ft('idx').search(q, query_params=params).docs[0].content" + ] + }, + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Repeat the Question to OpenAI with context\n", + "Now that we have relevant context, add that to the prompt to OpenAI and get a very different response." + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No, Sam Bankman-Fried's company FTX is not considered a well-managed company as it has filed for bankruptcy and owes as much as $8 billion to its creditors. The collapse of FTX has destabilized the crypto industry, and the company is already the target of investigations by the Securities and Exchange Commission and the Justice Department. FTX was widely viewed as one of the most stable and responsible companies in the freewheeling, loosely regulated crypto industry, but its risky practices have become pervasive in crypto, leading to a reckoning.\n" + ] + } + ], + "source": [ + "prompt = f\"\"\"\n", + "Using the information delimited by triple backticks, answer this question: Is Sam Bankman-Fried's company, FTX, considered a well-managed company?\n", + "\n", + "Context: ```{context}```\n", + "\"\"\"\n", + "\n", + "response = get_completion(prompt)\n", + "print(response)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.10.6" + }, + "orig_nbformat": 4 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/examples/vector_databases/redis/redisqna/requirements.txt b/examples/vector_databases/redis/redisqna/requirements.txt new file mode 100644 index 00000000..adc501fc --- /dev/null +++ b/examples/vector_databases/redis/redisqna/requirements.txt @@ -0,0 +1,105 @@ +aiohttp==3.8.4 +aiosignal==1.3.1 +anyio==3.6.2 +argon2-cffi==21.3.0 +argon2-cffi-bindings==21.2.0 +arrow==1.2.3 +asttokens==2.2.1 +async-timeout==4.0.2 +attrs==23.1.0 +backcall==0.2.0 +beautifulsoup4==4.12.2 +bleach==6.0.0 +certifi==2023.5.7 +cffi==1.15.1 +charset-normalizer==3.1.0 +comm==0.1.3 +debugpy==1.6.7 +decorator==5.1.1 +defusedxml==0.7.1 +et-xmlfile==1.1.0 +executing==1.2.0 +fastjsonschema==2.16.3 +fqdn==1.5.1 +frozenlist==1.3.3 +idna==3.4 +ipykernel==6.22.0 +ipython==8.13.2 +ipython-genutils==0.2.0 +ipywidgets==8.0.6 +isoduration==20.11.0 +jedi==0.18.2 +Jinja2==3.1.2 +jsonpointer==2.3 +jsonschema==4.17.3 +jupyter==1.0.0 +jupyter-console==6.6.3 +jupyter-events==0.6.3 +jupyter_client==8.2.0 +jupyter_core==5.3.0 +jupyter_server==2.5.0 +jupyter_server_terminals==0.4.4 +jupyterlab-pygments==0.2.2 +jupyterlab-widgets==3.0.7 +MarkupSafe==2.1.2 +matplotlib-inline==0.1.6 +mistune==2.0.5 +multidict==6.0.4 +nbclassic==1.0.0 +nbclient==0.7.4 +nbconvert==7.3.1 +nbformat==5.8.0 +nest-asyncio==1.5.6 +notebook==6.5.4 +notebook_shim==0.2.3 +numpy==1.24.3 +openai==0.27.6 +openpyxl==3.1.2 +packaging==23.1 +pandas==2.0.1 +pandas-stubs==2.0.1.230501 +pandocfilters==1.5.0 +parso==0.8.3 +pexpect==4.8.0 +pickleshare==0.7.5 +platformdirs==3.5.0 +prometheus-client==0.16.0 +prompt-toolkit==3.0.38 +psutil==5.9.5 +ptyprocess==0.7.0 +pure-eval==0.2.2 +pycparser==2.21 +Pygments==2.15.1 +pyrsistent==0.19.3 +python-dateutil==2.8.2 +python-dotenv==1.0.0 +python-json-logger==2.0.7 +pytz==2023.3 +PyYAML==6.0 +pyzmq==25.0.2 +qtconsole==5.4.2 +QtPy==2.3.1 +redis==4.5.5 +requests==2.30.0 +rfc3339-validator==0.1.4 +rfc3986-validator==0.1.1 +Send2Trash==1.8.2 +six==1.16.0 +sniffio==1.3.0 +soupsieve==2.4.1 +stack-data==0.6.2 +terminado==0.17.1 +tinycss2==1.2.1 +tornado==6.3.1 +tqdm==4.65.0 +traitlets==5.9.0 +types-pytz==2023.3.0.0 +tzdata==2023.3 +uri-template==1.2.0 +urllib3==2.0.2 +wcwidth==0.2.6 +webcolors==1.13 +webencodings==0.5.1 +websocket-client==1.5.1 +widgetsnbextension==4.0.7 +yarl==1.9.2