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 Hashmap Source Adapter

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

Overview

A SourceAdapter that loads string-string hashmaps from filesystem paths, converting storage paths into servable loaders for hashmap data.

Description

HashmapSourceAdapter extends SimpleLoaderSourceAdapter<StoragePath, std::unordered_map<string, string>> to provide a complete servable loading pipeline for hashmap data. It demonstrates the TensorFlow Serving source adapter pattern for non-TensorFlow servable types.

The adapter is configured with a HashmapSourceAdapterConfig protobuf that specifies the file format. Currently, only the SIMPLE_CSV format is supported, which reads comma-separated key-value pairs from a file (one pair per line, exactly two columns).

The internal LoadHashmapFromFile function: 1. Opens the file at the given path using a RandomAccessFile with a 256KB input buffer 2. Reads lines and splits each by comma 3. Validates that each line has exactly two columns 4. Inserts key-value pairs into an unordered_map

The adapter explicitly declines to provide resource footprint estimates (using EstimateNoResources()), as hashmap sizes are generally small and unpredictable without reading the file.

The destructor calls Detach() to properly disconnect from any connected sources before destruction.

Usage

Use this adapter as a reference implementation of the SimpleLoaderSourceAdapter pattern and for serving simple key-value lookup data alongside TensorFlow models. Configure it with a HashmapSourceAdapterConfig specifying the SIMPLE_CSV format, and connect it to a storage path source.

Code Reference

Source Location

  • Repository: Tensorflow_Serving
  • Files:
    • tensorflow_serving/servables/hashmap/hashmap_source_adapter.h (lines 1-47)
    • tensorflow_serving/servables/hashmap/hashmap_source_adapter.cc (lines 1-82)

Signature

class HashmapSourceAdapter final
    : public SimpleLoaderSourceAdapter<StoragePath,
                                       std::unordered_map<string, string>> {
 public:
  explicit HashmapSourceAdapter(const HashmapSourceAdapterConfig& config);
  ~HashmapSourceAdapter() override;
};

Import

#include "tensorflow_serving/servables/hashmap/hashmap_source_adapter.h"

I/O Contract

Inputs

Name Type Required Description
config HashmapSourceAdapterConfig Yes Configuration specifying the file format (e.g., SIMPLE_CSV)
path StoragePath Yes Filesystem path to the hashmap data file

Outputs

Name Type Description
hashmap std::unique_ptr<std::unordered_map<string, string>> Loaded hashmap servable
return Status OK on success; InvalidArgument for unexpected format or file structure

Usage Examples

Creating a Hashmap Source Adapter

HashmapSourceAdapterConfig config;
config.set_format(HashmapSourceAdapterConfig::SIMPLE_CSV);

HashmapSourceAdapter adapter(config);
// Connect to a storage path source
// Adapter will load hashmaps from paths provided by the source

Related Pages

Page Connections

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