> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenfactory.nebius.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Langchain

> Using Langchain  with Nebius Token Factory

## 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](https://python.langchain.com/docs/introduction/)\
[Langchain + Nebius Token Factory docs](https://python.langchain.com/docs/integrations/providers/nebius/)

## **Prerequisites**

1. [Create an API key](https://tokenfactory.nebius.com/project/api-keys) to authorize requests to Nebius Token Factory.
2. Save the API key into a `NEBIUS_API_KEY` environment variable:

   ```shellscript theme={null}
   export NEBIUS_API_KEY="<API_key>"
   ```
3. Install the `langchain` package:

   ```shellscript theme={null}
   pip install langchain-nebius
   ```

## Chat Models

```python theme={null}
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

```python theme={null}
from langchain_nebius import NebiusEmbeddings

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

## Retrievers

```python theme={null}
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
)
```
