Skip to main content
Glama

ask_rag

Query a knowledge base to get answers from processed documents using semantic search and vector retrieval technology.

Instructions

向 RAG 知识库提问,并根据存储的信息返回答案。 使用场景:

  • 询问特定主题或概念

  • 请求解释或定义

  • 从处理过的文档中获取信息

  • 基于学习的文本或文档获取答案

参数: query: 要向知识库提出的问题或查询。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Registers the MCP tool named 'rag_ask' (likely the intended 'ask_rag') with its input schema definition including parameters for query, mode, collection, limit, and threshold.
    @self.server.list_tools()
    async def list_tools() -> List[Tool]:
        """列出可用的MCP工具。"""
        return [
            Tool(
                name="rag_ask",
                description="向RAG知识库提问查询信息",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "query": {
                            "type": "string",
                            "description": "搜索查询"
                        },
                        "mode": {
                            "type": "string",
                            "enum": ["raw", "summary"],
                            "description": "检索模式",
                            "default": "raw"
                        },
                        "collection": {
                            "type": "string",
                            "description": "要搜索的集合名称",
                            "default": "default"
                        },
                        "limit": {
                            "type": "integer",
                            "description": "最大结果数量",
                            "default": 5,
                            "minimum": 1,
                            "maximum": 20
                        },
                        "threshold": {
                            "type": "number",
                            "description": "相似度阈值",
                            "default": 0.7,
                            "minimum": 0.0,
                            "maximum": 1.0
                        }
                    },
                    "required": ["query"]
                }
            )
        ]
  • Input schema for the 'rag_ask' tool defining parameters: query (required string), mode (raw/summary), collection (default 'default'), limit (1-20, default 5), threshold (0.0-1.0, default 0.7).
    Tool(
        name="rag_ask",
        description="向RAG知识库提问查询信息",
        inputSchema={
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "搜索查询"
                },
                "mode": {
                    "type": "string",
                    "enum": ["raw", "summary"],
                    "description": "检索模式",
                    "default": "raw"
                },
                "collection": {
                    "type": "string",
                    "description": "要搜索的集合名称",
                    "default": "default"
                },
                "limit": {
                    "type": "integer",
                    "description": "最大结果数量",
                    "default": 5,
                    "minimum": 1,
                    "maximum": 20
                },
                "threshold": {
                    "type": "number",
                    "description": "相似度阈值",
                    "default": 0.7,
                    "minimum": 0.0,
                    "maximum": 1.0
                }
            },
            "required": ["query"]
        }
    )
  • The handler function for MCP tool calls. For 'rag_ask', it extracts parameters, embeds the query using embedding model, searches the vector database, formats and returns search results as text content. Supports 'raw' and 'summary' modes (summary not fully implemented).
    @self.server.call_tool()
    async def call_tool(name: str, arguments: Dict[str, Any]) -> Sequence[types.TextContent]:
        """调用MCP工具。"""
        if name == "rag_ask":
            try:
                logger.info(f"开始处理RAG检索请求: {arguments.get('query', 'unknown')}")
                
                # 获取组件
                vector_db = await get_vector_database()
                embedding_model = await get_embedding_model()
    
                # 提取参数
                query = arguments["query"]
                mode = arguments.get("mode", "raw")
                collection = arguments.get("collection", "default")
                limit = arguments.get("limit", 5)
                threshold = arguments.get("threshold", 0.7)
    
                logger.info(f"编码查询: {query}")
                # 编码查询
                query_embedding = await embedding_model.encode_single(query)
    
                logger.info(f"搜索数据库,集合: {collection}, 限制: {limit}")
                # 搜索数据库
                search_results = await vector_db.search(
                    query_embedding=query_embedding,
                    collection_name=collection,
                    limit=limit,
                    threshold=threshold
                )
    
                # 格式化结果
                if not search_results:
                    logger.info("未找到相关文档")
                    return [types.TextContent(
                        type="text",
                        text=f"为查询 '{query}' 未找到相关文档"
                    )]
    
                logger.info(f"找到 {len(search_results)} 个相关文档")
                result_text = f"为查询 '{query}' 找到 {len(search_results)} 个相关文档\n\n"
    
                for i, result in enumerate(search_results, 1):
                    result_text += f"[{i}] 相似度: {result.score:.3f}\n"
                    result_text += f"内容: {result.document.content}\n"
                    if result.document.metadata.get("source"):
                        result_text += f"来源: {result.document.metadata['source']}\n"
                    result_text += "\n"
    
                # 对于摘要模式,添加摘要生成
                if mode == "summary":
                    result_text += "\n--- 摘要模式 ---\n"
                    result_text += "摘要生成功能尚未实现。\n"
    
                logger.info("RAG检索完成")
                return [types.TextContent(type="text", text=result_text)]
    
            except Exception as e:
                logger.error(f"工具调用失败: {e}")
                return [types.TextContent(
                    type="text",
                    text=f"检索过程中出错: {str(e)}"
                )]
        else:
            raise ValueError(f"未知工具: {name}")
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it states the tool queries a RAG knowledge base and returns answers, it doesn't describe important behavioral aspects like: what types of answers are returned (structured/unstructured), whether there are rate limits, authentication requirements, response formats, or error conditions. For a query tool with no annotation coverage, this leaves significant gaps in understanding how the tool behaves.

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 usage scenarios and parameter documentation. It's appropriately sized for a single-parameter tool. The only minor inefficiency is the repetition of similar concepts in the usage scenarios (e.g., '询问特定主题或概念' and '请求解释或定义' could potentially be combined).

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 that there's an output schema (which handles return values), the description doesn't need to explain outputs. However, for a query tool with no annotations, the description should provide more behavioral context about how the tool operates, what it expects from the knowledge base, and potential limitations. The usage scenarios help, but more operational transparency would improve completeness.

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?

The description explicitly documents the single parameter: 'query: 要向知识库提出的问题或查询' (query: the question or query to ask the knowledge base). With 0% schema description coverage and only one parameter, this provides complete parameter semantics beyond what the bare schema offers. The description fully compensates for the lack of schema documentation.

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: '向 RAG 知识库提问,并根据存储的信息返回答案' (Ask the RAG knowledge base questions and return answers based on stored information). This specifies the verb (ask/query) and resource (RAG knowledge base). However, it doesn't explicitly differentiate from its sibling 'ask_rag_filtered', which appears to be a similar querying tool with filtering capabilities.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides four clear usage scenarios (asking about topics/concepts, requesting explanations/definitions, getting information from processed documents, obtaining answers based on learned text/documents). This gives good context about when to use the tool. However, it doesn't explicitly state when NOT to use it or mention alternatives like 'ask_rag_filtered' despite having that sibling tool available.

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/kalicyh/mcp-rag'

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