Nebius
与 Nebius AI Studio 相关的所有功能
Nebius AI Studio 为各种用例提供对广泛的先进大型语言模型和嵌入模型的 API 访问。
安装和设置
可以通过 pip 安装 Nebius 集成:
pip install langchain-nebius
要使用 Nebius AI Studio,您需要一个 API 密钥,可以从 Nebius AI Studio 获取。API 密钥可以作为初始化参数 api_key 传递,或设置为环境变量 NEBIUS_API_KEY。
import os
os.environ["NEBIUS_API_KEY"] = "YOUR-NEBIUS-API-KEY"
可用模型
支持模型的完整列表可以在 Nebius AI Studio 文档 中找到。
Chat models
ChatNebius
ChatNebius 类允许您与 Nebius AI Studio 的聊天模型进行交互。
请参阅用法示例。
from langchain_nebius import ChatNebius
# 初始化聊天模型
chat = ChatNebius(
model="Qwen/Qwen3-30B-A3B-fast", # 从可用模型中选择
temperature=0.6,
top_p=0.95
)
Embedding models
NebiusEmbeddings
NebiusEmbeddings 类允许您使用 Nebius AI Studio 的嵌入模型生成向量嵌入。
请参阅用法示例。
from langchain_nebius import NebiusEmbeddings
# 初始化嵌入
embeddings = NebiusEmbeddings(
model="BAAI/bge-en-icl" # 默认嵌入模型
)
Retrievers
NebiusRetriever
NebiusRetriever 通过 Nebius AI Studio 的嵌入实现高效的相似性搜索。它利用高质量的嵌入模型来实现文档的语义搜索。
请参阅用法示例。
from langchain_core.documents import Document
from langchain_nebius import NebiusEmbeddings, NebiusRetriever
# 创建示例文档
docs = [
Document(page_content="Paris is the capital of France"),
Document(page_content="Berlin is the capital of Germany"),
]
# 初始化嵌入
embeddings = NebiusEmbeddings()
# 创建检索器
retriever = NebiusRetriever(
embeddings=embeddings,
docs=docs,
k=2 # 要返回的文档数
)
API Reference:Document
Tools
NebiusRetrievalTool
NebiusRetrievalTool 允许您基于 NebiusRetriever 为代理创建工具。
from langchain_nebius import NebiusEmbeddings, NebiusRetriever, NebiusRetrievalTool
from langchain_core.documents import Document
# 创建示例文档
docs = [
Document(page_content="Paris is the capital of France and has the Eiffel Tower"),
Document(page_content="Berlin is the capital of Germany and has the Brandenburg Gate"),
]
# 创建嵌入和检索器
embeddings = NebiusEmbeddings()
retriever = NebiusRetriever(embeddings=embeddings, docs=docs)
# 创建检索工具
tool = NebiusRetrievalTool(
retriever=retriever,
name="nebius_search",
description="Search for information about European capitals"
)
API Reference:Document