Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

set_vector_in_hash

Store a vector (list of numbers) in a Redis hash by specifying the hash key and field name. Use this tool to efficiently manage vector data within Redis for structured storage and retrieval.

Instructions

Store a vector as a field in a Redis hash.

Args: name: The Redis hash key. vector_field: The field name inside the hash. Unless specifically required, use the default field name vector: The vector (list of numbers) to store in the hash.

Returns: True if the vector was successfully stored, False otherwise.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
vectorYes
vector_fieldNovector

Implementation Reference

  • Implementation of the set_vector_in_hash tool handler. Decorated with @mcp.tool() for automatic registration. Converts input vector to numpy float32 array, serializes to binary blob, and stores in Redis hash using hset.
    @mcp.tool() async def set_vector_in_hash( name: str, vector: List[float], vector_field: str = "vector" ) -> Union[bool, str]: """Store a vector as a field in a Redis hash. Args: name: The Redis hash key. vector_field: The field name inside the hash. Unless specifically required, use the default field name vector: The vector (list of numbers) to store in the hash. Returns: True if the vector was successfully stored, False otherwise. """ try: r = RedisConnectionManager.get_connection() # Convert the vector to a NumPy array, then to a binary blob using np.float32 vector_array = np.array(vector, dtype=np.float32) binary_blob = vector_array.tobytes() r.hset(name, vector_field, binary_blob) return True except RedisError as e: return f"Error storing vector in hash '{name}' with field '{vector_field}': {str(e)}"

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