Skip to main content
Contextual AI 提供最先进的 RAG 组件,专为准确可靠的企业 AI 应用而设计。我们的 LangChain 集成为我们的专业模型提供了独立的 API 端点:
  • 接地语言模型(GLM):全球最接地的语言模型,通过优先考虑对检索知识的忠实度来最小化幻觉。GLM 以内联归因提供卓越的事实准确性,是企业 RAG 和智能体应用中对可靠性要求极高的理想选择。
  • 遵循指令的重排器:第一个遵循自定义指令的重排器,可根据时效性、来源或文档类型等特定标准智能地对文档进行优先排序。在行业基准上超越竞争对手,我们的重排器解决了企业知识库中的信息冲突问题。
Contextual AI 由 RAG 技术的发明者创立,其专业组件帮助创新团队加速开发生产就绪的 RAG 智能体,提供具有卓越准确性的响应。

接地语言模型(GLM)

接地语言模型(GLM)专门为最小化企业 RAG 和智能体应用中的幻觉而设计。GLM 提供:
  • 在 FACTS 基准测试中 88% 的强劲事实准确性(查看基准测试结果
  • 严格基于提供的知识来源并带有内联归因的响应(阅读产品详情
  • 直接集成在生成响应中的精确来源引用
  • 优先考虑检索到的上下文而非参数知识(查看技术概述
  • 信息不可用时明确承认不确定性
GLM 可作为 RAG 管道中通用 LLM 的直接替代品,大幅提高关键任务企业应用的可靠性。

遵循指令的重排器

全球首款遵循指令的重排器以前所未有的控制力和准确性彻底改变了文档排序。主要功能包括:
  • 通过自然语言指令根据时效性、来源、元数据等对文档进行优先排序(了解工作原理
  • 在 BEIR 基准测试中以 61.2 的得分表现出色,大幅超越竞争对手(查看基准测试数据
  • 智能解决多知识来源中的信息冲突
  • 作为现有重排器的无缝直接替代品
  • 通过自然语言命令对文档排序进行动态控制
该重排器在处理可能含有矛盾信息的企业知识库时表现出色,允许您指定在各种场景中哪些来源应优先。

在 LangChain 中使用 Contextual AI

详情请参阅此处 此集成让您可以轻松将 Contextual AI 的 GLM 和遵循指令的重排器融入 LangChain 工作流。GLM 确保您的应用提供严格接地的响应,而重排器通过智能优先排序最相关的文档显著提高检索质量。 无论您是为受监管行业还是注重安全的环境构建应用,Contextual AI 都提供企业用例所需的准确性、控制力和可靠性。 立即开始免费试用,体验面向企业 AI 应用的最接地语言模型和遵循指令的重排器。

接地语言模型

# 集成接地语言模型
import getpass
import os

from langchain_contextual import ChatContextual

# 设置凭据
if not os.getenv("CONTEXTUAL_AI_API_KEY"):
    os.environ["CONTEXTUAL_AI_API_KEY"] = getpass.getpass(
        "Enter your Contextual API key: "
    )

# 初始化 Contextual LLM
llm = ChatContextual(
    model="v1",
    api_key="",
)
# 包含系统提示(可选)
system_prompt = "You are a helpful assistant that uses all of the provided knowledge to answer the user's query to the best of your ability."

# 在此以字符串数组形式提供您知识库中的知识
knowledge = [
    "There are 2 types of dogs in the world: good dogs and best dogs.",
    "There are 2 types of cats in the world: good cats and best cats.",
]

# 创建您的消息
messages = [
    ("human", "What type of cats are there in the world and what are the types?"),
]

# 通过提供知识字符串和可选系统提示来调用 GLM
# 如果您想关闭 GLM 的评论,请将 True 传递给 `avoid_commentary` 参数
ai_msg = llm.invoke(
    messages, knowledge=knowledge, system_prompt=system_prompt, avoid_commentary=True
)

print(ai_msg.content)
According to the information available, there are two types of cats in the world:

1. Good cats
2. Best cats

遵循指令的重排器

import getpass
import os

from langchain_contextual import ContextualRerank

if not os.getenv("CONTEXTUAL_AI_API_KEY"):
    os.environ["CONTEXTUAL_AI_API_KEY"] = getpass.getpass(
        "Enter your Contextual API key: "
    )


api_key = ""
model = "ctxl-rerank-en-v1-instruct"

compressor = ContextualRerank(
    model=model,
    api_key=api_key,
)

from langchain_core.documents import Document

query = "What is the current enterprise pricing for the RTX 5090 GPU for bulk orders?"
instruction = "Prioritize internal sales documents over market analysis reports. More recent documents should be weighted higher. Enterprise portal content supersedes distributor communications."

document_contents = [
    "Following detailed cost analysis and market research, we have implemented the following changes: AI training clusters will see a 15% uplift in raw compute performance, enterprise support packages are being restructured, and bulk procurement programs (100+ units) for the RTX 5090 Enterprise series will operate on a $2,899 baseline.",
    "Enterprise pricing for the RTX 5090 GPU bulk orders (100+ units) is currently set at $3,100-$3,300 per unit. This pricing for RTX 5090 enterprise bulk orders has been confirmed across all major distribution channels.",
    "RTX 5090 Enterprise GPU requires 450W TDP and 20% cooling overhead.",
]

metadata = [
    {
        "Date": "January 15, 2025",
        "Source": "NVIDIA Enterprise Sales Portal",
        "Classification": "Internal Use Only",
    },
    {"Date": "11/30/2023", "Source": "TechAnalytics Research Group"},
    {
        "Date": "January 25, 2025",
        "Source": "NVIDIA Enterprise Sales Portal",
        "Classification": "Internal Use Only",
    },
]

documents = [
    Document(page_content=content, metadata=metadata[i])
    for i, content in enumerate(document_contents)
]
reranked_documents = compressor.compress_documents(
    query=query,
    instruction=instruction,
    documents=documents,
)