Skip to content

feat: Serve embedding model as a dedicated KServe InferenceService instead of per-run install #48

Closed as not planned

Description

@KUNDAN1334

Problem

The current chunk_and_embed pipeline component installs sentence-transformers
and torch from scratch on every single pipeline run:

@dsl.component(
    base_image="pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime",
    packages_to_install=["sentence-transformers", "langchain"]
)
def chunk_and_embed(
    github_data: dsl.Input[dsl.Dataset],
    repo_name: str,
    ...
):

This causes:

  • 5–10 minutes of install overhead per pipeline run before any actual work starts
  • Heavy base image (pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime is ~8GB) used just for embeddings
  • Model re-downloaded from HuggingFace on every run
  • No reuse — the API server (server/app.py, server-https/app.py) also loads embeddings separately, meaning the same model is loaded in two completely different places

This is already acknowledged in the README under "Future Improvements":

"A better improvement would be using the embedding model as a service where users
could call the service instead of installing heavy sentence transformers package every time.
This would reduce pipeline execution time, lower resource requirements, enable better
caching and optimization, improve scalability."


Proposed Solution

Deploy sentence-transformers/all-mpnet-base-v2 as a dedicated KServe InferenceService,
and update the pipeline component to call it via HTTP.

1. New file: manifests/embedding-inference-service.yaml

apiVersion: serving.kserve.io/v1beta1
kind: InferenceService
metadata:
  name: embedding-model
  namespace: ${NAMESPACE}
spec:
  predictor:
    minReplicas: 1
    model:
      modelFormat:
        name: huggingface
      args:
        - --model_name=all-mpnet-base-v2
        - --model_id=sentence-transformers/all-mpnet-base-v2
        - --task=feature-extraction
      resources:
        requests:
          cpu: "2"
          memory: "4Gi"
        limits:
          cpu: "4"
          memory: "8Gi"

2. Update pipelines/kubeflow-pipeline.py

Replace the heavy pytorch base image with a lightweight HTTP client:

# Before
@dsl.component(
    base_image="pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime",
    packages_to_install=["sentence-transformers", "langchain"]
)
def chunk_and_embed(...):
    from sentence_transformers import SentenceTransformer
    model = SentenceTransformer('all-mpnet-base-v2')
    embeddings = model.encode(chunks)

# After
@dsl.component(
    base_image="python:3.9",
    packages_to_install=["requests", "langchain-text-splitters"]
)
def chunk_and_embed(...):
    import requests
    EMBEDDING_SERVICE_URL = os.getenv(
        "EMBEDDING_SERVICE_URL",
        "http://embedding-model.${NAMESPACE}.svc.cluster.local/v1/models/all-mpnet-base-v2:predict"
    )
    response = requests.post(EMBEDDING_SERVICE_URL, json={"instances": chunks})
    embeddings = response.json()["predictions"]

3. Add EMBEDDING_SERVICE_URL to environment variables table in README.md


Benefits

Before After
Base image size ~8GB (pytorch) ~200MB (python:3.9)
Install time per run 5–10 min ~30 sec
Model reuse No Yes (shared service)
Reusable by API server No Yes
Consistent embeddings Risk of drift Guaranteed

Files Changed

File Change
manifests/embedding-inference-service.yaml New file — KServe InferenceService for embedding model
pipelines/kubeflow-pipeline.py Update chunk_and_embed to call embedding service via HTTP
README.md Add EMBEDDING_SERVICE_URL to env vars table, update architecture description

I'd like to work on this if maintainers are aligned on the approach.

Activity

  1. added 4 commits that reference this issue on Feb 28, 2026
    70f523a
    9148732
    320aaf7
    496aebe
  2. KUNDAN1334 commented on Mar 2, 2026

    @KUNDAN1334
    Author

    Hey @SanthoshToorpu — I opened this issue last week after identifying it in the codebase and proposing the KServe-based solution. I see @GunaPalanivel has raised PR #78 referencing this issue.

    I'd like to flag that I was planning to implement this as part of my GSoC proposal (Milestone 2). The embedding-as-a-service approach is central to my proposed architecture — it's not just a cleanup task but a prerequisite for consistent embeddings between ingestion time and query time, which directly affects retrieval quality.

    Happy to review PR #78 and contribute to it, or take a different angle on the implementation if there's a part of this that's still open. Just wanted to make sure my prior work on this issue is visible before it's closed.

  3. chasecadet commented on Nov 20, 2026

    @chasecadet
    Contributor

    Thank you for reporting this!

    We are closing pre-restructure issues targeting the legacy server/, server-https/, manifests/, kagent-feast-mcp/, or in-process SentenceTransformer prototype code. In #207, #210, #233, #240, and #249, kubeflow/docs-agent migrated to dedicated TEI (text-embeddings-inference), FastMCP (docs-agent-mcp/mcp-server/), shared modular KFP pipelines (docs-agent-mcp/pipelines/), and Helm charts (docs-agent-mcp/charts/).

    If you still observe an equivalent issue on the current main stack, please feel free to open a new issue using the current issue templates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions