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
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| vector_field | No | vector |
Implementation Reference
- src/tools/hash.py:148-174 (handler)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)}"
- src/tools/hash.py:148-148 (registration)The @mcp.tool() decorator registers the get_vector_from_hash function as an MCP tool, likely inferring schema from type hints.@mcp.tool()