← All articles

RAG · July 8, 2026 · 3 min read

Self-hosting an embedding model for private search

Learn how to self-host high-performance embedding models like BGE using FastAPI and Podstack for secure, private, and low-latency vector search.

In the era of Retrieval-Augmented Generation (RAG), embeddings are the bedrock of modern search. While managed API services offer convenience, many engineering teams are shifting toward self-hosting their embedding models to reduce latency, eliminate per-token costs, and—most importantly—ensure data privacy.

When you send a sensitive document to a third-party embedding API, that data leaves your infrastructure. By self-hosting on a private GPU cloud, your data stays within your controlled environment. In this post, we will walk through deploying a state-of-the-art embedding model as a scalable inference endpoint.

Choosing the Right Model

For most production use cases, the BGE (BAAI General Embedding) or nomic-embed-text families offer the best balance between dimensionality and performance. For this guide, we will use BAAI/bge-small-en-v1.5. It is lightweight, performs exceptionally well on the MTEB leaderboard, and runs with incredibly low latency on even modest GPU hardware.

The Architecture: FastEmbed and FastAPI

To keep our service "production-grade" yet lean, we will use FastEmbed. Developed by the Qdrant team, FastEmbed is optimized for speed and allows us to run inference without the heavy overhead of the full Transformers library if we choose. We will wrap this in a FastAPI application to handle concurrent requests.

Implementation: The Inference Script

Below is a Python implementation of our embedding server. This script initializes the model on the GPU and exposes a POST endpoint to convert text strings into vector representations.

import os
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from typing import List
import numpy as np
from fastembed import TextEmbedding

app = FastAPI(title="Private Embedding Service")

# Initialize the model (it will be cached on the first run)
# We specify the GPU device for acceleration
model = TextEmbedding(model_name="BAAI/bge-small-en-v1.5")

class EmbeddingRequest(BaseModel):
    input: List[str]

class EmbeddingResponse(BaseModel):
    embeddings: List[List[float]]

@app.post("/v1/embeddings", response_model=EmbeddingResponse)
async def get_embeddings(request: EmbeddingRequest):
    try:
        # Generate embeddings
        # FastEmbed returns an iterator of numpy arrays
        embeddings_iter = model.embed(request.input)
        embeddings_list = [emb.tolist() for emb in embeddings_iter]
        
        return EmbeddingResponse(embeddings=embeddings_list)
    except Exception as e:
        raise HTTPException(status_code=500, detail=str(e))

if __name__ == "__main__":
    import uvicorn
    uvicorn.run(app, host="0.0.0.0", port=8080)

Practical Tips for Production

  1. Batching: If you are processing thousands of documents for an initial index, always batch your requests. Large batches (e.g., 32 or 64 strings) utilize the GPU's parallel processing power much better than sequential single-string requests.
  2. Precision: Use FP16 (Half-precision) where possible. Most modern GPUs will see a significant speedup with negligible loss in retrieval accuracy.
  3. Cold Starts: In a serverless environment, ensure your model weights are pre-baked into your container image or stored on a persistent volume to avoid downloading several hundred megabytes on every boot.

Deploying on Podstack

Deploying this setup traditionally involves managing complex Kubernetes manifests or worrying about idle GPU costs. Podstack simplifies this by treating GPU functions as first-class citizens with per-second billing.

To deploy our embedding service, we use the Podstack API. This allows us to push our code and have it instantly accessible via a secure endpoint.

First, ensure your environment is set up:

export PODSTACK_API_KEY="your_api_key_here"

Then, you can deploy your Python function directly. Podstack handles the GPU allocation and scaling automatically. Because Podstack supports serverless inference, you aren't paying for the GPU while your search engine is idle—only during the milliseconds it takes to generate the embedding.

Podstack does not ship a command-line interface. Use the console, the Python package `podstack-sdk`, or the API at https://podstack.ai/api/v1 with a `ps_live_` key.

Once deployed, you can integrate this endpoint into your LangChain or LlamaIndex pipeline by simply swapping the base URL. Your vectors never leave your private cloud, and you benefit from the raw performance of an A100 or L40S without the overhead of managing the underlying hardware.

Closing Thoughts

Self-hosting embedding models is no longer an infrastructure nightmare. With optimized libraries like FastEmbed and on-demand GPU platforms like Podstack, you can achieve sub-10ms embedding latency while keeping your data strictly private. This setup provides the foundation for a secure, scalable, and cost-effective neural search engine.

Try it on Podstack

Per-second GPUs and pay-per-token models. Add $5, get $10 on your first top-up.

Start building