delete_documents
Remove documents from your local PocketMCP knowledge base by specifying document IDs or external identifiers. Clean up SQLite vector storage to maintain accurate semantic search results and optimize offline database performance.
Instructions
Delete documents by ID or external ID
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| doc_ids | No | Document IDs to delete | |
| external_ids | No | External IDs to delete |
Implementation Reference
- src/server.ts:381-400 (handler)The handleDeleteDocuments function is the main handler that validates arguments (doc_ids or external_ids required) and calls ingestManager.deleteDocuments(). Returns JSON with deleted_doc_ids and deleted_chunks.
async function handleDeleteDocuments(args: any, ingestManager: IngestManager): Promise<any> { const { doc_ids, external_ids } = args; if (!doc_ids && !external_ids) { throw new McpError(ErrorCode.InvalidParams, 'Either doc_ids or external_ids must be provided'); } const result = await ingestManager.deleteDocuments(doc_ids, external_ids); return { content: [ { type: 'text', text: JSON.stringify({ deleted_doc_ids: result.deletedDocIds, deleted_chunks: result.deletedChunks, }, null, 2), }, ], }; - src/server.ts:195-213 (schema)The input schema definition for delete_documents tool. Defines two optional properties: doc_ids (array of strings) and external_ids (array of strings) for specifying which documents to delete.
{ name: 'delete_documents', description: 'Delete documents by ID or external ID', inputSchema: { type: 'object', properties: { doc_ids: { type: 'array', items: { type: 'string' }, description: 'Document IDs to delete', }, external_ids: { type: 'array', items: { type: 'string' }, description: 'External IDs to delete', }, }, }, }, - src/ingest.ts:278-312 (helper)The IngestManager.deleteDocuments() method that performs the actual deletion. Handles both external ID-based deletion and doc ID-based deletion. Iterates through IDs, fetches documents, deletes them via database, and returns aggregated results.
async deleteDocuments(docIds?: string[], externalIds?: string[]): Promise<{ deletedDocIds: string[]; deletedChunks: number; }> { const deletedDocIds: string[] = []; let totalDeletedChunks = 0; // Handle deletion by external IDs if (externalIds && externalIds.length > 0) { for (const externalId of externalIds) { const doc = this.db.getDocumentByExternalId(externalId); if (doc) { const result = this.db.deleteDocument(doc.doc_id); deletedDocIds.push(doc.doc_id); totalDeletedChunks += result.deletedChunks; } } } // Handle deletion by doc IDs if (docIds && docIds.length > 0) { for (const docId of docIds) { const result = this.db.deleteDocument(docId); if (result.deletedChunks > 0) { deletedDocIds.push(docId); totalDeletedChunks += result.deletedChunks; } } } return { deletedDocIds, deletedChunks: totalDeletedChunks }; } - src/server.ts:251-252 (registration)The switch case in the tool call handler that routes 'delete_documents' tool calls to the handleDeleteDocuments function.
case 'delete_documents': return await handleDeleteDocuments(args, ingestManager);