rebuild_vector_index
Reconstruct the vector index for a specified table to optimize search performance and accuracy in the Baidu Vector Database MCP Server.
Instructions
Rebuild the vector index in the Mochow instance.
Args:
table_name (str): Name of the table.
index_name (str): Name of the vector index to rebuild.
Returns:
str: A message indicating the success of index rebuild initiation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| index_name | Yes | ||
| table_name | Yes |
Implementation Reference
- src/mochow_mcp_server/server.py:607-622 (handler)MCP tool handler function decorated with @mcp.tool() that executes the rebuild_vector_index tool by calling the underlying connector method.@mcp.tool() async def rebuild_vector_index(table_name: str, index_name: str, ctx: Context = None) -> str: """ Rebuild the vector index in the Mochow instance. Args: table_name (str): Name of the table. index_name (str): Name of the vector index to rebuild. Returns: str: A message indicating the success of index rebuild initiation. """ connector = ctx.request_context.lifespan_context.connector await connector.rebuild_vector_index(table_name, index_name) return f"Initiate the rebuild of vector index '{index_name}' successfully."
- Core helper method in MochowConnector class that checks if the vector index exists and rebuilds it using the Mochow client's rebuild_index method.async def rebuild_vector_index(self, table_name: str, index_name: str) -> bool: """ Rebuild a vector index in a given table. Args: table_name (str): Name of the table. index_name (str): Name of the vector index. Returns: bool: True if the index is rebuilt successfully, False otherwise. """ if self.database is None: raise ValueError("Switch to the database before rebuild 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 not index_existed: raise ValueError(f"Vector index not existed with name '{index_name}'") try: self.database.table(table_name).rebuild_index(index_name) return True except Exception as e: raise ValueError(f"Failed to rebuild vector index: {str(e)}")
- src/mochow_mcp_server/server.py:607-607 (registration)Registration of the rebuild_vector_index tool using the @mcp.tool() decorator.@mcp.tool()