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