Skip to content

bug(server-https): SentenceTransformer model reloaded on every query causing severe latency #157

Closed as not planned

Description

@Kunal-Somani

Bug Description

milvus_search() in server-https/app.py initializes a fresh SentenceTransformer instance on every single query:

def milvus_search(query: str, top_k: int = 5):
    encoder = SentenceTransformer(EMBEDDING_MODEL)  # reloaded every call
    query_vec = encoder.encode(query).tolist()

Impact

  • Every user query reloads ~400MB of model weights from disk
  • Adds 2-4 seconds of unnecessary latency per query
  • Under concurrent load, multiple threads each reload the full model simultaneously, multiplying memory pressure and risk of OOM crash
  • The model is stateless between calls — there is no reason to reload it

Proposed Fix

Move model initialization to module level so it runs exactly once at server startup and is reused across all requests:

# Module level — runs once at startup
encoder = SentenceTransformer(EMBEDDING_MODEL)

def milvus_search(query: str, top_k: int = 5):
    query_vec = encoder.encode(query).tolist()  # reuses warm model

This is the same fix already applied to server/app.py at the module level, making both servers consistent.

I will submit a PR with this fix.

Activity

  1. Kunal-Somani commented on Mar 21, 2026

    @Kunal-Somani
    Author

    /assign

  2. added a commit that references this issue on Mar 21, 2026
    7ab8737
  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

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