Skip to main content
Glama
vectara

Vectara MCP server

Official
by vectara

search_vectara

Execute a semantic search query using Vectara to retrieve contextually relevant results without generation. Provide a query, corpus keys, and API key to access matching search results from specified corpora.

Instructions

Run a semantic search query using Vectara, without generation.

Args:
    query: str, The user query to run - required.
    corpus_keys: list[str], List of Vectara corpus keys to use for the search - required. Please ask the user to provide one or more corpus keys. 
    api_key: str, The Vectara API key - required.
    n_sentences_before: int, Number of sentences before the answer to include in the context - optional, default is 2.
    n_sentences_after: int, Number of sentences after the answer to include in the context - optional, default is 2.
    lexical_interpolation: float, The amount of lexical interpolation to use - optional, default is 0.005.

Returns:
    The response from Vectara, including the matching search results.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
api_keyNo
corpus_keysNo
lexical_interpolationNo
n_sentences_afterNo
n_sentences_beforeNo
queryYes

Implementation Reference

  • The @mcp.tool()-decorated async function search_vectara implements the core tool logic: parameter validation, payload construction for semantic search (no generation), API call to Vectara query endpoint, and error handling with progress reporting.
    @mcp.tool()
    async def search_vectara(
        query: str,
        ctx: Context,
        corpus_keys: list[str],
        n_sentences_before: int = 2,
        n_sentences_after: int = 2,
        lexical_interpolation: float = 0.005
    ) -> dict:
        """
        Run a semantic search query using Vectara, without generation.
    
        Args:
            query: str, The user query to run - required.
            corpus_keys: list[str], List of Vectara corpus keys to use for the search - required. Please ask the user to provide one or more corpus keys.
            n_sentences_before: int, Number of sentences before the answer to include in the context - optional, default is 2.
            n_sentences_after: int, Number of sentences after the answer to include in the context - optional, default is 2.
            lexical_interpolation: float, The amount of lexical interpolation to use - optional, default is 0.005.
    
        Note: API key must be configured first using 'setup_vectara_api_key' tool
    
        Returns:
            dict: Raw search results from Vectara API containing:
                - "search_results": List of search result objects with scores, text, and metadata
                - Additional response metadata from the API
            On error, returns dict with "error" key containing error message.
        """
        # Validate parameters
        validation_error = _validate_common_parameters(query, corpus_keys)
        if validation_error:
            return {"error": validation_error}
    
        if ctx:
            ctx.info(f"Running Vectara semantic search query: {query}")
    
        try:
            payload = _build_query_payload(
                query=query,
                corpus_keys=corpus_keys,
                n_sentences_before=n_sentences_before,
                n_sentences_after=n_sentences_after,
                lexical_interpolation=lexical_interpolation,
                enable_generation=False
            )
    
            result = await _call_vectara_query(payload, ctx)
            return result
    
        except Exception as e:
            return {"error": _format_error("Vectara semantic search query", e)}
  • The @mcp.tool() decorator registers the search_vectara function as an MCP tool with the FastMCP server instance.
    @mcp.tool()
  • Function signature defines the input schema (parameters with types and defaults) and output type (dict) for the search_vectara tool, with detailed docstring description.
    async def search_vectara(
        query: str,
        ctx: Context,
        corpus_keys: list[str],
        n_sentences_before: int = 2,
        n_sentences_after: int = 2,
        lexical_interpolation: float = 0.005
    ) -> dict:
  • Helper function _build_query_payload constructs the API payload for search_vectara, configuring search parameters, reranker, and conditionally generation settings.
    def _build_query_payload(
        query: str,
        corpus_keys: list[str],
        n_sentences_before: int = 2,
        n_sentences_after: int = 2,
        lexical_interpolation: float = 0.005,
        max_used_search_results: int = 10,
        generation_preset_name: str = "vectara-summary-table-md-query-ext-jan-2025-gpt-4o",
        response_language: str = "eng",
        enable_generation: bool = True
    ) -> dict:
        """Build the query payload for Vectara API"""
        payload = {
            "query": query,
            "search": {
                "limit": 100,
                "corpora": [
                    {
                        "corpus_key": corpus_key,
                        "lexical_interpolation": lexical_interpolation
                    } for corpus_key in corpus_keys
                ],
                "context_configuration": {
                    "sentences_before": n_sentences_before,
                    "sentences_after": n_sentences_after
                },
                "reranker": {
                    "type": "customer_reranker",
                    "reranker_name": "Rerank_Multilingual_v1",
                    "limit": 100,
                    "cutoff": 0.2
                }
            },
            "save_history": True,
        }
    
        if enable_generation:
            payload["generation"] = {
                "generation_preset_name": generation_preset_name,
                "max_used_search_results": max_used_search_results,
                "response_language": response_language,
                "citations": {
                    "style": "markdown",
                    "url_pattern": "{doc.url}",
                    "text_pattern": "{doc.title}"
                },
                "enable_factual_consistency_score": True
            }
    
        return payload
  • Helper function _call_vectara_query makes the HTTP POST to Vectara's /query endpoint using shared request logic.
    async def _call_vectara_query(
        payload: dict,
        ctx: Context = None,
        api_key_override: str = None
    ) -> dict:
        """Make API call to Vectara query endpoint"""
        return await _make_api_request(
            f"{VECTARA_BASE_URL}/query",
            payload,
            ctx,
            api_key_override,
            "query"
        )
Behavior2/5

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

No annotations are provided, so the description carries full burden. It discloses that the tool performs a semantic search and returns matching results, but lacks details on behavioral traits like authentication needs (though 'api_key' is a parameter), rate limits, error handling, or what 'without generation' entails operationally. The description doesn't contradict annotations (none provided), but offers minimal behavioral context beyond basic functionality.

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 well-structured with a clear purpose statement followed by 'Args:' and 'Returns:' sections. It's appropriately sized, with each sentence adding value (e.g., explaining parameters and returns). However, it could be more front-loaded by integrating key parameter details into the initial statement, and some phrasing is slightly verbose (e.g., 'Please ask the user to provide').

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 6 parameters, 0% schema coverage, no annotations, and no output schema, the description is moderately complete. It covers parameter semantics well but lacks behavioral transparency (e.g., auth, limits) and detailed return value explanation beyond 'including the matching search results.' For a search tool with multiple parameters and no structured support, more context on outputs and behavior would improve completeness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It adds significant meaning beyond the schema by explaining all 6 parameters: purpose (e.g., 'query' is 'The user query to run'), requirements (e.g., 'corpus_keys' and 'api_key' are 'required'), defaults (e.g., 'n_sentences_before' default is 2), and user guidance (e.g., 'Please ask the user to provide one or more corpus keys'). This fully documents parameter semantics not covered by the schema.

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's purpose: 'Run a semantic search query using Vectara, without generation.' It specifies the verb ('search'), resource ('Vectara'), and distinguishes it from sibling 'ask_vectara' by noting 'without generation.' However, it doesn't explicitly contrast with the sibling tool beyond this implicit distinction.

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 by stating 'without generation,' suggesting this is for pure search versus generative queries. It mentions 'Please ask the user to provide one or more corpus keys' for the 'corpus_keys' parameter, offering some guidance. However, it lacks explicit when-to-use versus 'ask_vectara' or other alternatives, and no exclusions 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

Related 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/vectara/vectara-mcp'

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