Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

create_vector_index_hash

Set up a Redis vector similarity index using HNSW algorithm for approximate nearest neighbor search on hash data with float32 embeddings.

Instructions

Create a Redis 8 vector similarity index using HNSW on a Redis hash.

This function sets up a Redis index for approximate nearest neighbor (ANN) search using the HNSW algorithm and float32 vector embeddings.

Args: index_name: The name of the Redis index to create. Unless specifically required, use the default name for the index. prefix: The key prefix used to identify documents to index (e.g., 'doc:'). Unless specifically required, use the default prefix. vector_field: The name of the vector field to be indexed for similarity search. Unless specifically required, use the default field name dim: The dimensionality of the vectors stored under the vector_field. distance_metric: The distance function to use (e.g., 'COSINE', 'L2', 'IP').

Returns: A string indicating whether the index was created successfully or an error message.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
index_nameNovector_index
prefixNodoc:
vector_fieldNovector
dimNo
distance_metricNoCOSINE

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The core implementation of the 'create_vector_index_hash' tool. This async function, decorated with @mcp.tool(), creates a Redis vector similarity index using HNSW index on hash data structures. It handles parameters for index configuration and performs the index creation via Redis commands.
    @mcp.tool()
    async def create_vector_index_hash(
        index_name: str = "vector_index",
        prefix: str = "doc:",
        vector_field: str = "vector",
        dim: int = 1536,
        distance_metric: str = "COSINE",
    ) -> str:
        """
        Create a Redis 8 vector similarity index using HNSW on a Redis hash.
    
        This function sets up a Redis index for approximate nearest neighbor (ANN)
        search using the HNSW algorithm and float32 vector embeddings.
    
        Args:
            index_name: The name of the Redis index to create. Unless specifically required, use the default name for the index.
            prefix: The key prefix used to identify documents to index (e.g., 'doc:'). Unless specifically required, use the default prefix.
            vector_field: The name of the vector field to be indexed for similarity search. Unless specifically required, use the default field name
            dim: The dimensionality of the vectors stored under the vector_field.
            distance_metric: The distance function to use (e.g., 'COSINE', 'L2', 'IP').
    
        Returns:
            A string indicating whether the index was created successfully or an error message.
        """
        try:
            r = RedisConnectionManager.get_connection()
    
            index_def = IndexDefinition(prefix=[prefix])
            schema = VectorField(
                vector_field,
                "HNSW",
                {"TYPE": "FLOAT32", "DIM": dim, "DISTANCE_METRIC": distance_metric},
            )
    
            r.ft(index_name).create_index([schema], definition=index_def)
            return f"Index '{index_name}' created successfully."
        except RedisError as e:
            return f"Error creating index '{index_name}': {str(e)}"
  • The @mcp.tool() decorator registers the 'create_vector_index_hash' function as an MCP tool.
    @mcp.tool()
  • The function signature and docstring define the input schema (parameters with types and defaults) and output (str: success/error message).
    async def create_vector_index_hash(
        index_name: str = "vector_index",
        prefix: str = "doc:",
        vector_field: str = "vector",
        dim: int = 1536,
        distance_metric: str = "COSINE",
    ) -> str:
        """
        Create a Redis 8 vector similarity index using HNSW on a Redis hash.
    
        This function sets up a Redis index for approximate nearest neighbor (ANN)
        search using the HNSW algorithm and float32 vector embeddings.
    
        Args:
            index_name: The name of the Redis index to create. Unless specifically required, use the default name for the index.
            prefix: The key prefix used to identify documents to index (e.g., 'doc:'). Unless specifically required, use the default prefix.
            vector_field: The name of the vector field to be indexed for similarity search. Unless specifically required, use the default field name
            dim: The dimensionality of the vectors stored under the vector_field.
            distance_metric: The distance function to use (e.g., 'COSINE', 'L2', 'IP').
    
        Returns:
            A string indicating whether the index was created successfully or an error message.
Behavior3/5

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

With no annotations provided, the description carries full burden. It adequately discloses that this is a creation/mutation operation ('Create', 'sets up') and mentions the algorithm (HNSW) and vector type (float32). However, it lacks important behavioral details: whether this operation is idempotent, what permissions are required, potential performance impact, or error conditions beyond the generic return statement. The Returns section is minimal but doesn't contradict any annotations.

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

Conciseness4/5

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

The description is well-structured with purpose statement, technical details, parameter documentation, and return value - all front-loaded. Every sentence earns its place. Minor deduction because the 'Unless specifically required, use the default...' phrasing is repeated for three parameters, creating some redundancy that could be consolidated.

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 this is a complex mutation tool (creating vector indexes) with 5 parameters, 0% schema coverage, no annotations, but with output schema (implied by 'Returns'), the description does quite well. It explains what the tool does, documents all parameters thoroughly, and mentions the return. It could be more complete by addressing idempotency, error conditions, or relationship to other vector operations, but covers the essentials adequately.

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

Parameters5/5

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

With 0% schema description coverage (titles only, no descriptions), the description fully compensates by providing detailed parameter documentation in the Args section. Each of the 5 parameters gets clear explanations with examples and default usage guidance. The description adds significant meaning beyond what the bare schema provides, especially for understanding what 'prefix', 'vector_field', and 'distance_metric' mean in context.

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 ('Create a Redis 8 vector similarity index'), technology ('using HNSW on a Redis hash'), and purpose ('for approximate nearest neighbor (ANN) search using the HNSW algorithm and float32 vector embeddings'). It distinguishes this tool from siblings like 'set_vector_in_hash' or 'vector_search_hash' by focusing on index creation rather than data manipulation or querying.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. While it mentions the tool's purpose, it doesn't specify prerequisites (e.g., whether Redis is configured for vector search), when this should be called versus using existing indexes, or what happens if an index already exists. The Args section includes 'Unless specifically required, use the default...' but this is parameter guidance, not usage context.

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