Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

set_vector_in_hash

Store vector data as a field within a Redis hash to enable efficient vector search and retrieval operations in Redis databases.

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

  • The handler function for the 'set_vector_in_hash' MCP tool. It uses the @mcp.tool() decorator for registration and implements the logic to store a vector (converted to np.float32 binary blob) into a Redis hash field 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