get_vector_from_hash
Retrieve vector embeddings stored as binary blobs in Redis hashes and convert them to usable float arrays for AI applications.
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 handler function decorated with @mcp.tool(), which registers and implements the get_vector_from_hash MCP tool. It retrieves a binary vector blob from a Redis hash field and converts it back to a list of floats.@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)}"