Sub topic 13
Chaining Models with InferenceGraph
This chapter assumes you know Kubernetes pods, Services, namespaces, and YAML manifests. You should also know how to deploy an InferenceService and send JSON requests with curl. The examples use KServe’s V1 inference protocol.
Why chain models?
A production prediction often needs more than one model. A preprocessing model may clean or transform input before classification. A classifier may feed a second model that ranks or filters results.
KServe’s InferenceGraph describes this workflow as a graph of inference nodes. Each node can point to an existing KServe service. KServe routes a request from the graph’s public endpoint to those services and passes the output from one node to the next.
This keeps the workflow separate from application code:
- Each model can be deployed and scaled independently.
- The graph defines the order or routing logic.
- Clients call one endpoint instead of coordinating several model calls.
- You can change a model service without changing the client contract, if the input and output formats remain compatible.
A sequential graph
The following graph sends a request to preprocess-service and then sends that result to classifier-service.
The referenced services must already exist in the same namespace, unless your KServe configuration supports the required cross-namespace reference. The services must also agree on the payload passed between them.
apiVersion: serving.kserve.io/v1alpha1
kind: InferenceGraph
metadata:
name: image-pipeline
spec:
nodes:
root:
routerType: Sequence
steps:
- nodeName: preprocess
- nodeName: classify
preprocess:
serviceName: preprocess-service
classify:
serviceName: classifier-serviceApply the manifest and inspect the graph:
kubectl apply -f image-pipeline.yaml
kubectl get inferencegraph image-pipelineA request uses the graph name in the model path:
cat <<'EOF' > request.json
{"instances": [{"image": "gs://example-bucket/images/cat.jpg"}]}
EOF
curl -H "Host: ${SERVICE_HOSTNAME}" \
-H "Content-Type: application/json" \
"http://${INGRESS_HOST}:${INGRESS_PORT}/v1/models/image-pipeline:predict" \
-d @request.jsonThe exact response depends on the final node. If the preprocessing service returns a payload that the classifier does not understand, the graph can be healthy while requests still fail.
Graph routing patterns
A Sequence runs nodes in order. Other router types support branching and combining results. Use them only when the payload contracts and failure behavior are clear.
| Pattern | Use |
|---|---|
| Sequence | Pass one result through several steps |
| Splitter | Send traffic to multiple nodes and combine responses |
| Switch | Select a node based on request or intermediate data |
Treat every edge as an API boundary. Document the JSON shape produced by each node, including errors, missing fields, and batching behavior.
Failure handling and operations
A graph request can fail because a node is unavailable, times out, rejects the payload, or returns an unexpected response. Check the graph and the referenced services separately:
kubectl describe inferencegraph image-pipeline
kubectl get inferenceservice preprocess-service classifier-service
kubectl logs deploy/preprocess-service
kubectl logs deploy/classifier-serviceKeep graph chains short when latency matters. Every synchronous node adds network and processing time. Scale the busiest node independently, and set timeouts and resource limits appropriate to the whole request path.
Exercise
In a sequential graph, the classifier reports an invalid input schema, but both services are Ready. What should you inspect first?
Show answer
Inspect the preprocessing service’s actual response and compare its JSON shape with the classifier’s expected request schema. Readiness only confirms that a service can accept requests; it does not validate the contract between graph nodes.