Skip to main content

Langchain

LangChain is an open-source framework that helps developers build applications powered by Large Language Models (LLMs), by providing tools to connect models with data, APIs, and external systems. Langchain docs
Langchain + Nebius Token Factory docs

Prerequisites

  1. Create an API key to authorize requests to Nebius Token Factory.
  2. Save the API key into a NEBIUS_API_KEY environment variable:
    export NEBIUS_API_KEY="<API_key>"
    
  3. Install the langchain package:
    pip install langchain-nebius
    

Chat Models

from langchain_nebius import ChatNebius

# Initialize the chat model
chat = ChatNebius(
    model="Qwen/Qwen3-30B-A3B-fast",  # Choose from available models
    temperature=0.6,
    top_p=0.95
)

Embedding Models

from langchain_nebius import NebiusEmbeddings

embeddings = NebiusEmbeddings(
    model="BAAI/bge-en-icl"  # Default embedding model
)

Retrievers

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
)