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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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)}"
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It discloses the tool's behavior by stating it stores a vector and returns a boolean success indicator, but doesn't cover critical aspects like error conditions (e.g., invalid vector format, Redis connection issues), performance implications, or whether it overwrites existing fields. It adds some context but leaves gaps for a mutation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and front-loaded with the core purpose, followed by organized sections for Args and Returns. Every sentence adds value without redundancy, and it efficiently covers key details in a compact format.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no annotations, 0% schema coverage, but an output schema exists (implied by 'Returns' section), the description is reasonably complete. It explains the tool's purpose, parameters, and return value, though it could benefit from more behavioral context (e.g., error handling) for a mutation tool with no annotation support.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It provides clear semantics for all three parameters: 'name' as the Redis hash key, 'vector_field' as the field name with a default hint, and 'vector' as a list of numbers. This adds meaningful context beyond the bare schema, though it could elaborate on constraints (e.g., vector length limits).

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('Store a vector as a field in a Redis hash'), identifies the resource (Redis hash), and distinguishes it from siblings like 'hset' (general hash set) and 'get_vector_from_hash' (retrieval). It provides a precise verb+resource combination with clear scope.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context by specifying it's for storing vectors in Redis hashes, which helps differentiate from general storage tools like 'set' or 'hset'. However, it lacks explicit guidance on when to use this vs. alternatives like 'hset' for non-vector data or 'create_vector_index_hash' for indexing, and doesn't mention prerequisites or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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