SuperAPI AI 工具集

cohere-langchain

智能体与模型

查看项目

更新于 10-16 10:52

技能介绍

用途

cohere-langchain 是 Cohere 与 LangChain 的集成参考,面向需要构建 RAG(检索增强生成)管线、链和智能体的开发者。它覆盖 ChatCohere、CohereEmbeddings、CohereRerank 和 CohereRagRetriever 等核心组件。

主要能力

  • ChatCohere:基础对话、流式输出、提示模板,以及面向智能体的推荐参数设置。
  • CohereEmbeddings:生成查询向量与文档向量,可结合 FAISS 等向量库做相似度搜索。
  • CohereRerank:对文档重排,并可与上下文压缩检索器组合使用。
  • 工具调用:通过 bind_tools 绑定工具并读取 tool_calls。
  • 结构化输出:使用 Pydantic 模型配合 with_structured_output 获取结构化结果。
  • 完整 RAG 链:串联嵌入、向量库、重排、提示与 LLM 输出解析。

使用方式

安装命令为:

pip install langchain-cohere langchain langchain-core

导入时使用 from langchain_cohere import (...),而非已弃用的 langchain_community。

适用场景

适用于在 LangChain 中接入 Cohere 的对话、嵌入、重排、工具调用、结构化输出,以及构建完整 RAG 链。

限制

模型兼容性方面,Command A Reasoning 和 Command A Vision 在 LangChain 中不受支持,需使用 Cohere 原生 SDK。

官方资源

  • 文档与 Cookbook:https://github.com/cohere-ai/cohere-developer-experience
  • API 参考:https://docs.cohere.com/reference/about