To use Nebius Token Factory, you’ll need an API key which you can obtain from Nebius Token Factory. The API key can be passed as an initialization parameter api_key or set as the environment variable NEBIUS_API_KEY.
The ChatNebius class allows you to interact with Nebius Token Factory’s chat models.查看使用示例.
from langchain_nebius import ChatNebius# Initialize the chat modelchat = ChatNebius( model="moonshotai/Kimi-K2.5", # Choose from available models temperature=0.6, top_p=0.95)
The NebiusRetriever enables efficient similarity search using embeddings from Nebius Token Factory. It leverages high-quality embedding models to enable semantic search over documents.查看使用示例.
from langchain_core.documents import Documentfrom langchain_nebius import NebiusEmbeddings, NebiusRetriever# Create sample documentsdocs = [ Document(page_content="Paris is the capital of France"), Document(page_content="Berlin is the capital of Germany"),]# Initialize embeddingsembeddings = NebiusEmbeddings()# Create retrieverretriever = NebiusRetriever( embeddings=embeddings, docs=docs, k=2 # Number of documents to return)
The NebiusRetrievalTool allows you to create a tool for agents based on the NebiusRetriever.
from langchain_nebius import NebiusEmbeddings, NebiusRetriever, NebiusRetrievalToolfrom langchain_core.documents import Document# Create sample documentsdocs = [ 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 retrieverembeddings = NebiusEmbeddings()retriever = NebiusRetriever(embeddings=embeddings, docs=docs)# Create retrieval tooltool = NebiusRetrievalTool( retriever=retriever, name="nebius_search", description="Search for information about European capitals")