跳到主要內容
Open In ColabOpen on GitHub

Contextual AI

Contextual AI 提供最先進的 RAG 組件,專為精準可靠的企業 AI 應用程式設計。我們的 LangChain 整合公開了我們專業模型的獨立 API 端點

  • Grounded Language Model (GLM):世界上最基於事實的語言模型,透過優先考慮對檢索知識的忠實度來最大限度地減少幻覺。GLM 提供卓越的事實準確性與內嵌歸因,使其成為可靠性至關重要的企業 RAG 和代理應用程式的理想選擇。

  • Instruction-Following Reranker:第一個遵循自訂指示的重新排序器,可根據特定標準(如新近度、來源或文件類型)智慧地優先排序文件。我們的重新排序器在行業基準測試中優於競爭對手,解決了企業知識庫中資訊衝突的挑戰。

Contextual AI 由 RAG 技術的發明者創立,其專業組件可協助創新團隊加速開發生產就緒的 RAG 代理程式,這些代理程式可提供極其準確的回應。

Grounded Language Model (GLM)

Grounded Language Model (GLM) 專為最大限度地減少企業 RAG 和代理應用程式中的幻覺而設計。GLM 提供

  • 在 FACTS 基準測試中表現強勁,事實準確度達 88%(查看基準測試結果
  • 回應嚴格基於提供的知識來源,並帶有內嵌歸因(閱讀產品詳細資訊
  • 精確的來源引用直接整合在產生的回應中
  • 優先考慮檢索到的上下文,而不是參數化知識(查看技術概述
  • 當資訊不可用時,明確承認不確定性

GLM 可作為 RAG 管道中通用 LLM 的直接替換,顯著提高任務關鍵型企業應用程式的可靠性。

Instruction-Following Reranker

世界上第一個 Instruction-Following Reranker 以空前的控制和準確性徹底改變了文件排名。主要功能包括

  • 自然語言指示,可根據新近度、來源、元數據等優先排序文件(了解其運作方式
  • 在 BEIR 基準測試中表現卓越,得分為 61.2,顯著優於競爭對手(查看基準測試數據
  • 智慧地解決來自多個知識來源的衝突資訊
  • 無縫整合,可直接替換現有的重新排序器
  • 透過自然語言命令動態控制文件排名

重新排序器擅長處理具有潛在矛盾資訊的企業知識庫,讓您可以精確指定在各種情況下應優先考慮哪些來源。

將 Contextual AI 與 LangChain 結合使用

請參閱此處了解詳細資訊。

此整合讓您可以輕鬆地將 Contextual AI 的 GLM 和 Instruction-Following Reranker 整合到您的 LangChain 工作流程中。GLM 確保您的應用程式提供嚴格基於事實的回應,而重新排序器透過智慧地優先排序最相關的文件,顯著提高檢索品質。

無論您是為受監管行業或注重安全性的環境建構應用程式,Contextual AI 都能提供您的企業用例所需的準確性、控制和可靠性。

立即開始免費試用,體驗最基於事實的語言模型和 Instruction-Following Reranker,適用於企業 AI 應用程式。

Grounded Language Model

# Integrating the Grounded Language Model
import getpass
import os

from langchain_contextual import ChatContextual

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

# initialize Contextual llm
llm = ChatContextual(
model="v1",
api_key="",
)
# include a system prompt (optional)
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."

# provide your own knowledge from your knowledge-base here in an array of string
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.",
]

# create your message
messages = [
("human", "What type of cats are there in the world and what are the types?"),
]

# invoke the GLM by providing the knowledge strings, optional system prompt
# if you want to turn off the GLM's commentary, pass True to the `avoid_commentary` argument
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

Instruction-Following Reranker

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,
)
API 參考:Document

此頁面是否有幫助?