LangChain
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
Section titled “Installation”pip install sie-langchainThis installs sie-sdk and langchain-core as dependencies.
pnpm add @superlinked/sie-langchainThis installs @superlinked/sie-sdk and @langchain/core as dependencies.
Start the Server
Section titled “Start the Server”# Docker (recommended)docker run -p 8080:8080 ghcr.io/superlinked/sie-server:default
# Or with GPUdocker run --gpus all -p 8080:8080 ghcr.io/superlinked/sie-server:defaultEmbeddings
Section titled “Embeddings”SIEEmbeddings implements LangChain’s Embeddings interface. Use it with any vector store.
from sie_langchain import SIEEmbeddings
embeddings = SIEEmbeddings( base_url="http://localhost:8080", model="BAAI/bge-m3")
# Embed documentsvectors = embeddings.embed_documents([ "Machine learning uses algorithms to learn from data.", "The weather is sunny today."])print(len(vectors)) # 2
# Embed a queryquery_vector = embeddings.embed_query("What is machine learning?")print(len(query_vector)) # 1024import { SIEEmbeddings } from "@superlinked/sie-langchain";
const embeddings = new SIEEmbeddings({ baseUrl: "http://localhost:8080", model: "BAAI/bge-m3",});
// Embed documentsconst vectors = await embeddings.embedDocuments([ "Machine learning uses algorithms to learn from data.", "The weather is sunny today.",]);console.log(vectors.length); // 2
// Embed a queryconst queryVector = await embeddings.embedQuery("What is machine learning?");console.log(queryVector.length); // 1024Any model SIE supports for dense embeddings works - just change the model parameter:
# 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 automaticallyembeddings = SIEEmbeddings(model="intfloat/e5-large-v2")See the Model Catalog for all 85+ supported models.
With ChromaDB
Section titled “With ChromaDB”from langchain_chroma import Chromafrom sie_langchain import SIEEmbeddings
embeddings = SIEEmbeddings(model="BAAI/bge-m3")
# Create vector storevectorstore = Chroma.from_texts( texts=["Document one", "Document two"], embedding=embeddings)
# Searchresults = vectorstore.similarity_search("query", k=2)import { Chroma } from "@langchain/community/vectorstores/chroma";import { SIEEmbeddings } from "@superlinked/sie-langchain";
const embeddings = new SIEEmbeddings({ model: "BAAI/bge-m3" });
// Create vector storeconst vectorstore = await Chroma.fromTexts( ["Document one", "Document two"], [], embeddings);
// Searchconst results = await vectorstore.similaritySearch("query", 2);Async Support
Section titled “Async Support”Both sync and async methods are available:
# Syncvectors = embeddings.embed_documents(texts)query_vec = embeddings.embed_query(text)
# Asyncvectors = await embeddings.aembed_documents(texts)query_vec = await embeddings.aembed_query(text)All methods are async by default:
// All methods return Promisesconst vectors = await embeddings.embedDocuments(texts);const queryVec = await embeddings.embedQuery(text);Reranking
Section titled “Reranking”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.
from langchain_core.documents import Documentfrom 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]}")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
Section titled “With ContextualCompressionRetriever”from langchain.retrievers import ContextualCompressionRetrieverfrom 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 5results = compression_retriever.invoke("What is machine learning?")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 5const results = await compressionRetriever.invoke("What is machine learning?");Hybrid Search
Section titled “Hybrid Search”Use SIESparseEncoder with SIEEmbeddings for hybrid dense+sparse search.
from langchain_pinecone import PineconeHybridSearchRetrieverfrom 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")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
Section titled “Full RAG Pipeline”Complete example combining embeddings, reranking, and LLM generation:
from langchain_chroma import Chromafrom langchain_core.output_parsers import StrOutputParserfrom langchain_core.prompts import ChatPromptTemplatefrom langchain_core.runnables import RunnablePassthroughfrom langchain_openai import ChatOpenAIfrom langchain.retrievers import ContextualCompressionRetrieverfrom sie_langchain import SIEEmbeddings, SIEReranker
# 1. Create embeddings and vector storeembeddings = 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 rerankingreranker = 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 chaintemplate = """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. Queryanswer = chain.invoke("What is deep learning?")print(answer)Extraction
Section titled “Extraction”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
Section titled “Entity Extraction”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)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
Section titled “Relation Extraction”Extract relationships between entities using GLiREL:
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.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
Section titled “Text Classification”Classify text into categories using GLiClass:
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.02import { 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.02Multimodal Embeddings
Section titled “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:
from sie_sdk import SIEClientfrom sie_sdk.types import Item
client = SIEClient("http://localhost:8080")
# Embed an imageresult = 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"])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 for full SDK documentation and the Model Catalog for supported vision models.
Configuration Options
Section titled “Configuration Options”SIEEmbeddings
Section titled “SIEEmbeddings”| 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 |
| 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
Section titled “SIEReranker”| 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 |
| 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
Section titled “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".
| 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 |
| 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
Section titled “What’s Next”- Rerank Results - cross-encoder reranking details
- Extract - extraction details (NER, relations, classification, vision)
- Model Catalog - all supported embedding models
- Troubleshooting - common errors and solutions