Skip to main content
Glama
baidu

Baidu Vector Database MCP Server

Official
by baidu

vector_search

Search for similar vectors in Baidu Vector Database tables while filtering results by scalar attributes to find relevant data points efficiently.

Instructions

Perform vector similarity search combining vector similarity and scalar attribute filtering in the Mochow instance.

Args:
    table_name (str): Name of the table to search.
    vector (list[float]): Search vector.
    vector_field (str): Target field containing vectors to search. Defaults to "vector".
    limit (int): Maximum number of results. Defaults to 10.
    output_fields (Optional[list[str]]): Fields to return in the results. Defaults to None.
    filter_expr (Optional[str]): Filter expression for scalar attributes. Defaults to None.
    params: Additional vector search parameters

Returns:
    str: A string containing the vector search results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
table_nameYes
vectorYes
vector_fieldNovector
filter_exprNo
limitNo
output_fieldsNo

Implementation Reference

  • The main handler function for the 'vector_search' MCP tool. It uses the MochowConnector to perform the vector search and formats the results as a string.
    @mcp.tool()
    async def vector_search(
        table_name: str, 
        vector: list[float],
        vector_field: str = "vector",
        filter_expr: Optional[str] = None,
        limit: int = 10,
        output_fields: Optional[list[str]] = None,
        ctx: Context = None,
    ) -> str:
        """
        Perform vector similarity search combining vector similarity and scalar attribute filtering in the Mochow instance.
    
        Args:
            table_name (str): Name of the table to search.
            vector (list[float]): Search vector.
            vector_field (str): Target field containing vectors to search. Defaults to "vector".
            limit (int): Maximum number of results. Defaults to 10.
            output_fields (Optional[list[str]]): Fields to return in the results. Defaults to None.
            filter_expr (Optional[str]): Filter expression for scalar attributes. Defaults to None.
            params: Additional vector search parameters
    
        Returns:
            str: A string containing the vector search results.
        """
        connector = ctx.request_context.lifespan_context.connector
        search_results = await connector.vector_search(table_name, vector, vector_field, limit, output_fields, filter_expr)
    
        output = f"Vector search results for '{table_name}':\n"
        for row in search_results.rows:
            output += f"{str(row["row"])}\n"
    
        return output
  • The @mcp.tool() decorator registers the vector_search function as an MCP tool.
    @mcp.tool()
  • Helper method in MochowConnector class that constructs the VectorTopkSearchRequest and calls the underlying database.vector_search method to execute the vector search.
    async def vector_search(
        self,
        table_name: str, 
        vector: list[float],
        vector_field: str = "vector",
        limit: int = 10,
        output_fields: Optional[list[str]] = None,
        filter_expr: Optional[str] = None,
        params: Optional[dict[str, Any]] = None,
    ) -> HttpResponse:
        """
        Perform vector similarity search combining vector similarity and scalar attribute filtering.
    
        Args:
            table_name (str): Name of the table to search.
            vector (list[float]): Search vector.
            vector_field (str): Target field containing vectors to search. Defaults to "vector".
            limit (int): Maximum number of results. Defaults to 10.
            output_fields (Optional[list[str]]): Fields to return in the results. Defaults to None.
            filter_expr (Optional[str]): Filter expression for scalar attributes. Defaults to None.
            params (Optional[dict[str, Any]]): Additional vector search parameters. Defaults to None.
    
        Returns:
            HttpResponse: The HTTP response containing the search results.
        """
        if self.database is None:
            raise ValueError("Switch to the database before perform vector search.")
    
        request = VectorTopkSearchRequest(vector_field=vector_field, vector=FloatVector(vector),
                                          limit=limit, filter=filter_expr,
                                          config=VectorSearchConfig(ef=params.get("ef", 200)))
        try:
            return self.database.table(table_name).vector_search(request=request, projections=output_fields)
        except Exception as e:
            raise ValueError(f"Failed to perform vector search: {str(e)}")
  • Imports schema classes used in the vector_search implementation, such as VectorTopkSearchRequest for input validation and VectorSearchConfig for parameters.
    from pymochow.model.table import VectorTopkSearchRequest, VectorSearchConfig, FloatVector, BM25SearchRequest
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. It mentions what the tool does but lacks critical behavioral details: authentication requirements, rate limits, error conditions, performance characteristics, or what happens when no results match. The return type is mentioned but without format details.

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 efficiently structured with a clear purpose statement followed by parameter documentation. Every sentence adds value, though the 'params' parameter is vaguely documented as 'Additional vector search parameters' without specifics.

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?

For a 6-parameter search tool with no annotations and no output schema, the description covers the basic operation and parameters adequately. However, it lacks details about the return format (beyond 'string'), error handling, performance implications, and how vector similarity is calculated.

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 documenting all 6 parameters with clear explanations of their purpose and defaults. It adds meaningful context beyond the bare schema, explaining what each parameter controls in the search operation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool performs 'vector similarity search combining vector similarity and scalar attribute filtering' in a specific system (Mochow instance). It specifies both the similarity search and filtering aspects, though it doesn't explicitly differentiate from sibling tools like fulltext_search or select_table_rows.

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 like fulltext_search or select_table_rows. It mentions the tool's capabilities but offers no context about appropriate use cases, prerequisites, or exclusions.

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