Skip to main content
Glama

Explain PgVector Query Plan

explain_vector_query

Runs read-only EXPLAIN ANALYZE on pre-filtered vector search SQL to detect HNSW index misses and return targeted indexing advice.

Instructions

在只读事务中对带 Pre-filtering 条件的向量检索 SQL 执行 EXPLAIN ANALYZE(FORMAT JSON),解析是否命中 HNSW 索引、过滤淘汰行数与缓存块命中,给出针对性索引调优建议。

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "query": "<query>"
    },
    "name": "explain_vector_query"
  }
}

Input Schema

NameRequiredDescriptionDefault
queryYes用于生成向量并测试执行计划的查询文本
top_kNo执行计划测试 LIMIT 条数
analyzeNo是否执行真实 EXPLAIN ANALYZE + BUFFERS
tenant_idNoPre-filtering 租户过滤条件default
doc_statusNo文档状态过滤条件active
collection_nameNo可选:知识库集合名称,用于验证过滤条件下索引命中行为

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.1.0

TDQS

A3.6/5.0
Behavior4/5

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

No annotations are supplied, so the description carries the full burden of disclosure. It does well: it states that execution happens inside a read-only transaction, which establishes the safety profile, and it lists the concrete diagnostics produced (HNSW index hit, rows eliminated by the filter, buffer cache hits, tuning suggestions). What it does not disclose is that setting analyze=true actually executes the query with real timing and buffer reads, which has a cost; the analyze parameter's own description hints at this, but the top-level description does not.

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 a single dense sentence that leads with the core operation and then lists the diagnostics and the output. Nothing is wasted, but packing execution mode, parsed metrics, and the advice output into one sentence makes it harder to scan; splitting it into operation and output would improve structure without adding length.

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 six-parameter tool with no annotations and no output schema, the description covers the operation, the safety context, and what the tool reports, which is reasonably complete. It is still missing guidance on when to choose it over its siblings and on the execution cost when analyze=true, and because there is no output schema, the description would need to say more about the shape of the returned plan and advice.

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

Parameters3/5

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

Schema description coverage is 100%, so every one of the six parameters is already documented in the input schema, which sets the baseline at 3. The description adds conceptual framing by tying the tool to pre-filtering conditions and to HNSW index usage, which explains why tenant_id, doc_status, and collection_name exist, but it adds no syntax or format details beyond what the schema already provides.

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 names a specific verb and resource: it runs EXPLAIN ANALYZE (FORMAT JSON) inside a read-only transaction against a vector-retrieval SQL query that carries pre-filtering conditions. It also states what the tool extracts (whether the HNSW index was used, how many rows the filter discarded, and buffer cache hits) and that it produces index-tuning advice. The purpose is clear, but the description never contrasts the tool with its siblings inspect_retrieval and view_chunk_context, so the agent must infer the difference from the tool names alone.

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 usage context is only implied: the mention of pre-filtering and HNSW index hits signals that this is a diagnostic tool for filtered vector search, but the description never says when to call this tool rather than inspect_retrieval or view_chunk_context, nor when not to call it. There is no mention of prerequisites or of how costly it is to run a real EXPLAIN ANALYZE.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.