Skip to main content
Cohere 是一家加拿大初创公司,提供自然语言处理模型,帮助企业改善人机交互。
本笔记本介绍如何开始使用 Cohere RAG 检索器。这使您能够利用通过各种连接器搜索文档的能力,或提供您自己的文档。
import getpass
import os

os.environ["COHERE_API_KEY"] = getpass.getpass()
from langchain_cohere import ChatCohere, CohereRagRetriever
from langchain_core.documents import Document
rag = CohereRagRetriever(llm=ChatCohere())
def _pretty_print(docs):
    for doc in docs:
        print(doc.metadata)
        print("\n\n" + doc.page_content)
        print("\n\n" + "-" * 30 + "\n\n")
_pretty_print(rag.invoke("What is cohere ai?"))
{'id': 'web-search_4:0', 'snippet': 'AI startup Cohere, now valued at over $2.1B, raises $270M\n\nKyle Wiggers 4 months\n\nIn a sign that there’s plenty of cash to go around for generative AI startups, Cohere, which is developing an AI model ecosystem for the enterprise, today announced that it raised $270 million as part of its Series C round.\n\nReuters reported earlier in the year that Cohere was in talks to raise “hundreds of millions” of dollars at a valuation of upward of just over $6 billion. If there’s credence to that reporting, Cohere appears to have missed the valuation mark substantially; a source familiar with the matter tells TechCrunch that this tranche values the company at between $2.1 billion and $2.2 billion.', 'title': 'AI startup Cohere, now valued at over $2.1B, raises $270M | TechCrunch', 'url': 'https://techcrunch.com/2023/06/08/ai-startup-cohere-now-valued-at-over-2-1b-raises-270m/'}


AI 初创公司 Cohere,现估值超过 21 亿美元,融资 2.7 亿美元

Kyle Wiggers 4 个月前

在生成式 AI 初创公司资金充裕的迹象下,为企业开发 AI 模型生态系统的 Cohere 今日宣布,在其 C 轮融资中筹集了 2.7 亿美元。

路透社今年早些时候报道称,Cohere 正在谈判以略高于 60 亿美元的估值筹集“数亿美元”。如果该报道可信,Cohere 似乎大幅错失了估值目标;一位知情人士告诉 TechCrunch,本轮融资对该公司的估值在 21 亿至 22 亿美元之间。


------------------------------


{'id': 'web-search_9:0', 'snippet': 'Cohere is a Canadian multinational technology company focused on artificial intelligence for the enterprise, specializing in large language models. Cohere was founded in 2019 by Aidan Gomez, Ivan Zhang, and Nick Frosst, and is headquartered in Toronto and San Francisco, with offices in Palo Alto and London.\n\nIn 2017, a team of researchers at Google Brain, which included Aidan Gomez, published a paper called "Attention is All You Need," which introduced the transformer machine learning architecture, setting state-of-the-art performance on a variety of natural language processing tasks. In 2019, Gomez and Nick Frosst, another researcher at Google Brain, founded Cohere along with Ivan Zhang, with whom Gomez had done research at FOR.ai. All of the co-founders attended University of Toronto.', 'title': 'Cohere - Wikipedia', 'url': 'https://en.wikipedia.org/wiki/Cohere'}


Cohere 是一家加拿大跨国科技公司,专注于企业人工智能,专精于大型语言模型。Cohere 由 Aidan Gomez、Ivan Zhang 和 Nick Frosst 于 2019 年创立,总部位于多伦多和旧金山,在帕洛阿尔托和伦敦设有办事处。

2017 年,包括 Aidan Gomez 在内的 Google Brain 研究团队发表了一篇名为《Attention is All You Need》的论文,该论文介绍了 transformer 机器学习架构,在各种自然语言处理任务上取得了最先进的性能。2019 年,Gomez 和 Google Brain 的另一位研究员 Nick Frosst 与 Ivan Zhang 共同创立了 Cohere,Gomez 曾与 Zhang 在 FOR.ai 一起进行研究。所有联合创始人均毕业于多伦多大学。


------------------------------


{'id': 'web-search_8:2', 'snippet': ' Cofounded by Aidan Gomez, a Google Brain alum and coauthor of the seminal transformer research paper, Cohere describes itself as being “on a mission to transform enterprises and their products with AI to unlock a more intuitive way to generate, search, and summarize information than ever before.” One key element of Cohere’s approach is its focus on data protection, deploying its models inside enterprises’ secure data environment.\n\n“We are both independent and cloud-agnostic, meaning we are not beholden to any one tech company and empower enterprises to implement customized AI solutions on the cloud of their choosing, or even on-premises,” says Martin Kon, COO and president of Cohere.', 'title': 'McKinsey and Cohere collaborate to transform clients with enterprise generative AI', 'url': 'https://www.mckinsey.com/about-us/new-at-mckinsey-blog/mckinsey-and-cohere-collaborate-to-transform-clients-with-enterprise-generative-ai'}


由 Aidan Gomez(Google Brain 校友、开创性 transformer 研究论文的合著者)联合创立的 Cohere 自称“致力于通过 AI 改变企业和其产品,以解锁比以往任何时候都更直观的信息生成、搜索和总结方式。”Cohere 方法的一个关键要素是其对数据保护的关注,将其模型部署在企业安全的数据环境中。

“我们既独立又云无关,这意味着我们不依赖于任何一家科技公司,并赋能企业在其选择的云上甚至本地部署定制的 AI 解决方案,”Cohere 首席运营官兼总裁 Martin Kon 表示。


