以编程方式使用文档

与 Nebius Token Factory 相关的所有功能

>Nebius Token Factory 提供 API 访问多种前沿大型语言模型和嵌入模型,适用于各种用例。

安装和设置

Nebius 集成可以通过 pip 安装:

pip install langchain-nebius
uv add langchain-nebius

要使用 Nebius Token Factory,您需要获取一个 API 密钥,您可以从中获取 Nebius Token Factory。API 密钥可以作为初始化参数传递 api_key 或设置为环境变量 NEBIUS_API_KEY.

os.environ["NEBIUS_API_KEY"] = "YOUR-NEBIUS-API-KEY"

可用模型

支持的模型完整列表可在 Nebius Token Factory 模型页面.

聊天模型

ChatNebius

ChatNebius 类允许您与 Nebius Token Factory 的聊天模型进行交互。

请参阅 使用示例.

from langchain_nebius import ChatNebius

# Initialize the chat model
chat = ChatNebius(
    model="moonshotai/Kimi-K2.5",  # Choose from available models
    temperature=0.6,
    top_p=0.95
)

嵌入模型

NebiusEmbeddings

NebiusEmbeddings 类允许您使用 Nebius Token Factory 的嵌入模型生成向量嵌入。

请参阅 使用示例.

from langchain_nebius import NebiusEmbeddings

# Initialize embeddings
embeddings = NebiusEmbeddings(
    model="Qwen/Qwen3-Embedding-8B"  # Default embedding model
)

检索器

NebiusRetriever

NebiusRetriever 支持使用 Nebius Token Factory 的嵌入进行高效的相似性搜索。它利用高质量的嵌入模型实现文档的语义搜索。

请参阅 使用示例.

from langchain_core.documents import Document
from langchain_nebius import NebiusEmbeddings, NebiusRetriever

# Create sample documents
docs = [
    Document(page_content="Paris is the capital of France"),
    Document(page_content="Berlin is the capital of Germany"),
]

# Initialize embeddings
embeddings = NebiusEmbeddings()

# Create retriever
retriever = NebiusRetriever(
    embeddings=embeddings,
    docs=docs,
    k=2  # Number of documents to return
)

工具

NebiusRetrievalTool

NebiusRetrievalTool 允许您基于 NebiusRetriever 为代理创建一个工具。

from langchain_nebius import NebiusEmbeddings, NebiusRetriever, NebiusRetrievalTool
from langchain_core.documents import Document

# Create sample documents
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"),
]

# Create embeddings and retriever
embeddings = NebiusEmbeddings()
retriever = NebiusRetriever(embeddings=embeddings, docs=docs)

# Create retrieval tool
tool = NebiusRetrievalTool(
    retriever=retriever,
    name="nebius_search",
    description="Search for information about European capitals"
)