DSPy
The sie-dspy package provides an embedder compatible with DSPy’s retrieval components. Use SIEEmbedder with dspy.retrievers.Embeddings for semantic search.
Installation
Section titled “Installation”pip install sie-dspyThis installs sie-sdk and numpy as dependencies.
Start the Server
Section titled “Start the Server”# Docker (recommended)docker run -p 8080:8080 ghcr.io/superlinked/sie:latest
# Or with GPUdocker run --gpus all -p 8080:8080 ghcr.io/superlinked/sie:latestEmbedder
Section titled “Embedder”SIEEmbedder is callable and works directly with DSPy’s retrieval components.
from sie_dspy import SIEEmbedder
embedder = SIEEmbedder( base_url="http://localhost:8080", model="BAAI/bge-m3",)
# Embed a single textvector = embedder("What is machine learning?")print(vector.shape) # (1024,)
# Embed multiple textsvectors = embedder(["First document", "Second document"])print(vectors.shape) # (2, 1024)Configuration Options
Section titled “Configuration Options”| Parameter | Type | Default | Description |
|---|---|---|---|
base_url | str | http://localhost:8080 | SIE server URL |
model | str | BAAI/bge-m3 | Model to use |
gpu | str | None | Target GPU type for routing |
options | dict | None | Model-specific options |
timeout_s | float | 180.0 | Request timeout in seconds |
Full Example
Section titled “Full Example”Build a complete DSPy RAG program using SIE embeddings:
import dspyfrom sie_dspy import SIEEmbedder
# 1. Configure DSPy with your LLMlm = dspy.LM("openai/gpt-4o-mini")dspy.configure(lm=lm)
# 2. Create SIE embedderembedder = SIEEmbedder( base_url="http://localhost:8080", model="BAAI/bge-m3",)
# 3. Build retriever with your corpuscorpus = [ "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.",]
retriever = dspy.retrievers.Embeddings( corpus=corpus, embedder=embedder, k=2,)
# 4. Define a RAG signatureclass RAG(dspy.Signature): """Answer questions using retrieved context.""" context: list[str] = dspy.InputField(desc="retrieved passages") question: str = dspy.InputField() answer: str = dspy.OutputField()
# 5. Build the RAG programclass RAGProgram(dspy.Module): def __init__(self): self.retriever = retriever self.generate = dspy.ChainOfThought(RAG)
def forward(self, question: str): passages = self.retriever(question) return self.generate(context=passages, question=question)
# 6. Run the programrag = RAGProgram()result = rag("What is deep learning?")print(result.answer)What’s Next
Section titled “What’s Next”- Encode Text - embedding API details
- Model Catalog - all supported embedding models