------------------------------
_pretty_print(await rag.ainvoke("What is cohere ai?"))  # async version
{'id': 'web-search_9:0', 'snippet': 'Cohere is a Canadian multinational technology company focused on artificial intelligence for the enterprise, specializing in large language models. Cohere was founded in 2019 by Aidan Gomez, Ivan Zhang, and Nick Frosst, and is headquartered in Toronto and San Francisco, with offices in Palo Alto and London.\n\nIn 2017, a team of researchers at Google Brain, which included Aidan Gomez, published a paper called "Attention is All You Need," which introduced the transformer machine learning architecture, setting state-of-the-art performance on a variety of natural language processing tasks. In 2019, Gomez and Nick Frosst, another researcher at Google Brain, founded Cohere along with Ivan Zhang, with whom Gomez had done research at FOR.ai. All of the co-founders attended University of Toronto.', 'title': 'Cohere - Wikipedia', 'url': 'https://en.wikipedia.org/wiki/Cohere'}


Cohere 是一家加拿大跨国科技公司,专注于企业人工智能,专精于大型语言模型。Cohere 由 Aidan Gomez、Ivan Zhang 和 Nick Frosst 于 2019 年创立,总部位于多伦多和旧金山,在帕洛阿尔托和伦敦设有办事处。

2017 年,包括 Aidan Gomez 在内的 Google Brain 研究团队发表了一篇名为《Attention is All You Need》的论文,该论文介绍了 transformer 机器学习架构,在各种自然语言处理任务上取得了最先进的性能。2019 年,Gomez 和 Google Brain 的另一位研究员 Nick Frosst 与 Ivan Zhang 共同创立了 Cohere,Gomez 曾与 Zhang 在 FOR.ai 一起进行研究。所有联合创始人均毕业于多伦多大学。


------------------------------


{'id': 'web-search_8:2', 'snippet': ' Cofounded by Aidan Gomez, a Google Brain alum and coauthor of the seminal transformer research paper, Cohere describes itself as being “on a mission to transform enterprises and their products with AI to unlock a more intuitive way to generate, search, and summarize information than ever before.” One key element of Cohere’s approach is its focus on data protection, deploying its models inside enterprises’ secure data environment.\n\n“We are both independent and cloud-agnostic, meaning we are not beholden to any one tech company and empower enterprises to implement customized AI solutions on the cloud of their choosing, or even on-premises,” says Martin Kon, COO and president of Cohere.', 'title': 'McKinsey and Cohere collaborate to transform clients with enterprise generative AI', 'url': 'https://www.mckinsey.com/about-us/new-at-mckinsey-blog/mckinsey-and-cohere-collaborate-to-transform-clients-with-enterprise-generative-ai'}


由 Aidan Gomez(Google Brain 校友、开创性 transformer 研究论文的合著者)联合创立的 Cohere 自称“致力于通过 AI 改变企业和其产品,以解锁比以往任何时候都更直观的信息生成、搜索和总结方式。”Cohere 方法的一个关键要素是其对数据保护的关注,将其模型部署在企业安全的数据环境中。

“我们既独立又云无关,这意味着我们不依赖于任何一家科技公司,并赋能企业在其选择的云上甚至本地部署定制的 AI 解决方案,”Cohere 首席运营官兼总裁 Martin Kon 表示。


------------------------------


{'id': 'web-search_4:0', 'snippet': 'AI startup Cohere, now valued at over $2.1B, raises $270M\n\nKyle Wiggers 4 months\n\nIn a sign that there’s plenty of cash to go around for generative AI startups, Cohere, which is developing an AI model ecosystem for the enterprise, today announced that it raised $270 million as part of its Series C round.\n\nReuters reported earlier in the year that Cohere was in talks to raise “hundreds of millions” of dollars at a valuation of upward of just over $6 billion. If there’s credence to that reporting, Cohere appears to have missed the valuation mark substantially; a source familiar with the matter tells TechCrunch that this tranche values the company at between $2.1 billion and $2.2 billion.', 'title': 'AI startup Cohere, now valued at over $2.1B, raises $270M | TechCrunch', 'url': 'https://techcrunch.com/2023/06/08/ai-startup-cohere-now-valued-at-over-2-1b-raises-270m/'}


AI 初创公司 Cohere,现估值超过 21 亿美元,融资 2.7 亿美元

Kyle Wiggers 4 个月前

在生成式 AI 初创公司资金充裕的迹象下,为企业开发 AI 模型生态系统的 Cohere 今日宣布,在其 C 轮融资中筹集了 2.7 亿美元。

路透社今年早些时候报道称,Cohere 正在谈判以略高于 60 亿美元的估值筹集“数亿美元”。如果该报道可信,Cohere 似乎大幅错失了估值目标;一位知情人士告诉 TechCrunch,本轮融资对该公司的估值在 21 亿至 22 亿美元之间。


------------------------------
docs = rag.invoke(
    "Does langchain support cohere RAG?",
    documents=[
        Document(page_content="LangChain supports cohere RAG!"),
        Document(page_content="The sky is blue!"),
    ],
)
_pretty_print(docs)
{'id': 'doc-0', 'snippet': 'LangChain supports cohere RAG!'}


LangChain 支持 cohere RAG!


------------------------------
请注意,连接器和文档不能同时使用。如果您选择在 invoke 方法中提供文档,它们将优先使用,并且该特定请求将不会使用连接器,如上面的代码片段所示!