Skip to main content
Glama
redis

Redis MCP Server

Official
by redis

create_vector_index_hash

Set up a Redis vector similarity index using the HNSW algorithm for efficient approximate nearest neighbor (ANN) search on float32 embeddings stored in a Redis hash.

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
dimNo
distance_metricNoCOSINE
index_nameNovector_index
prefixNodoc:
vector_fieldNovector

Implementation Reference

  • The main handler function for the 'create_vector_index_hash' tool. It is decorated with @mcp.tool(), which registers it as an MCP tool. The function creates a Redis vector similarity index on hash fields using HNSW index with configurable parameters.
    @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)}"

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