Skip to main content
Glama

semantic_search

Find semantically related content in user-configured documents using OpenAI Embeddings. Input a query and optional limit to retrieve the most relevant results efficiently.

Instructions

意味的に関連する内容を検索

Args:
    query: 検索クエリ
    limit: 返す結果の最大数(デフォルト: 5)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
queryYes

Implementation Reference

  • MCP tool handler for semantic_search. Registers the tool with @mcp.tool() and delegates execution to DocumentManager.semantic_search.
    @mcp.tool()
    async def semantic_search(query: str, limit: int = 5) -> str:
        """意味的に関連する内容を検索
    
        Args:
            query: 検索クエリ
            limit: 返す結果の最大数(デフォルト: 5)
        """
        return doc_manager.semantic_search(query, limit)
  • Core implementation of semantic search using OpenAI embeddings, cosine similarity, and preview extraction from cached document embeddings.
    def semantic_search(self, query: str, limit: int = 5) -> str:
        """意味的に関連する内容を検索"""
        if not self.client:
            return "Error: OpenAI API key not configured"
    
        if not self.embeddings_cache:
            return "Error: No embeddings available. Run 'python scripts/generate_metadata.py' first."
    
        try:
            # クエリのembeddingを取得
            query_embedding = self._get_embedding(query)
    
            # 各ドキュメントとの類似度を計算
            similarities = []
            for doc_path, doc_embedding in self.embeddings_cache.items():
                # embeddingがリストとして保存されているので、そのまま使用
                similarity = self._cosine_similarity(query_embedding, doc_embedding)
                similarities.append((doc_path, similarity))
    
            # 類似度でソート
            similarities.sort(key=lambda x: x[1], reverse=True)
    
            # 結果を構築
            results = []
            for doc_path, similarity in similarities[:limit]:
                description = self.docs_metadata.get(doc_path, "")
                result_line = f"{doc_path} (相似度: {similarity:.3f})"
                if description:
                    result_line += f" - {description}"
                results.append(result_line)
    
                # 関連する内容を一部抽出
                if doc_path in self.docs_content:
                    content = self.docs_content[doc_path]
                    preview = self._extract_preview(content, query)
                    if preview:
                        results.append(f"  → {preview}")
    
            return "\n\n".join(results)
    
        except Exception as e:
            return f"Error during semantic search: {e}"
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. It states the tool performs a search but lacks details on what 'semantically related' means, how results are ranked, whether it's read-only or has side effects, or any rate limits or authentication requirements. This leaves significant gaps for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is highly concise and well-structured: a brief purpose statement followed by clear parameter explanations in a bullet-like format. Every sentence adds value without redundancy, making it easy to scan and understand quickly.

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 the tool's moderate complexity (2 parameters, no output schema, no annotations), the description is minimally adequate. It covers the purpose and parameters but lacks behavioral details, usage context, and output information. Without annotations or output schema, more completeness would be beneficial for effective agent use.

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 adds meaningful context for both parameters: 'query' is described as a search query, and 'limit' specifies it's the maximum number of results to return with a default of 5. With 0% schema description coverage, this compensates well by clarifying the purpose and default value, though it doesn't detail format constraints or examples.

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 as '意味的に関連する内容を検索' (search for semantically related content), which is a specific verb+resource combination. It distinguishes itself from siblings like 'get_doc', 'grep_docs', and 'list_docs' by focusing on semantic rather than exact or list-based searches. However, it doesn't explicitly contrast with these siblings in the description text itself.

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. There is no mention of when semantic search is appropriate compared to exact matching ('grep_docs') or listing documents ('list_docs'), nor any prerequisites or exclusions for its use.

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/herring101/docs-mcp'

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