Skip to main content
Glama
baidu

Baidu Vector Database MCP Server

Official
by baidu

create_vector_index

Create a vector index on a vector field in Baidu Vector Database to enable efficient similarity searches for AI applications.

Instructions

Create a vector index on a vector type field in the Mochow instance.

Args:
    table_name (str): Name of the table.
    index_name (str): Name of the index.
    field_name (str): Name of the vector field.
    index_type (str): Type of vector index. Supported values are "HNSW", "HNSWPQ", "HNSWSQ".
    metric_type (str): Distance metric. Supported values are "L2", "COSINE", "IP".
    params (Optional[dict[str, Any]]): Additional vector index parameters.

Returns:
    str: A message indicating the success of index creation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYes
index_nameYes
field_nameYes
index_typeNoHNSW
metric_typeNoL2
paramsNo

Implementation Reference

  • The MCP tool handler function decorated with @mcp.tool(), which registers and implements the 'create_vector_index' tool by delegating to the MochowConnector.
    @mcp.tool()
    async def create_vector_index(
        table_name: str,
        index_name: str,
        field_name: str,
        index_type: str = "HNSW",
        metric_type: str = "L2",
        params: Optional[dict[str, Any]] = None,
        ctx: Context = None) -> str:
        """
        Create a vector index on a vector type field in the Mochow instance.
    
        Args:
            table_name (str): Name of the table.
            index_name (str): Name of the index.
            field_name (str): Name of the vector field.
            index_type (str): Type of vector index. Supported values are "HNSW", "HNSWPQ", "HNSWSQ".
            metric_type (str): Distance metric. Supported values are "L2", "COSINE", "IP".
            params (Optional[dict[str, Any]]): Additional vector index parameters.
    
        Returns:
            str: A message indicating the success of index creation.
        """
        connector = ctx.request_context.lifespan_context.connector
        await connector.create_vector_index(table_name, index_name, field_name, index_type, metric_type, params)
        return f"Vector index '{index_name}' created successfully"
  • The helper method in MochowConnector class that performs the actual vector index creation using the MochowClient, including validation, parameter mapping, and index creation.
    async def create_vector_index(
        self,
        table_name: str,
        index_name: str,
        field_name: str,
        index_type: str = "HNSW",
        metric_type: str = "L2",
        params: Optional[dict[str, Any]] = None,
    ) -> bool:
        """
        Create a vector index on a given vector field.
    
        Args:
            table_name (str): Name of the table.
            index_name (str): Name of the index.
            field_name (str): Name of the vector field.
            index_type (str): Type of vector index. Supported values are "HNSW", "HNSWPQ", "PUCK".
            metric_type (str): Distance metric. Supported values are "L2", "COSINE", "IP".
            params (Optional[dict[str, Any]]): Additional vector index parameters.
    
        Returns:
            bool: True if the index is created successfully, False otherwise.
        """
        if self.database is None:
            raise ValueError("Switch to the database before create vector index")
    
        # check vector index
        index_existed = True
        try:
            self.database.table(table_name).describe_index(index_name)
        except ServerError as e:
            if e.code == ServerErrCode.INDEX_NOT_EXIST:
                index_existed = False
            else:
                raise ValueError(f"Failed to get index detail: {str(e)}")
    
        # index already existed with same name
        if index_existed:
            raise ValueError(f"Index already existed with same name '{index_name}'")
    
        # create vector index
        index_metric_type = None
        for k, v in MetricType.__members__.items():
            if k == metric_type:
                index_metric_type = v
        if index_metric_type is None:
            raise ValueError("Only the three metric types of L2, COSINE, and IP are supported.")
    
        indexes = []
        if index_type == "HNSW":
            indexes.append(
                VectorIndex(
                    index_name=index_name, index_type=IndexType.HNSW, field=field_name,
                    metric_type=index_metric_type, auto_build=False,
                    params=HNSWParams(m=params.get("M", 16), efconstruction=params.get("efConstruction", 200))))
        elif index_type == "HNSWPQ":
            indexes.append(
                VectorIndex(
                    index_name=index_name, index_type=IndexType.HNSW, field=field_name,
                    metric_type=index_metric_type, auto_build=False,
                    params=HNSWPQParams(
                        m=params.get("M", 16), efconstruction=params.get("efConstruction", 200),
                        NSQ=params.get("NSQ", 8), samplerate=params.get("sampleRate", 1.0))))
        elif index_type == "PUCK":
            indexes.append(
                VectorIndex(
                    index_name=index_name, index_type=IndexType.HNSW, field=field_name,
                    metric_type=index_metric_type, auto_build=False,
                    params=PUCKParams(
                        coarseClusterCount=params.get("coarseClusterCount", 5),
                        fineClusterCount=params.get("fineClusterCount", 5))))
        else:
            raise ValueError("Only the three vector index types of HNSW, HNSWPQ, PUCK are supported.")
    
        try:
            self.database.table(table_name).create_indexes(indexes)
            return True
        except Exception as e:
            raise ValueError(f"Failed to create vector index: {str(e)}")
  • The docstring in the handler function defining the input schema, supported values, and output format for the create_vector_index tool.
    """
    Create a vector index on a vector type field in the Mochow instance.
    
    Args:
        table_name (str): Name of the table.
        index_name (str): Name of the index.
        field_name (str): Name of the vector field.
        index_type (str): Type of vector index. Supported values are "HNSW", "HNSWPQ", "HNSWSQ".
        metric_type (str): Distance metric. Supported values are "L2", "COSINE", "IP".
        params (Optional[dict[str, Any]]): Additional vector index parameters.
    
    Returns:
        str: A message indicating the success of index creation.
    """
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While it mentions the action ('Create') and return value ('A message indicating success'), it lacks crucial behavioral details: whether this requires specific permissions, if it's destructive to existing data, performance implications, or error conditions. For a database indexing operation with zero annotation coverage, this is insufficient.

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 appropriately sized and well-structured with clear sections (purpose statement, Args, Returns). Every sentence earns its place by providing essential information. It could be slightly more concise by integrating the purpose statement with parameter explanations.

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

Completeness3/5

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

Given the tool's complexity (6 parameters, database indexing operation) and complete lack of annotations/output schema, the description provides adequate basic information but has significant gaps. It covers parameters well but lacks behavioral context, error handling, and detailed return format explanation beyond 'A message indicating success'.

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?

With 0% schema description coverage, the description compensates well by explaining all 6 parameters in the Args section, including their data types, purposes, and supported values for 'index_type' and 'metric_type'. It adds meaningful semantics beyond what the bare schema provides, though it doesn't fully document the optional 'params' dictionary's structure.

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 vector index') on a specific resource ('on a vector type field in the Mochow instance'). It distinguishes itself from sibling tools like 'drop_vector_index', 'rebuild_vector_index', and 'describe_index' by specifying it's for creation rather than deletion, rebuilding, or description.

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

Usage Guidelines3/5

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

The description implies usage context through the parameter explanations (e.g., 'Supported values are "HNSW", "HNSWPQ", "HNSWSQ"'), but doesn't explicitly state when to use this tool versus alternatives like 'rebuild_vector_index' or 'drop_vector_index'. No explicit when-not-to-use guidance or prerequisites are provided.

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/baidu/mochow-mcp-server-python'

If you have feedback or need assistance with the MCP directory API, please join our Discord server