Skip to main content
Glama
cskwork

Knowledge Retrieval Server

by cskwork

search-documents

Search document chunks using BM25 algorithm with keywords and optional domain filtering to retrieve relevant information from knowledge bases.

Instructions

Search documents using BM25 algorithm. Takes keyword arrays and returns relevant document chunks.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordsYesArray of keywords to search for (e.g., ["payment", "API", "authentication"])
domainNoDomain to search in (optional, e.g., "company", "customer")
topNNoMaximum number of results to return (default: 10)

Implementation Reference

  • Handler for 'search-documents' tool call. Extracts keywords, domain, topN from args, calls DocumentRepository.searchDocuments, and returns results as MCP TextContent.
    case 'search-documents': { const { keywords, domain, topN } = args as { keywords: string[]; domain?: string; topN?: number; }; const results = await repository.searchDocuments(keywords, { domain, topN, contextWindow: config.chunk.contextWindowSize }); const content: TextContent[] = [{ type: 'text', text: results }]; return { content }; }
  • src/index.ts:215-238 (registration)
    Registration of 'search-documents' tool in ListTools handler, including description and input schema definition.
    { name: 'search-documents', description: 'Search documents using BM25 algorithm. Takes keyword arrays and returns relevant document chunks.', inputSchema: { type: 'object', properties: { keywords: { type: 'array', items: { type: 'string' }, description: 'Array of keywords to search for (e.g., ["payment", "API", "authentication"])' }, domain: { type: 'string', description: 'Domain to search in (optional, e.g., "company", "customer")' }, topN: { type: 'number', description: 'Maximum number of results to return (default: 10)', default: 10 } }, required: ['keywords'] } },
  • Core implementation of document search using BM25. Selects appropriate calculator (domain-specific or global), constructs regex pattern from keywords, calls BM25.calculate, slices topN results, and formats output with context.
    async searchDocuments( keywords: string[], options: { domain?: string; topN?: number; contextWindow?: number; } = {} ): Promise<string> { this.ensureInitialized(); const { domain, topN = 10, contextWindow = 1 } = options; // 검색할 계산기 선택 let calculator: BM25Calculator | null; if (domain && this.domainCalculators.has(domain)) { calculator = this.domainCalculators.get(domain)!; } else { calculator = this.globalCalculator; } if (!calculator) { return "검색 가능한 문서가 없습니다."; } // 키워드를 정규식 패턴으로 변환 const pattern = keywords .map(keyword => escapeRegExp(keyword.trim())) .filter(keyword => keyword.length > 0) .join("|"); if (!pattern) { return "유효한 검색 키워드가 없습니다."; } // BM25 검색 수행 const results = calculator.calculate(pattern); const topResults = results.slice(0, topN); return this.formatSearchResults(topResults, contextWindow); }

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

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