├── requirements.txt ├── assets ├── overview.png └── marqo_photo.jpeg ├── start_marqo.sh ├── .gitignore ├── main.py ├── news_summaries.txt ├── README.md └── news.py /requirements.txt: -------------------------------------------------------------------------------- 1 | marqo 2 | openai -------------------------------------------------------------------------------- /assets/overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iain-mackie/marqo-gpt3/HEAD/assets/overview.png -------------------------------------------------------------------------------- /assets/marqo_photo.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iain-mackie/marqo-gpt3/HEAD/assets/marqo_photo.jpeg -------------------------------------------------------------------------------- /start_marqo.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker pull marqoai/marqo:0.0.6; 4 | docker rm -f marqo; 5 | docker run --name marqo -it --privileged -p 8882:8882 --add-host host.docker.internal:host-gateway marqoai/marqo:0.0.6 -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | .idea 132 | data/* -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | 2 | import marqo 3 | import json 4 | import openai 5 | 6 | from news import MARQO_DOCUMENTS 7 | 8 | # init GPT3 API 9 | openai.organization = None 10 | openai.api_key = None 11 | 12 | DOC_INDEX_NAME = 'news-index' 13 | output = './news_summaries.txt' 14 | queries = [ 15 | # question # date filter 16 | ('How is the US Midterm Election going?', None), 17 | ('How is COP27 progressing?', None), 18 | ('What is happening in business today?', '2022-11-09'), 19 | 20 | ] 21 | 22 | 23 | if __name__ == '__main__': 24 | 25 | print('Establishing connection to marqo client.') 26 | mq = marqo.Client(url='http://localhost:8882') 27 | 28 | ######################################################################### 29 | ######################### MARQO INDEXING ################################ 30 | ######################################################################### 31 | # mq.index(DOC_INDEX_NAME).delete() 32 | try: 33 | print(f'document index build: {mq.index(DOC_INDEX_NAME).get_stats()}') 34 | except KeyboardInterrupt: 35 | raise 36 | except: 37 | print('Indexing documents') 38 | mq.index(DOC_INDEX_NAME).add_documents(MARQO_DOCUMENTS) 39 | print('Done') 40 | 41 | 42 | ######################################################################### 43 | ######################### GPT3 GENERATION ############################### 44 | ######################################################################### 45 | 46 | def get_no_context_prompt(question): 47 | """ GPT3 prompt without any context. """ 48 | return f'Question: {question}\n\nAnswer:' 49 | 50 | def get_context_prompt(question, context): 51 | """ GPT3 prompt without text-based context from marqo search. """ 52 | return f'Background: \n{context}\n\nQuestion: {question}\n\nAnswer:' 53 | 54 | def prompt_to_essay(prompt): 55 | """ Process GPT-3 prompt and clean string . """ 56 | response = openai.Completion.create( 57 | engine="text-davinci-002", 58 | prompt=prompt, 59 | temperature=0.0, 60 | max_tokens=256, 61 | top_p=1.0, 62 | frequency_penalty=0.0, 63 | presence_penalty=0.0 64 | ) 65 | return response['choices'][0]['text'].strip().replace('\n', ' ') 66 | 67 | 68 | ######################################################################### 69 | ########################### EXPERIMENTS ################################ 70 | ######################################################################### 71 | 72 | # Write to news_summaries.txt for analysis. 73 | with open(output, 'w') as f_out: 74 | for question, date in queries: 75 | f_out.write('////////////////////////////////////////////////////////\n') 76 | f_out.write('////////////////////////////////////////////////////////\n') 77 | 78 | f_out.write(f'question: {question}, date filter: {date}\n') 79 | 80 | f_out.write('================= GPT3 NO CONTEXT ======================\n') 81 | # Build prompt without context. 82 | prompt = get_no_context_prompt(question) 83 | f_out.write(f'Prompt: \n{prompt}\n') 84 | summary = prompt_to_essay(prompt) 85 | f_out.write(f'{summary}\n\n') 86 | 87 | f_out.write('================= GPT3 + Marqo =======================\n') 88 | # Query Marqo and set filters based on user query 89 | if isinstance(date, str): 90 | results = mq.index(DOC_INDEX_NAME).search(q=question, 91 | searchable_attributes=['Title', 'Description'], 92 | filter_string=f"date:{date}", 93 | limit=5) 94 | else: 95 | results = mq.index(DOC_INDEX_NAME).search(q=question, 96 | searchable_attributes=['Title', 'Description'], 97 | limit=5) 98 | 99 | # Build context using Marqo's highlighting functionality. 100 | context = '' 101 | for i, hit in enumerate(results['hits']): 102 | title = hit['Title'] 103 | text = hit['Description'] 104 | # for section, text in hit['_highlights'].items(): 105 | # context += text + '\n' 106 | context += f'Source {i}) {title} || {" ".join(text.split()[:60])}... \n' 107 | # Build prompt with Marqo context. 108 | prompt = get_context_prompt(question=question, context=context) 109 | f_out.write(f'Prompt: \n{prompt}\n') 110 | summary = prompt_to_essay(prompt) 111 | f_out.write(f'{summary}\n\n') 112 | 113 | -------------------------------------------------------------------------------- /news_summaries.txt: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////// 2 | //////////////////////////////////////////////////////// 3 | question: How is the US Midterm Election going?, date filter: None 4 | ================= GPT3 NO CONTEXT ====================== 5 | Prompt: 6 | Question: How is the US Midterm Election going? 7 | 8 | Answer: 9 | The US Midterm Election is going well. 10 | 11 | ================= GPT3 + Marqo ======================= 12 | Prompt: 13 | Background: 14 | Source 0) Georgia race goes to run-off as fight for US Senate neck-and-neck || Results are being declared in the US midterm elections, with control of Congress hanging in the balance. Republicans are likely to take control of the House of Representatives but the Senate fight is on a knife-edge. The race for the Senate seat in Georgia, which could determine the outcome, will not be decided until a runoff election on 6 December.... 15 | Source 1) US election results: When will we know who won? || As voters across the US wake up on Wednesday morning after the election, the results of the 2022 midterms are not yet completely clear - with officials across the country warning that elections may drag on for days or weeks. The expected delays are the result of a number of factors, including razor-thin margins between candidates, potentially contested elections, the... 16 | Source 2) Republican 'red wave' turns into a ripple, Georgia Senate headed to runoff || Republicans made modest gains in U.S. midterm elections but Democrats performed better than expected, as control of the Senate hinged on three races that remained too close to call on Wednesday afternoon. The Georgia U.S. Senate race between Democratic incumbent Raphael Warnock and Republican Herschel Walker will go to a Dec. 6 runoff, Edison Research projected. That means it could... 17 | Source 3) Control of U.S. Congress unclear as Republican 'red wave' fizzles || Republicans made modest gains in U.S. midterm elections but Democrats performed better than expected, as control of the Senate hinged on three races that remained too close to call on Wednesday afternoon. The Georgia U.S. Senate race between Democratic incumbent Raphael Warnock and Republican Herschel Walker will go to a Dec. 6 runoff, Edison Research projected. That means it could... 18 | Source 4) Allianz beats quarterly profit expectations, posts rosier 2022 outlook || German insurer Allianz on Wednesday posted a better-than-expected 17% rise in third-quarter net profit, helped by strength at its property and casualty division, and gave a more optimistic full-year outlook.... 19 | 20 | 21 | Question: How is the US Midterm Election going? 22 | 23 | Answer: 24 | The US Midterm Election is going neck-and-neck, with the Republicans likely to take control of the House of Representatives, but the Senate fight is on a knife-edge. The race for the Senate seat in Georgia, which could determine the outcome, will not be decided until a runoff election on 6 December. 25 | 26 | //////////////////////////////////////////////////////// 27 | //////////////////////////////////////////////////////// 28 | question: How is COP27 progressing?, date filter: None 29 | ================= GPT3 NO CONTEXT ====================== 30 | Prompt: 31 | Question: How is COP27 progressing? 32 | 33 | Answer: 34 | The COP27 climate conference is progressing well. The conference is focused on finalizing the details of the Paris Agreement, which was reached in 2015. 35 | 36 | ================= GPT3 + Marqo ======================= 37 | Prompt: 38 | Background: 39 | Source 0) What is COP27 and why is it important? || World leaders are discussing action to tackle climate change at the COP27 climate summit in Egypt. It follows a year of climate-related disasters and broken temperature records. UK Prime Minister Rishi Sunak is attending, having previously said he would not. United Nations (UN) climate summits are held every year, for governments to agree steps to limit global temperature rises. They... 40 | Source 1) Show us the money: Developing world at COP27 seeks financing details || Finance took centre stage at the COP27 climate talks on Wednesday, with U.N. experts publishing a list of projects worth $120 billion that investors could back to help poorer countries cut emissions and adapt to the impacts of global warming. A $3 billion water transfer project between Lesotho and Botswana and a $10 million plan to improve the public water... 41 | Source 2) COP27: Time to pay the climate bill - vulnerable nations || Leaders of countries flooded or parched due to climate change are pleading at the COP27 summit for an urgent financial lifeline from richer nations. "We will not give up... the alternative consigns us to a watery grave," Bahamas Prime Minister Philip Davis said.Countries are meeting in Sharm el-Sheikh, Egypt to discuss next steps in curbing climate change. Front line nations... 42 | Source 3) COP27: Ukraine a reason to act fast on climate change - Rishi Sunak || The war in Ukraine is a reason to act faster to tackle climate change, UK Prime Minister Rishi Sunak has told the UN climate summit COP27. "Climate and energy security go hand-in-hand," he said in his first international appearance since taking office. Leaders from 120 countries are meeting in Sharm el-Sheikh, Egypt to discuss next steps in curbing climate change.... 43 | Source 4) COP27: UAE and Egypt agree to build one of world's biggest wind farms || The presidents of the United Arab Emirates (UAE) and Egypt witnessed the signing of an agreement on Tuesday to develop one of the world's largest onshore wind projects in Egypt, according to an official statement on the Gulf nation's state news agency. The memorandum of understanding was signed between the UAE's renewable energy firm Masdar alongside its joint venture with... 44 | 45 | 46 | Question: How is COP27 progressing? 47 | 48 | Answer: 49 | COP27 is progressing well, with leaders from around the world discussing ways to tackle climate change. One key issue that has been raised is the need for more financing to help developing countries cut emissions and adapt to the impacts of global warming. Another issue that has been discussed is the importance of increasing renewable energy production, with the UAE and Egypt agreeing to develop one of the world's largest onshore wind projects. 50 | 51 | //////////////////////////////////////////////////////// 52 | //////////////////////////////////////////////////////// 53 | question: What is happening in business today?, date filter: 2022-11-09 54 | ================= GPT3 NO CONTEXT ====================== 55 | Prompt: 56 | Question: What is happening in business today? 57 | 58 | Answer: 59 | There is a lot happening in business today. The economy is slowly recovering from the recession, and businesses are starting to invest again. However, there is still a lot of uncertainty in the business world, and many companies are struggling to stay afloat. 60 | 61 | ================= GPT3 + Marqo ======================= 62 | Prompt: 63 | Background: 64 | Source 0) M&S warns of 'gathering storm' as shoppers squeezed || Marks and Spencer has warned of a "gathering storm" of higher costs for retailers and pressure on household budgets as it reported a fall in profits for the first half of the year. The High Street giant said trading would become "more challenging" after it revealed its profits dropped by 24%. It said "all parts" of retail would be affected... 65 | Source 1) Facebook-owner Meta to cut 11,000 staff || Meta, which owns Facebook, Instagram and WhatsApp, has announced that it will cut 13% of its workforce. The first mass lay-offs in the firm's history will result in 11,000 employees, from a worldwide headcount of 87,000, losing their jobs. Meta chief executive Mark Zuckerberg said the cuts were "the most difficult changes we've made in Meta's history". The news follows... 66 | Source 2) Allianz beats quarterly profit expectations, posts rosier 2022 outlook || German insurer Allianz on Wednesday posted a better-than-expected 17% rise in third-quarter net profit, helped by strength at its property and casualty division, and gave a more optimistic full-year outlook.... 67 | Source 3) Georgia race goes to run-off as fight for US Senate neck-and-neck || Results are being declared in the US midterm elections, with control of Congress hanging in the balance. Republicans are likely to take control of the House of Representatives but the Senate fight is on a knife-edge. The race for the Senate seat in Georgia, which could determine the outcome, will not be decided until a runoff election on 6 December.... 68 | Source 4) Tesla stock hits 2-year low after Musk sells $4 bln worth of shares || Tesla Inc (TSLA.O) shares slid to their lowest level in nearly two years on Wednesday after Chief Executive Elon Musk sold $3.95 billion worth of shares in the electric-vehicle maker. The shares were down 6.1% at $179.66 in afternoon trading. Musk's latest share sale fueled jitters about the fallout of his Twitter buy on the world's most valuable automaker, analysts... 69 | 70 | 71 | Question: What is happening in business today? 72 | 73 | Answer: 74 | There are a few major stories happening in business today. Firstly, Marks and Spencer has warned of a "gathering storm" of higher costs for retailers and pressure on household budgets. Secondly, Facebook-owner Meta is cutting 11,000 staff in its first mass lay-offs. And finally, Tesla stock has hit a 2-year low after CEO Elon Musk sold $4 billion worth of shares. 75 | 76 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Using Marqo to Power News Summarisation 2 | 3 | ## Who am I? 4 | 5 | My name is Iain Mackie and I lead NLP investments at Creator Fund and previously worked in Quant trading. I am currently finishing my PhD in neural search systems at the University of Glasgow and recently won the $500k grand prize at the Alexa TaskBot Challenge.🤖 6 | 7 | Today we announce that Creator Fund has led a £660,000 Pre-Seed investment into Marqo. Marqo allows search engines to think like humans through neural search. The Melbourne-based company is led by two senior engineers from Amazon Robotics and Australia. 8 | 9 | ## What is neural search? 10 | 11 | Search, or information retrieval, is the study of retrieving relevant information given a user query. The most obvious example is Google, where a user inputs a query and Google will return a ranked list of web documents. Search is complex because: 12 |
    13 |
  1. Indexes can have millions or billions of documents.
  2. 14 |
  3. Judgements mapping user requests can be incredibly sparse.
  4. 15 |
  5. Documents can be long with many different modalities (text, structured information, images, and videos).
  6. 16 |
17 | 18 | Historically due to scale and computations, search systems were based on inverted indexes, where each word is stored in a database, making it easy to run simple algorithms over billions of documents. For example, for the query "good startup", search algorithms such as BM25 would return results with "good" and "startup" words. However, with the explosion of large language models (LLMs) with billions of parameters (SBERT, BERT, T5, GPT3, etc.), neural search systems have vastly improved search effectiveness. Specifically, LLMs can draw semantic connections between similar terms, i.e. between "good startup" and words like "scalable", "strong founders", and "high growth". In addition, there has also been breakthroughs in multimodal neural models (CLIP, DALLE, etc.) that allow for aligned multimodal indexing and search. So, for example, you could search for images or videos that align with our "good startup" query (maybe the picture of Marqo below!). 19 | 20 | The problem is that multimodal search can be extremely beneficial in many multimodal applications (search engines, image recommendation, product search, etc.). Still, effective and robust search systems require technical experts to implement and keep up-to-date with this fast-moving search environment. Now that's where Marqo comes in... 21 | 22 | ## What is Marqo? 23 | 24 | Marqo is developing "tensor search for humans" that improves search relevance for multimodal search applications (text 💬, image 🖼️, video 📽️), while being simple to set up and scale. Whereas many current neural databases require specialised search engineers, Marqo is a simple API where developers can index and query within seconds. Specifically, Marqo effortlessly combines the robustness and expressiveness of traditional search engines, allowing for complex filters and lexical search, with your favourite multimodal neural search models such as S-Bert and CLIP. Furthermore, Marqo's cloud platform enables customers to easily deploy their applications with a pay-per-use and reduces costs due to pooled resources ☁️. They are already powering child-friendly search engines, NFT recommendation systems, and much much more! 25 | 26 | More than just the technology, we are backing two incredible founders. Jesse has a PhD in Physics from La Trobe University, Postdocs at UCL and Stanford, and was a Lead Machine Learning Scientist at Alexa and Amazon Robotics AI. Tom Hamer has computer science and economics degrees from the Australian National University and Cambridge, and was a software engineer within AWS' ElasticSearch and Database teams. Together, they have built a team of search enthusiasts with the passion and skillset to enable developers worldwide effortless access to the next generation of search. 27 | 28 |

29 | Jesse & Tom 30 | 31 | Marqo's open-source Github Github has reached 1.1k+ 🌟 in 6 weeks (top 10 trending libraries!). They have also launched the cloud beta that allows customers to pay-per-use and reduces costs due to pooled resources (join waiting list). Lastly, they are building a community of search enthusiasts tackling different problems (Slack). 32 | 33 | ## Topical news summarisation 34 | 35 | Now for the fun bit... 36 | 37 | I wanted to build a fun search application within minutes to show the ease and power of Marqo. I decided to build a news summarisation application, i.e. answer questions like "What is happening in business today?" that synthesises example news corpus (link). 38 | 39 | The plan is to use Marqo's search to provide useful context for a generation algorithm; we use OpenAI's GPT3 API (link). This is more formally called "retrieval-augmented generation" and helps with generation tasks that require specific knowledge that the model has not seen during training. For example, company-specific documents and news data that's "in the future". Overview of what we're planning: 40 | 41 |

42 | Overview 43 | 44 | 45 | Thus, we can see the problem when we solely ask GPT3, "What is happening in business today?" It does not know and thus generates a generic response: 46 | ``` 47 | Question: What is happening in business today? 48 | 49 | Answer: 50 | There is a lot happening in business today. The economy is slowly recovering from the recession, and businesses are starting to invest again... 51 | ``` 52 | In fact, anyone following the financial markets knows 'the "economy is slowly recovering" and "businesses are starting to invest again" is completely wrong!! 53 | 54 | To solve this, we need to start our Marqo docker container, which creates a Python API we'll interact with during this demo: 55 | ``` 56 | docker pull marqoai/marqo:0.0.6; 57 | docker rm -f marqo; 58 | docker run --name marqo -it --privileged -p 8882:8882 --add-host host.docker.internal:host-gateway marqoai/marqo:0.0.6 59 | ``` 60 | 61 | Next, let's look at our example news documents corpus, which contains BBC and Reuters news content from 8th and 9th of November. We use "_id" as Marqo document identifier, the "date" the article was written, "website" indicating the web domain, "Title" for the headline, and "Description" for the article body: 62 | ``` 63 | [ 64 | { 65 | '_id': '2', 66 | 'date': '2022-11-09', 67 | 'website': 'www.bbc.co.uk', 68 | 'Title': 'COP27: Time to pay the climate bill - vulnerable nations', 69 | 'Description': 'Leaders of countries flooded or parched due to climate change are pleading at the COP27 summit...' 70 | },... 71 | ] 72 | ``` 73 | 74 | We then index our news documents that manage both the lexical and neural embeddings. By default, Marqo uses SBERT from neural text embeding and has complete OpenSearch lexical and metadata functionality natively. 75 | ``` 76 | from news import MARQO_DOCUMENTS 77 | 78 | DOC_INDEX_NAME = ''news-index' 79 | 80 | print('Establishing connection to marqo client.') 81 | mq = marqo.Client(url='http://localhost:8882') 82 | 83 | print('Indexing documents') 84 | mq.index(DOC_INDEX_NAME).add_documents(MARQO_DOCUMENTS) 85 | ``` 86 | 87 | Now we have indexed our news documents, we can simply use Marqo Python search API to return relevant context for our GPT3 generation. For query "q", we use the question and want to match news context based on the "Title" and "Description" text. We also want to filter our documents for "today", which was '2022-11-09'. 88 | ``` 89 | question = 'What is happening in business today?' 90 | date = '2022-11-09' 91 | results = mq.index(DOC_INDEX_NAME).search( 92 | q=question, 93 | searchable_attributes=['Title', 'Description'], 94 | filter_string=f"date:{date}" 95 | limit=5) 96 | ``` 97 | 98 | Next, we insert Marqo's search results into GPT3 prompt as context, and we try generating an answer again:: 99 | ``` 100 | Background: 101 | Source 0) M&S warns of 'gathering storm' as shoppers squeezed || Marks and Spencer has warned of a "gathering storm" of higher costs for retailers and pressure on household budgets as it reported a fall in profits for the first half of the year. The High Street giant said trading would become "more challenging" after it revealed its profits dropped by 24%. It said "all parts" of retail would be affected... 102 | Source 1) Facebook-owner Meta to cut 11,000 staff || Meta, which owns Facebook, Instagram and WhatsApp, has announced that it will cut 13% of its workforce. The first mass lay-offs in the firm's history will result in 11,000 employees, from a worldwide headcount of 87,000, losing their jobs. Meta chief executive Mark Zuckerberg said the cuts were "the most difficult changes we've made in Meta's history". The news follows... 103 | Source 2) Allianz beats quarterly profit expectations, posts rosier 2022 outlook || German insurer Allianz on Wednesday posted a better-than-expected 17% rise in third-quarter net profit, helped by strength at its property and casualty division, and gave a more optimistic full-year outlook.... 104 | Source 3) Georgia race goes to run-off as fight for US Senate neck-and-neck || Results are being declared in the US midterm elections, with control of Congress hanging in the balance. Republicans are likely to take control of the House of Representatives but the Senate fight is on a knife-edge. The race for the Senate seat in Georgia, which could determine the outcome, will not be decided until a runoff election on 6 December.... 105 | Source 4) Tesla stock hits 2-year low after Musk sells $4 bln worth of shares || Tesla Inc (TSLA.O) shares slid to their lowest level in nearly two years on Wednesday after Chief Executive Elon Musk sold $3.95 billion worth of shares in the electric-vehicle maker. The shares were down 6.1% at $179.66 in afternoon trading. Musk's latest share sale fueled jitters about the fallout of his Twitter buy on the world's most valuable automaker, analysts... 106 | 107 | 108 | Question: What is happening in business today? 109 | 110 | Answer: 111 | There are a few major stories happening in business today. Firstly, Marks and Spencer has warned of a "gathering storm" of higher costs for retailers and pressure on household budgets. Secondly, Facebook-owner Meta is cutting 11,000 staff in its first mass lay-offs. And finally, Tesla stock has hit a 2-year low after CEO Elon Musk sold $4 billion worth of shares. 112 | ``` 113 | 114 | Sucess! You'll notice that using Marqo to add relevant and temporally correct context means we can build a news summarisation application with ease. So instead of wrong and vague answers, we get factually-grounded summaries based on retrieved facts such as: 115 |

    116 |
  1. Marks and Spencer has warned of a "gathering storm" of higher costs for retailers
  2. 117 |
  3. Facebook-owner Meta is cutting 11,000 staff
  4. 118 |
  5. Tesla stock has hit a 2-year low after CEO Elon Musk sold $4 billion worth of shares
  6. 119 |
120 | 121 | Full code: here (you'll need GPT3 API token) 122 | -------------------------------------------------------------------------------- /news.py: -------------------------------------------------------------------------------- 1 | MARQO_DOCUMENTS = [ 2 | { 3 | '_id': '1', 4 | 'date': '2022-11-09', 5 | 'website': 'www.bbc.co.uk', 6 | 'Title': 'M&S warns of \'gathering storm\' as shoppers squeezed', 7 | 'Description': 'Marks and Spencer has warned of a "gathering storm" of higher costs for retailers and pressure on household budgets as it reported a fall in profits for the first half of the year. The High Street giant said trading would become "more challenging" after it revealed its profits dropped by 24%. It said "all parts" of retail would be affected by the UK\'s economic climate, adding unviable firms would go bust. But M&S said its business could "prove more resilient" due to its clientele. Many UK businesses are being hit by rising energy bills, wage costs and raw materials prices. Consumers are also cutting back their spending, with the Bank of England warning the UK is facing its longest recession since records began. M&S said the "combined impacts of the cost-of-living squeeze" and the increased cost of doing business was "creating pressure on margins industry-wide".' 8 | }, 9 | { 10 | '_id': '2', 11 | 'date': '2022-11-09', 12 | 'website': 'www.bbc.co.uk', 13 | 'Title': 'COP27: Time to pay the climate bill - vulnerable nations', 14 | 'Description': 'Leaders of countries flooded or parched due to climate change are pleading at the COP27 summit for an urgent financial lifeline from richer nations.\n\"We will not give up... the alternative consigns us to a watery grave,\" Bahamas Prime Minister Philip Davis said.Countries are meeting in Sharm el-Sheikh, Egypt to discuss next steps in curbing climate change. Front line nations want a special compensation fund for the climate impacts they cannot recover from. "I\'m not here to ask any of you to love the people of my country with the same passion as I do," Mr Davis told leaders. "I\'m asking what is it worth to you to have millions of climate refugees to turn into tens of millions, putting pressure on political and economic systems around the world,\" he said.' 15 | }, 16 | { 17 | '_id': '3', 18 | 'date': '2022-11-09', 19 | 'website': 'www.bbc.co.uk', 20 | 'Title': 'World Cup 2022: Wales name injury doubt Joe Allen in 26-man squad', 21 | 'Description': 'Robert Page has named his 26-man squad for Wales\' first World Cup in 64 years, with midfielder Joe Allen included despite being a major injury doubt.Gareth Bale captains a squad that has no surprising inclusions or omissions. Rhys Norrington-Davies is out with a hamstring injury so Tom Lockyer is recalled more than a year since he last played for Wales, while a calf injury rules out forward Tyler Roberts. Wales face the United States in their opening World Cup match on 21 November. They are joined in Group B by Iran and England, who name their squad on Thursday.' 22 | }, 23 | { 24 | '_id': '4', 25 | 'date': '2022-11-09', 26 | 'website': 'www.bbc.co.uk', 27 | 'Title': 'I regret Williamson job ended in resignation, says Rishi Sunak', 28 | 'Description': 'Rishi Sunak has said he regrets Sir Gavin Williamson\'s ministerial appointment ended in resignation amid bullying claims against him. The prime minister said Sir Gavin had been right to resign, adding his behaviour had been "unacceptable". Mr Sunak said he had not known of "specific concerns" about his conduct in two previous ministerial roles. But Labour\'s Sir Keir Starmer accused him of failing to "stand up to a run-of-the-mill bully\".' 29 | }, 30 | { 31 | '_id': '5', 32 | 'date': '2022-11-09', 33 | 'website': 'www.bbc.co.uk', 34 | 'Title': 'Facebook-owner Meta to cut 11,000 staff', 35 | 'Description': 'Meta, which owns Facebook, Instagram and WhatsApp, has announced that it will cut 13% of its workforce. The first mass lay-offs in the firm\'s history will result in 11,000 employees, from a worldwide headcount of 87,000, losing their jobs. Meta chief executive Mark Zuckerberg said the cuts were "the most difficult changes we\'ve made in Meta\'s history". The news follows major lay-offs at Twitter, which cut about half its staff, and other tech firms. "I know this is tough for everyone, and I\'m especially sorry to those impacted," he wrote in a statement. Mr Zuckerberg blamed massive long-term expectations for growth based on the firm\'s rise in revenue during the pandemic.' 36 | }, 37 | { 38 | '_id': '6', 39 | 'date': '2022-11-08', 40 | 'website': 'www.bbc.co.uk', 41 | 'Title': 'US election results: When will we know who won?', 42 | 'Description': 'As voters across the US wake up on Wednesday morning after the election, the results of the 2022 midterms are not yet completely clear - with officials across the country warning that elections may drag on for days or weeks. The expected delays are the result of a number of factors, including razor-thin margins between candidates, potentially contested elections, the possibility of recounts and even a likely run-off in Georgia - a key Senate battleground. Other delays will be due to the decentralised way in which elections are set up in the US, in which states have varied rules for how mail-in ballots are counted, and when. Live: Latest updates as contest goes to the wire. The issue of delays has been a politically contentious one since the 2020 presidential election, when then-President Donald Trump attempted to claim victory the following morning while votes were still being tallied, declaring continued voting counting a "fraud" and an "embarrassment".', 43 | }, 44 | { 45 | '_id': '7', 46 | 'date': '2022-11-09', 47 | 'website': 'www.bbc.co.uk', 48 | 'Title': 'Georgia race goes to run-off as fight for US Senate neck-and-neck', 49 | 'Description': 'Results are being declared in the US midterm elections, with control of Congress hanging in the balance. Republicans are likely to take control of the House of Representatives but the Senate fight is on a knife-edge. The race for the Senate seat in Georgia, which could determine the outcome, will not be decided until a runoff election on 6 December. The contest there between Republican Herschel Walker and Democrat Raphael Warnock is too close to call. Democrat John Fetterman, who suffered a stroke in May, defeated his Republican opponent Mehmet Oz to flip a key Senate seat in Pennsylvania. But the results of two other races that will decide the contest have yet to be called - in Nevada and Arizona. If Democrats lose control of either chamber of Congress, Republicans will be able to block President Joe Biden\'s agenda. Meanwhile Florida\'s Republican governor Ron DeSantis, a possible 2024 presidential contender, has won a large victory to stay in office.', 50 | }, 51 | { 52 | '_id': '8', 53 | 'date': '2022-11-08', 54 | 'website': 'www.bbc.co.uk', 55 | 'Title': 'Tesla recalls 40,000 cars over power-steering fault', 56 | 'Description': 'Tesla is recalling just over 40,000 cars in the US because of a potential power-steering problem. Elon Musk\'s electric-car manufacturer says the vehicles\' power-steering assist system may fail on rough roads or after hitting a pothole. The National Highway Traffic Safety Administration said it could require greater steering effort, especially at low speeds, increasing crash risks. Tesla has released a software update to recalibrate the system. It was unaware of any injuries or deaths in connection with the problem, it said. However, 314 vehicle alerts have been issued for US vehicles that may be related to the recall. The recall affects the 2017-21 Model S and Model X vehicles.', 57 | }, 58 | { 59 | '_id': '9', 60 | 'date': '2022-11-08', 61 | 'website': 'www.bbc.co.uk', 62 | 'Title': 'COP27: Ukraine a reason to act fast on climate change - Rishi Sunak', 63 | 'Description': 'The war in Ukraine is a reason to act faster to tackle climate change, UK Prime Minister Rishi Sunak has told the UN climate summit COP27. "Climate and energy security go hand-in-hand," he said in his first international appearance since taking office. Leaders from 120 countries are meeting in Sharm el-Sheikh, Egypt to discuss next steps in curbing climate change. Key topics are compensation and support for the most-affected countries. "Putin\'s abhorrent war in Ukraine and rising energy prices across the world are not a reason to go slow on climate change. They are a reason to act faster," Mr Sunak said. "We can bequeath our children a greener planet and a more prosperous future [...] There really is room for hope," he added.', 64 | }, 65 | { 66 | '_id': '10', 67 | 'date': '2022-11-08', 68 | 'website': 'www.bbc.co.uk', 69 | 'Title': 'Millions to receive latest cost-of-living payment', 70 | 'Description': 'Eight million people on low incomes who receive certain benefits will start getting the second instalment of a targeted cost-of-living payment. The £324 payment would be made directly into bank accounts between now and 23 November, the Department for Work and Pensions (DWP) said. Those who qualify via tax credits will receive it by the end of the month. A first grant of £326 was paid earlier in the year and, together, they are designed to assist with rising bills. When will I get the £400 energy discount? The support, totalling £650, is for those across the UK on certain benefits, including Universal Credit and pension credit. It is the largest part of direct financial assistance from the government to tackle costs such as energy bills. The funds are paid directly into the same accounts used to receive benefits payments, with the reference of the recipients\' national insurance number followed by "DWP COL".', 71 | }, 72 | { 73 | '_id': '11', 74 | 'date': '2022-11-09', 75 | 'website': 'www.reuters.com', 76 | 'Title': 'Republican \'red wave\' turns into a ripple, Georgia Senate headed to runoff', 77 | 'Description': 'Republicans made modest gains in U.S. midterm elections but Democrats performed better than expected, as control of the Senate hinged on three races that remained too close to call on Wednesday afternoon. The Georgia U.S. Senate race between Democratic incumbent Raphael Warnock and Republican Herschel Walker will go to a Dec. 6 runoff, Edison Research projected. That means it could be weeks until control of that chamber is known, unless Democrats hold off challengers in Nevada and Arizona. Republicans picked up at least seven seats in the U.S. House of Representatives, Edison Research projected. That would be two more than needed to wrest control of the chamber from Democrats, though with 45 races still uncalled, the Republican margin could go up or down. But they appeared to be far short of the sweeping "red wave" victory they had sought, as Democrats were avoiding the kind of heavy midterm defeat that often plagues sitting presidents of either party. The results appeared to show voters punishing Biden for presiding over an economy hit by steep inflation, while also lashing out against Republican efforts to ban abortion and cast doubt on the nation\'s vote-counting process.' 78 | }, 79 | { 80 | '_id': '12', 81 | 'date': '2022-11-09', 82 | 'website': 'www.reuters.com', 83 | 'Title': 'Tesla stock hits 2-year low after Musk sells $4 bln worth of shares', 84 | 'Description': 'Tesla Inc (TSLA.O) shares slid to their lowest level in nearly two years on Wednesday after Chief Executive Elon Musk sold $3.95 billion worth of shares in the electric-vehicle maker. The shares were down 6.1% at $179.66 in afternoon trading. Musk\'s latest share sale fueled jitters about the fallout of his Twitter buy on the world\'s most valuable automaker, analysts said. The billionaire\'s recent acquisition of Twitter sparked investor concerns including whether he would be distracted from running Tesla or divert resources to the social media company. Some investors also feared the possible impact on Tesla\'s sales and brand as well as potential pressure on Tesla from countries trying to control online speech. The latest sale brings the total amount of Tesla stock sold by Musk since last November to about $36 billion - despite his having said earlier that he would sell no more of his shares.' 85 | }, 86 | { 87 | '_id': '13', 88 | 'date': '2022-11-08', 89 | 'website': 'www.reuters.com', 90 | 'Title': 'Meta will begin laying off employees on Wednesday morning - WSJ', 91 | 'Description': 'Meta Platforms Inc (META.O) will begin laying off employees on Wednesday morning, Chief Executive Mark Zuckerberg told hundreds of executives on Tuesday, the Wall Street Journal reported. Zuckerberg appeared downcast in Tuesday\'s meeting and said he was accountable for the company\'s missteps and his overoptimism about growth had led to overstaffing, the report added, citing people familiar with the matter. The specific employees losing their jobs will be informed over the course of the morning, the report said. Meta\'s head of human resources, Lori Goler, said employees who lose their jobs will be provided with at least four months of salary as severance, the WSJ reported, citing people familiar with the matter. Meta reported more than 87,000 employees at the end of September.' 92 | }, 93 | { 94 | '_id': '14', 95 | 'date': '2022-11-09', 96 | 'website': 'www.reuters.com', 97 | 'Title': 'Disney\'s steep streaming costs push shares to 2-1/2-year low', 98 | 'Description': 'Shares in Walt Disney Co (DIS.N) tumbled 12% to the lowest since March 2020 on Wednesday, as ballooning costs at the entertainment giant\'s fast-growing streaming division cast a shadow on strong subscriber additions. Disney+ has attracted millions of subscribers and will launch an ad-supported tier next month, but executives\' promise of profitability next year and forecast for operating results in the next quarter failed to impress. The company missed analysts\' expectations for fourth-quarter earnings, after a $1.5 billion loss in its streaming division. "Disney\'s streaming results are indicative of the tightrope it is walking," said Fred Boxa, associate director at consulting firm Arthur D. Little. Finance chief Christine McCarthy, in a call with analysts on Tuesday, said the ad tier was not expected to meaningfully impact results until later in the financial year.' 99 | }, 100 | { 101 | '_id': '15', 102 | 'date': '2022-11-08', 103 | 'website': 'www.reuters.com', 104 | 'Title': 'COP27: UAE and Egypt agree to build one of world\'s biggest wind farms', 105 | 'Description': 'The presidents of the United Arab Emirates (UAE) and Egypt witnessed the signing of an agreement on Tuesday to develop one of the world\'s largest onshore wind projects in Egypt, according to an official statement on the Gulf nation\'s state news agency. The memorandum of understanding was signed between the UAE\'s renewable energy firm Masdar alongside its joint venture with Egypt\'s main renewable energy developer Infinity and Hassan Allam Utilities, the statement on news agency WAM said. Masdar, which has a portfolio of renewable energy assets with a combined value of more than $20 billion and a total capacity of more than 15 GW, said the new project would be its biggest yet. The 10 GW farm would produce 47,790 GWh of clean energy annually and offset 23.8 million tonnes of carbon dioxide emissions, equivalent to around 9% of Egypt\'s current CO2 emissions."With this agreement to develop our largest ever project, Masdar is proud to bolster our contribution to Egypt\'s renewable energy goals," Masdar\'s CEO Mohamed Jameel al-Ramahi said.' 106 | }, 107 | { 108 | '_id': '16', 109 | 'date': '2022-11-08', 110 | 'website': 'www.reuters.com', 111 | 'Title': 'Supreme Court urged to reject Pennsylvania\'s \'consent-by-registration\' law', 112 | 'Description': 'Reuters) - The U.S. Supreme Court on Tuesday heard arguments over whether states can require corporations to consent to the jurisdiction of their courts when they register to do business in the state, in a case that could dramatically expand state courts\' jurisdiction over corporations around the country. The dispute arises from a petition by Virginia resident Robert Mallory, who asked the nation\'s top court to revive his lawsuit in Pennsylvania state court against his former employer, Virginia-based Norfolk Southern Railway Co, claiming he developed colon cancer because of asbestos exposure on the job. Pennsylvania had a statute requiring companies to consent to its courts\' jurisdiction when they register to do business there. Norfolk Southern, one of the nation\'s largest railway operators, maintained that the law violates its due process rights under the U.S. Constitution\'s 14th Amendment. The Pennsylvania Supreme Court agreed, affirming the trial court\'s dismissal of Mallory\'s case. "Fidelity to the original public meaning of the 14th Amendment in this case means that the flesh-and-blood little guy wins and the Fortune 500 company loses," Ashley Keller of Keller Postman, a lawyer for Mallory, told the justices on Tuesday, urging them to reverse.' 113 | }, 114 | { 115 | '_id': '17', 116 | 'date': '2022-11-09', 117 | 'website': 'www.reuters.com', 118 | 'Title': 'Show us the money: Developing world at COP27 seeks financing details', 119 | 'Description': 'Finance took centre stage at the COP27 climate talks on Wednesday, with U.N. experts publishing a list of projects worth $120 billion that investors could back to help poorer countries cut emissions and adapt to the impacts of global warming. A $3 billion water transfer project between Lesotho and Botswana and a $10 million plan to improve the public water system in Mauritius were among dozens of projects listed, including 19 in Africa.We can now show that a meaningful pipeline of investible opportunities does exist across the economies that need finance most," Mahmoud Mohieldin, one of the U.N. appointed experts, known as U.N. Climate Change High-Level Champions, said in a statement to accompany the report. n an effort to answer the argument by private sector financiers that it\'s too risky to invest more in emerging markets, the experts, who help the COP host-governments engage with business, pulled together a list of projects that could be funded more quickly.' 120 | }, 121 | { 122 | '_id': '18', 123 | 'date': '2022-11-09', 124 | 'website': 'www.reuters.com', 125 | 'Title': 'Control of U.S. Congress unclear as Republican \'red wave\' fizzles', 126 | 'Description': 'Republicans made modest gains in U.S. midterm elections but Democrats performed better than expected, as control of the Senate hinged on three races that remained too close to call on Wednesday afternoon. The Georgia U.S. Senate race between Democratic incumbent Raphael Warnock and Republican Herschel Walker will go to a Dec. 6 runoff, Edison Research projected. That means it could be weeks until control of that chamber is known, unless Democrats hold off challengers in Nevada and Arizona. Republicans picked up at least eight seats in the U.S. House of Representatives, Edison Research projected. That would be three more than needed to wrest control of the chamber from Democrats, though with 44 races still uncalled the Republican margin could go up or down and might not be resolved for days. Even a slim House majority would let Republicans hem in Democratic President Joe Biden during his next two years in office, blocking legislation and launching potentially politically damaging investigations.', 127 | }, 128 | { 129 | '_id': '19', 130 | 'date': '2022-11-09', 131 | 'website': 'www.reuters.com', 132 | 'Title': 'Allianz beats quarterly profit expectations, posts rosier 2022 outlook', 133 | 'Description': 'German insurer Allianz on Wednesday posted a better-than-expected 17% rise in third-quarter net profit, helped by strength at its property and casualty division, and gave a more optimistic full-year outlook.' 134 | }, 135 | { 136 | '_id': '20', 137 | 'date': '2022-11-09', 138 | 'website': 'www.bbc.co.uk', 139 | 'Title': 'What is COP27 and why is it important?', 140 | 'Description': 'World leaders are discussing action to tackle climate change at the COP27 climate summit in Egypt. It follows a year of climate-related disasters and broken temperature records. UK Prime Minister Rishi Sunak is attending, having previously said he would not. United Nations (UN) climate summits are held every year, for governments to agree steps to limit global temperature rises. They are referred to as COPs, which stands for "Conference of the Parties". The parties are the attending countries that signed up to the original UN climate agreement in 1992. COP27 is the 27th annual UN meeting on climate. It is taking place in Sharm el-Sheikh until 18 November.' 141 | }, 142 | 143 | ] 144 | 145 | 146 | --------------------------------------------------------------------------------