knowledge_recall
Search and retrieve raw content from Get笔记 knowledge bases to quickly find and preview relevant information without AI processing.
Instructions
在Get笔记知识库中召回相关内容,返回未经AI处理的原始结果。可用于快速查找和预览。
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| question | Yes | 要搜索的问题 | |
| topic_id | No | 知识库ID(单个) | |
| topic_ids | No | 知识库ID列表(当前只支持1个)。注意:topic_id和topic_ids可都不提供,如果配置了GET_BIJI_DEFAULT_TOPIC_ID环境变量。优先使用topic_id | |
| top_k | No | 返回相似度最高的N个结果 | |
| intent_rewrite | No | 是否进行问题意图重写 | |
| select_matrix | No | 是否对结果进行重选 | |
| history | No | 对话历史,用于追问场景 |
Implementation Reference
- src/index.ts:179-221 (handler)MCP tool handler for 'knowledge_recall': extracts parameters, calls client.knowledgeRecall, formats and returns results as MCP content.case 'knowledge_recall': { const { question, topic_id, topic_ids, top_k, intent_rewrite, select_matrix, history } = args as { question: string; topic_id?: string; topic_ids?: string[]; top_k?: number; intent_rewrite?: boolean; select_matrix?: boolean; history?: ChatMessage[]; }; const result = await client.knowledgeRecall({ question, topic_id, topic_ids, top_k, intent_rewrite, select_matrix, history, }); // 格式化输出 const formattedResults = result.c.data.map((item, index) => ({ index: index + 1, title: item.title || '无标题', content: item.content.substring(0, 500) + (item.content.length > 500 ? '...' : ''), score: item.score.toFixed(4), type: item.type, source: item.recall_source, })); return { content: [ { type: 'text', text: JSON.stringify({ total: result.c.data.length, results: formattedResults, }, null, 2), }, ], }; }
- src/types.ts:49-127 (schema)TypeScript interface defining KnowledgeRecallRequest parameters, matching the MCP inputSchema.export interface KnowledgeRecallRequest { question: string; topic_id?: string; // 单个知识库ID,优先使用 topic_ids?: string[]; // 知识库ID列表(当前只支持1个) top_k?: number; intent_rewrite?: boolean; select_matrix?: boolean; history?: ChatMessage[]; } // 知识库召回响应 export interface KnowledgeRecallResponse { h: { c: number; e: string; s: number; t: number; apm: string; }; c: { data: RecallItem[]; }; } // 召回项 export interface RecallItem { id: string; title: string; content: string; score: number; type: 'FILE' | 'NOTE' | 'BLOGGER'; recall_source: 'embedding' | 'keyword'; } // API 配置 export interface GetBijiConfig { apiKey: string; baseURL: string; timeout: number; rateLimitQPS: number; rateLimitDaily: number; defaultTopicId?: string; // 默认知识库ID } // 错误响应 export interface ErrorResponse { h: { c: number; e: string; }; }
- src/index.ts:79-128 (registration)Tool registration in the tools array: defines name, description, and inputSchema for listTools.{ name: 'knowledge_recall', description: '在Get笔记知识库中召回相关内容,返回未经AI处理的原始结果。可用于快速查找和预览。', inputSchema: { type: 'object', properties: { question: { type: 'string', description: '要搜索的问题', }, topic_id: { type: 'string', description: '知识库ID(单个)', }, topic_ids: { type: 'array', items: { type: 'string' }, description: '知识库ID列表(当前只支持1个)。注意:topic_id和topic_ids可都不提供,如果配置了GET_BIJI_DEFAULT_TOPIC_ID环境变量。优先使用topic_id', }, top_k: { type: 'number', description: '返回相似度最高的N个结果', default: 10, }, intent_rewrite: { type: 'boolean', description: '是否进行问题意图重写', default: false, }, select_matrix: { type: 'boolean', description: '是否对结果进行重选', default: false, }, history: { type: 'array', items: { type: 'object', properties: { content: { type: 'string' }, role: { type: 'string', enum: ['user', 'assistant'] }, }, required: ['content', 'role'], }, description: '对话历史,用于追问场景', }, }, required: ['question'], }, },
- src/client.ts:110-138 (helper)Client method implementing the API call to '/knowledge/search/recall' with rate limiting and error handling.async knowledgeRecall(params: KnowledgeRecallRequest): Promise<KnowledgeRecallResponse> { await this.rateLimiter.waitForSlot(); // 如果没有提供topic_id和topic_ids,但配置了默认topic_id,则使用默认值 if (!params.topic_id && (!params.topic_ids || params.topic_ids.length === 0)) { if (this.config.defaultTopicId) { params.topic_id = this.config.defaultTopicId; } else { throw new Error('topic_id or topic_ids is required, or set GET_BIJI_DEFAULT_TOPIC_ID in environment'); } } try { const response = await this.client.post<KnowledgeRecallResponse>( '/knowledge/search/recall', params ); if (response.data.h.c !== 0) { throw new Error(response.data.h.e || 'Unknown error'); } return response.data; } catch (error: any) { const errorMsg = error.response?.data?.h?.e || error.message; logger.error('Knowledge recall failed', { error: errorMsg, params }); throw new Error(`Knowledge recall failed: ${errorMsg}`); } }