Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Tensorflow Serving servable data h

From Leeroopedia
Knowledge Sources
Domains Model Serving, Core Framework
Last Updated 2026-02-13 00:00 GMT

Overview

ServableData is a template container that pairs a ServableId with either associated data of type T or an error status.

Description

The ServableData<T> class template acts as a typed envelope for servable data flowing through the TensorFlow Serving pipeline. It associates a ServableId (name + version) with either a successfully produced data payload of type T, or a Status indicating an error. This is the fundamental unit of data that Sources emit and that propagates through SourceAdapters toward Managers.

The class enforces two static assertions: T must be move-constructible, and T cannot be Status itself (to avoid ambiguity between the data and error paths). Data can be accessed via DataOrDie() which CHECK-fails if the status is not OK, or consumed via ConsumeDataOrDie() which moves the data out.

A convenience factory function CreateServableData() is provided that leverages argument-dependent lookup (ADL) so callers need not specify the template argument explicitly.

Usage

Use ServableData whenever you need to pair a servable identifier with its corresponding data payload or an error. This is the standard container used in Source and SourceAdapter interfaces to transport aspired-version data through the serving pipeline. Sources create ServableData instances to represent each version of a servable they wish to load.

Code Reference

Source Location

Signature

template <typename T>
class ServableData {
 public:
  ServableData(const ServableId& id, T data);
  ServableData(const ServableId& id, const Status& error);
  ServableData(const ServableData& other) = default;
  ServableData& operator=(const ServableData& other) = default;
  ServableData(ServableData&& other) = default;

  const ServableId& id() const;
  const Status& status() const;
  const T& DataOrDie() const;
  T& DataOrDie();
  T ConsumeDataOrDie();
};

template <typename T>
ServableData<T> CreateServableData(const ServableId& id, T data);

Import

#include "tensorflow_serving/core/servable_data.h"

I/O Contract

Inputs

Name Type Required Description
id const ServableId& Yes The unique identifier (name + version) for the servable
data T Yes (success path) The payload data associated with the servable version
error const Status& Yes (error path) An error status; must not be OK (CHECK-fails otherwise)

Outputs

Name Type Description
id() const ServableId& Returns the servable identifier
status() const Status& Returns OK on success, or the error status
DataOrDie() const T& / T& Returns a reference to the data; CHECK-fails if status is not OK
ConsumeDataOrDie() T Moves the data out of the container; CHECK-fails if status is not OK

Usage Examples

Creating ServableData with Valid Data

#include "tensorflow_serving/core/servable_data.h"
#include "tensorflow_serving/core/servable_id.h"

using namespace tensorflow::serving;

// Create a ServableData with a string payload
ServableId id = {"my_model", 1};
ServableData<string> data(id, "model_path_v1");

// Access the data
const string& path = data.DataOrDie();  // Returns "model_path_v1"

Creating ServableData with Error

#include "tensorflow_serving/core/servable_data.h"

using namespace tensorflow::serving;

ServableId id = {"my_model", 2};
Status error = errors::NotFound("Model version not found");
ServableData<string> data(id, error);

// data.status() is the NotFound error
// data.DataOrDie() would CHECK-fail

Using the Factory Function

#include "tensorflow_serving/core/servable_data.h"

using namespace tensorflow::serving;

// Template argument deduced via ADL
ServableId id = {"my_model", 3};
auto data = CreateServableData(id, string("some_path"));

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment