Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

get_vector_from_hash

Retrieve and convert a vector stored as a binary blob in a Redis hash into a list of floats. Specify the hash key and optional field name to extract the vector data accurately.

Instructions

Retrieve a vector from a Redis hash and convert it back from binary blob.

Args: name: The Redis hash key. vector_field: The field name inside the hash. Unless specifically required, use the default field name

Returns: The vector as a list of floats, or an error message if retrieval fails.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
vector_fieldNovector

Implementation Reference

  • The core handler function for the 'get_vector_from_hash' MCP tool. It retrieves a binary vector blob from Redis hash, converts it to a NumPy array using float32 dtype, and returns it as a list. Decorated with @mcp.tool() for automatic registration and schema inference.
    @mcp.tool() async def get_vector_from_hash(name: str, vector_field: str = "vector"): """Retrieve a vector from a Redis hash and convert it back from binary blob. Args: name: The Redis hash key. vector_field: The field name inside the hash. Unless specifically required, use the default field name Returns: The vector as a list of floats, or an error message if retrieval fails. """ try: r = RedisConnectionManager.get_connection(decode_responses=False) # Retrieve the binary blob stored in the hash binary_blob = r.hget(name, vector_field) if binary_blob: # Convert the binary blob back to a NumPy array (assuming it's stored as float32) vector_array = np.frombuffer(binary_blob, dtype=np.float32) return vector_array.tolist() else: return f"Field '{vector_field}' not found in hash '{name}'." except RedisError as e: return f"Error retrieving vector field '{vector_field}' from hash '{name}': {str(e)}"
  • The @mcp.tool() decorator registers the get_vector_from_hash function as an MCP tool, likely inferring schema from type hints.
    @mcp.tool()

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/redis/mcp-redis'

If you have feedback or need assistance with the MCP directory API, please join our Discord server