---
title: LangChain
description: Use SIE embeddings and reranking in LangChain RAG pipelines.
canonical_url: https://superlinked.com/docs/integrations/langchain
last_updated: 2026-05-20
---

The `sie-langchain` package (Python) and `@superlinked/sie-langchain` package (TypeScript) provide drop-in components for LangChain. Both languages support embeddings, sparse search, reranking, and extraction (entities, relations, classifications, and object detection).

## Installation

#### Python

```bash
pip install sie-langchain
```
This installs `sie-sdk` and `langchain-core` as dependencies.

#### TypeScript

```bash
pnpm add @superlinked/sie-langchain
```
This installs `@superlinked/sie-sdk` and `@langchain/core` as dependencies.

## Start the Server

Source: [packages/sie_server/src/sie_server/cli.py](https://github.com/superlinked/sie/blob/main/packages/sie_server/src/sie_server/cli.py)

```bash
# Docker (recommended)
docker run -p 8080:8080 ghcr.io/superlinked/sie-server:latest-cpu-default

# Or with GPU
docker run --gpus all -p 8080:8080 ghcr.io/superlinked/sie-server:latest-cuda12-default
```

## Embeddings

Source: [integrations/sie_langchain/src/sie_langchain/embeddings.py](https://github.com/superlinked/sie/blob/main/integrations/sie_langchain/src/sie_langchain/embeddings.py)

`SIEEmbeddings` implements LangChain's `Embeddings` interface. Use it with any vector store.

#### Python

```python
from sie_langchain import SIEEmbeddings

embeddings = SIEEmbeddings(
    base_url="http://localhost:8080",
    model="BAAI/bge-m3"
)

# Embed documents
vectors = embeddings.embed_documents([
    "Machine learning uses algorithms to learn from data.",
    "The weather is sunny today."
])
print(len(vectors))  # 2

# Embed a query
query_vector = embeddings.embed_query("What is machine learning?")
print(len(query_vector))  # 1024
```

#### TypeScript

```typescript
import { SIEEmbeddings } from "@superlinked/sie-langchain";

const embeddings = new SIEEmbeddings({
  baseUrl: "http://localhost:8080",
  model: "BAAI/bge-m3",
});

// Embed documents
const vectors = await embeddings.embedDocuments([
  "Machine learning uses algorithms to learn from data.",
  "The weather is sunny today.",
]);
console.log(vectors.length); // 2

// Embed a query
const queryVector = await embeddings.embedQuery("What is machine learning?");
console.log(queryVector.length); // 1024
```

Any model SIE supports for dense embeddings works - just change the `model` parameter:

```python
# Stella (1024-dim, strong quality)
embeddings = SIEEmbeddings(model="NovaSearch/stella_en_400M_v5")

# Nomic MoE (768-dim)
embeddings = SIEEmbeddings(model="nomic-ai/nomic-embed-text-v2-moe")

# E5 (1024-dim) - SIE handles query vs document encoding automatically
embeddings = SIEEmbeddings(model="intfloat/e5-large-v2")
```

See the [Model Catalog](/models) for all 85+ supported models.

### With ChromaDB

#### Python

```python
from langchain_chroma import Chroma
from sie_langchain import SIEEmbeddings

embeddings = SIEEmbeddings(model="BAAI/bge-m3")

# Create vector store
vectorstore = Chroma.from_texts(
    texts=["Document one", "Document two"],
    embedding=embeddings
)

# Search
results = vectorstore.similarity_search("query", k=2)
```

#### TypeScript

```typescript
import { Chroma } from "@langchain/community/vectorstores/chroma";
import { SIEEmbeddings } from "@superlinked/sie-langchain";

const embeddings = new SIEEmbeddings({ model: "BAAI/bge-m3" });

// Create vector store
const vectorstore = await Chroma.fromTexts(
  ["Document one", "Document two"],
  [],
  embeddings
);

// Search
const results = await vectorstore.similaritySearch("query", 2);
```

### Async Support

#### Python

Both sync and async methods are available:

```python
# Sync
vectors = embeddings.embed_documents(texts)
query_vec = embeddings.embed_query(text)

# Async
vectors = await embeddings.aembed_documents(texts)
query_vec = await embeddings.aembed_query(text)
```

#### TypeScript

All methods are async by default:

```typescript
// All methods return Promises
const vectors = await embeddings.embedDocuments(texts);
const queryVec = await embeddings.embedQuery(text);
```

## Reranking

Source: [integrations/sie_langchain/src/sie_langchain/rerankers.py](https://github.com/superlinked/sie/blob/main/integrations/sie_langchain/src/sie_langchain/rerankers.py)

`SIEReranker` implements `BaseDocumentCompressor`. Use it to rerank retrieved documents. Works with both cross-encoder models (e.g., `jinaai/jina-reranker-v2-base-multilingual`) and ColBERT/late-interaction models (e.g., `jinaai/jina-colbert-v2`) - just change the model name.

#### Python

```python
from langchain_core.documents import Document
from sie_langchain import SIEReranker

reranker = SIEReranker(
    base_url="http://localhost:8080",
    model="jinaai/jina-reranker-v2-base-multilingual",
    top_k=3
)

documents = [
    Document(page_content="Machine learning is a subset of AI."),
    Document(page_content="The weather is sunny today."),
    Document(page_content="Deep learning uses neural networks."),
]

reranked = reranker.compress_documents(documents, "What is ML?")

for doc in reranked:
    score = doc.metadata.get("relevance_score", 0)
    print(f"{score:.3f}: {doc.page_content[:50]}")
```

#### TypeScript

```typescript
import { Document } from "@langchain/core/documents";
import { SIEReranker } from "@superlinked/sie-langchain";

const reranker = new SIEReranker({
  baseUrl: "http://localhost:8080",
  model: "jinaai/jina-reranker-v2-base-multilingual",
  topK: 3,
});

const documents = [
  new Document({ pageContent: "Machine learning is a subset of AI." }),
  new Document({ pageContent: "The weather is sunny today." }),
  new Document({ pageContent: "Deep learning uses neural networks." }),
];

const reranked = await reranker.compressDocuments(documents, "What is ML?");

for (const doc of reranked) {
  const score = doc.metadata.relevance_score ?? 0;
  console.log(`${score.toFixed(3)}: ${doc.pageContent.slice(0, 50)}`);
}
```

### With ContextualCompressionRetriever

#### Python

```python
from langchain.retrievers import ContextualCompressionRetriever
from sie_langchain import SIEReranker

reranker = SIEReranker(model="jinaai/jina-reranker-v2-base-multilingual", top_k=5)

compression_retriever = ContextualCompressionRetriever(
    base_compressor=reranker,
    base_retriever=vectorstore.as_retriever(search_kwargs={"k": 20})
)

# Retrieves 20 docs, reranks, returns top 5
results = compression_retriever.invoke("What is machine learning?")
```

#### TypeScript

```typescript
import { ContextualCompressionRetriever } from "langchain/retrievers/contextual_compression";
import { SIEReranker } from "@superlinked/sie-langchain";

const reranker = new SIEReranker({
  model: "jinaai/jina-reranker-v2-base-multilingual",
  topK: 5,
});

const compressionRetriever = new ContextualCompressionRetriever({
  baseCompressor: reranker,
  baseRetriever: vectorstore.asRetriever({ k: 20 }),
});

// Retrieves 20 docs, reranks, returns top 5
const results = await compressionRetriever.invoke("What is machine learning?");
```

## Hybrid Search

Source: [integrations/sie_langchain/src/sie_langchain/embeddings.py](https://github.com/superlinked/sie/blob/main/integrations/sie_langchain/src/sie_langchain/embeddings.py)

Use `SIESparseEncoder` with `SIEEmbeddings` for hybrid dense+sparse search.

#### Python

```python
from langchain_pinecone import PineconeHybridSearchRetriever
from sie_langchain import SIEEmbeddings, SIESparseEncoder

retriever = PineconeHybridSearchRetriever(
    embeddings=SIEEmbeddings(model="BAAI/bge-m3"),
    sparse_encoder=SIESparseEncoder(model="BAAI/bge-m3"),
    index=pinecone_index
)

results = retriever.invoke("hybrid search query")
```

#### TypeScript

```typescript
import { PineconeHybridSearchRetriever } from "@langchain/pinecone";
import { SIEEmbeddings, SIESparseEncoder } from "@superlinked/sie-langchain";

const retriever = new PineconeHybridSearchRetriever({
  embeddings: new SIEEmbeddings({ model: "BAAI/bge-m3" }),
  sparseEncoder: new SIESparseEncoder({ model: "BAAI/bge-m3" }),
  index: pineconeIndex,
});

const results = await retriever.invoke("hybrid search query");
```

## Full RAG Pipeline

Source: [integrations/sie_langchain/src/sie_langchain/](https://github.com/superlinked/sie/blob/main/integrations/sie_langchain/src/sie_langchain/)

Complete example combining embeddings, reranking, and LLM generation:

#### Python

```python
from langchain_chroma import Chroma
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.runnables import RunnablePassthrough
from langchain_openai import ChatOpenAI
from langchain.retrievers import ContextualCompressionRetriever
from sie_langchain import SIEEmbeddings, SIEReranker

# 1. Create embeddings and vector store
embeddings = SIEEmbeddings(
    base_url="http://localhost:8080",
    model="BAAI/bge-m3"
)

documents = [
    "Machine learning is a branch of artificial intelligence.",
    "Neural networks are inspired by biological neurons.",
    "Deep learning uses multiple layers of neural networks.",
    "Python is popular for machine learning development.",
]

vectorstore = Chroma.from_texts(texts=documents, embedding=embeddings)

# 2. Create two-stage retriever with reranking
reranker = SIEReranker(
    base_url="http://localhost:8080",
    model="jinaai/jina-reranker-v2-base-multilingual",
    top_k=2
)

retriever = ContextualCompressionRetriever(
    base_compressor=reranker,
    base_retriever=vectorstore.as_retriever(search_kwargs={"k": 10})
)

# 3. Build RAG chain
template = """Answer based on the context:

Context: {context}

Question: {question}"""

prompt = ChatPromptTemplate.from_template(template)
llm = ChatOpenAI(model="gpt-4o-mini")

def format_docs(docs):
    return "\n".join(doc.page_content for doc in docs)

chain = (
    {"context": retriever | format_docs, "question": RunnablePassthrough()}
    | prompt
    | llm
    | StrOutputParser()
)

# 4. Query
answer = chain.invoke("What is deep learning?")
print(answer)
```

## Extraction

Source: [integrations/sie_langchain/src/sie_langchain/extractors.py](https://github.com/superlinked/sie/blob/main/integrations/sie_langchain/src/sie_langchain/extractors.py)

`SIEExtractor` provides zero-shot extraction as a LangChain `Tool`. It supports all extraction types: entities (GLiNER), relations (GLiREL), classifications (GLiClass), and object detection (GroundingDINO/OWL-v2). The tool name is `"sie_extract"` and it returns a dict with keys `entities`, `relations`, `classifications`, and `objects`.

### Entity Extraction

#### Python

```python
from sie_langchain import SIEExtractor

extractor = SIEExtractor(
    base_url="http://localhost:8080",
    model="urchade/gliner_multi-v2.1",
    labels=["person", "organization", "location"]
)

result = extractor.invoke("Tim Cook announced new products at Apple Park in Cupertino.")
for entity in result["entities"]:
    print(f"{entity['label']}: {entity['text']} ({entity['score']:.2f})")
# person: Tim Cook (0.96)
# organization: Apple (0.91)
# location: Cupertino (0.88)
```

#### TypeScript

```typescript
import { SIEExtractor } from "@superlinked/sie-langchain";

const extractor = new SIEExtractor({
  baseUrl: "http://localhost:8080",
  model: "urchade/gliner_multi-v2.1",
  labels: ["person", "organization", "location"],
});

const result = await extractor.invoke(
  "Tim Cook announced new products at Apple Park in Cupertino."
);
for (const entity of result.entities) {
  console.log(`${entity.label}: ${entity.text} (${entity.score.toFixed(2)})`);
}
// person: Tim Cook (0.96)
// organization: Apple (0.91)
// location: Cupertino (0.88)
```

### Relation Extraction

Extract relationships between entities using GLiREL:

#### Python

```python
from sie_langchain import SIEExtractor

extractor = SIEExtractor(
    base_url="http://localhost:8080",
    model="jackboyla/glirel-large-v0",
    labels=["works_for", "ceo_of", "founded"]
)

result = extractor.invoke("Tim Cook is the CEO of Apple Inc.")
for relation in result["relations"]:
    print(f"{relation['head']} --{relation['relation']}--> {relation['tail']}")
# Tim Cook --ceo_of--> Apple Inc.
```

#### TypeScript

```typescript
import { SIEExtractor } from "@superlinked/sie-langchain";

const extractor = new SIEExtractor({
  baseUrl: "http://localhost:8080",
  model: "jackboyla/glirel-large-v0",
  labels: ["works_for", "ceo_of", "founded"],
});

const result = await extractor.invoke("Tim Cook is the CEO of Apple Inc.");
for (const relation of result.relations) {
  console.log(`${relation.head} --${relation.relation}--> ${relation.tail}`);
}
// Tim Cook --ceo_of--> Apple Inc.
```

### Text Classification

Classify text into categories using GLiClass:

#### Python

```python
from sie_langchain import SIEExtractor

extractor = SIEExtractor(
    base_url="http://localhost:8080",
    model="knowledgator/gliclass-base-v1.0",
    labels=["positive", "negative", "neutral"]
)

result = extractor.invoke("I absolutely loved this movie! The acting was superb.")
for classification in result["classifications"]:
    print(f"{classification['label']}: {classification['score']:.2f}")
# positive: 0.94
# neutral: 0.04
# negative: 0.02
```

#### TypeScript

```typescript
import { SIEExtractor } from "@superlinked/sie-langchain";

const extractor = new SIEExtractor({
  baseUrl: "http://localhost:8080",
  model: "knowledgator/gliclass-base-v1.0",
  labels: ["positive", "negative", "neutral"],
});

const result = await extractor.invoke(
  "I absolutely loved this movie! The acting was superb."
);
for (const classification of result.classifications) {
  console.log(`${classification.label}: ${classification.score.toFixed(2)}`);
}
// positive: 0.94
// neutral: 0.04
// negative: 0.02
```

## Multimodal Embeddings

LangChain's `Embeddings` interface is text-only (`embed_documents(texts)` / `embed_query(text)`), so there is no native way to pass images through the integration. For image embedding with models like CLIP, SigLIP, or ColPali, use the SIE SDK directly:

#### Python

```python
from sie_sdk import SIEClient
from sie_sdk.types import Item

client = SIEClient("http://localhost:8080")

# Embed an image
result = client.encode(
    "openai/clip-vit-large-patch14",
    Item(images=["photo.jpg"]),
    output_types=["dense"]
)
image_embedding = result["dense"].tolist()

# Embed text+image together (for models that support it)
result = client.encode(
    "openai/clip-vit-large-patch14",
    Item(text="A photo of a cat", images=["cat.jpg"]),
    output_types=["dense"]
)
```

#### TypeScript

```typescript
import { SIEClient } from "@superlinked/sie-sdk";

const client = new SIEClient("http://localhost:8080");

// Embed an image (pass as Uint8Array)
const result = await client.encode(
  "openai/clip-vit-large-patch14",
  { images: [imageBytes] },
  { outputTypes: ["dense"] }
);
```

See [Encode](/docs/encode/) for full SDK documentation and the [Model Catalog](/models#task=encode) for supported vision models.

:::tip[LlamaIndex and Haystack]
If you need image embedding as part of a framework pipeline, [LlamaIndex](/docs/integrations/llamaindex/) and [Haystack](/docs/integrations/haystack/) have native multimodal support via `SIEMultiModalEmbedding` and `SIEImageEmbedder`.
:::

## Configuration Options

### SIEEmbeddings

#### Python

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `base_url` | `str` | `http://localhost:8080` | SIE server URL |
| `model` | `str` | `BAAI/bge-m3` | Model to use |
| `instruction` | `str` | `None` | Instruction prefix for encoding |
| `output_dtype` | `str` | `None` | Output dtype: float32, float16, int8, binary |
| `gpu` | `str` | `None` | Target GPU type for routing |
| `timeout_s` | `float` | `180.0` | Request timeout in seconds |

#### TypeScript

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `baseUrl` | `string` | `http://localhost:8080` | SIE server URL |
| `model` | `string` | `BAAI/bge-m3` | Model to use |
| `instruction` | `string` | `undefined` | Instruction prefix for encoding |
| `outputDtype` | `DType` | `undefined` | Output dtype: float32, float16, int8, binary |
| `gpu` | `string` | `undefined` | Target GPU type for routing |
| `timeout` | `number` | `180000` | Request timeout in milliseconds |

### SIEReranker

#### Python

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `base_url` | `str` | `http://localhost:8080` | SIE server URL |
| `model` | `str` | `jinaai/jina-reranker-v2-base-multilingual` | Reranker model |
| `top_k` | `int` | `None` | Number of documents to return |
| `gpu` | `str` | `None` | Target GPU type for routing |
| `options` | `dict` | `None` | Model-specific options |
| `timeout_s` | `float` | `180.0` | Request timeout in seconds |

#### TypeScript

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `baseUrl` | `string` | `http://localhost:8080` | SIE server URL |
| `model` | `string` | `jinaai/jina-reranker-v2-base-multilingual` | Reranker model |
| `topK` | `number` | `undefined` | Number of documents to return |
| `gpu` | `string` | `undefined` | Target GPU type for routing |
| `timeout` | `number` | `180000` | Request timeout in milliseconds |

### SIEExtractor

The extraction model determines which result types are populated. Use GLiNER models for entities, GLiREL for relations, GLiClass for classifications, and GroundingDINO/OWL-v2 for object detection. The tool name is `"sie_extract"`.

#### Python

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `base_url` | `str` | `http://localhost:8080` | SIE server URL |
| `model` | `str` | `urchade/gliner_multi-v2.1` | Extraction model (GLiNER, GLiREL, GLiClass, GroundingDINO, OWL-v2) |
| `labels` | `list[str]` | `["person", "organization", "location"]` | Labels for extraction (entity types, relation types, or classification categories) |
| `gpu` | `str` | `None` | Target GPU type for routing |
| `options` | `dict` | `None` | Model-specific options |
| `timeout_s` | `float` | `180.0` | Request timeout in seconds |

#### TypeScript

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `baseUrl` | `string` | `http://localhost:8080` | SIE server URL |
| `model` | `string` | `urchade/gliner_multi-v2.1` | Extraction model (GLiNER, GLiREL, GLiClass, GroundingDINO, OWL-v2) |
| `labels` | `string[]` | `["person", "organization", "location"]` | Labels for extraction (entity types, relation types, or classification categories) |
| `threshold` | `number` | `undefined` | Minimum confidence threshold (0-1) |
| `gpu` | `string` | `undefined` | Target GPU type for routing |
| `timeout` | `number` | `180000` | Request timeout in milliseconds |

## What's Next

- [Rerank Results](/docs/score/) - cross-encoder reranking details
- [Extract](/docs/extract/) - extraction details (NER, relations, classification, vision)
- [Model Catalog](/models#task=encode) - all supported embedding models
- [Troubleshooting](/docs/reference/troubleshooting/) - common errors and solutions
