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

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.

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