fulltext_search
Search text content in Baidu Vector Database tables using BM25 similarity with attribute filtering to retrieve relevant results.
Instructions
Perform full text search combining BM25 similarity and scalar attribute filtering in the Mochow instance.
Args:
table_name (str): Name of the table to search.
index_name (str): Name of the inverted index to perform full text search.
search_text (str): Text to search.
limit (int): Maximum number of results. Defaults to 10.
output_fields (Optional[list[str]]): Fields to return in the results. Defaults to None.
Returns:
str: A string containing the full text search results.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| table_name | Yes | ||
| index_name | Yes | ||
| search_text | Yes | ||
| filter_expr | No | ||
| limit | No | ||
| output_fields | No |
Implementation Reference
- src/mochow_mcp_server/server.py:716-746 (handler)The MCP tool handler for 'fulltext_search'. It extracts parameters, calls the underlying connector's fulltext_search method, formats the search results from HttpResponse into a readable string output.@mcp.tool() async def fulltext_search( table_name: str, index_name: str, search_text: str, filter_expr: Optional[str] = None, limit: int = 10, output_fields: Optional[list[str]] = None, ctx: Context = None, ) -> str: """ Perform full text search combining BM25 similarity and scalar attribute filtering in the Mochow instance. Args: table_name (str): Name of the table to search. index_name (str): Name of the inverted index to perform full text search. search_text (str): Text to search. limit (int): Maximum number of results. Defaults to 10. output_fields (Optional[list[str]]): Fields to return in the results. Defaults to None. Returns: str: A string containing the full text search results. """ connector = ctx.request_context.lifespan_context.connector search_results = await connector.fulltext_search(table_name, index_name, search_text, limit, output_fields, filter_expr) output = f"Full text search results for '{table_name}':\n" for row in search_results.rows: output += f"{str(row["row"])}\n" return output
- Helper method in the MochowConnector class that implements the core full-text search logic using BM25SearchRequest on the Mochow database client.async def fulltext_search( self, table_name: str, index_name: str, search_text: str, limit: int = 10, output_fields: Optional[list[str]] = None, filter_expr: Optional[str] = None, ) -> HttpResponse: """ Perform full text search combining BM25 similarity and scalar attribute filtering. Args: table_name (str): Name of the table to search. index_name (str): Name of the inverted index to perform full text search. search_text (str): Text to search. 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. Returns: HttpResponse: The HTTP response containing the search results. """ if self.database is None: raise ValueError("Switch to the database before perform full text search.") request = BM25SearchRequest(index_name=index_name, search_text=search_text, limit=limit, filter=filter_expr) try: return self.database.table(table_name).bm25_search(request=request, projections=output_fields) except Exception as e: raise ValueError(f"Failed to perform full text search: {str(e)}")
- src/mochow_mcp_server/server.py:716-716 (registration)The @mcp.tool() decorator registers the fulltext_search function as an MCP tool.@mcp.tool()