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
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| vector | Yes | ||
| vector_field | No | vector |
Implementation Reference
- src/tools/hash.py:121-146 (handler)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)}"