find_related
Discover semantically related documents in Outline wiki to expand research, find connections, and gather context for any document.
Instructions
Find documents semantically related to a specific document.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| documentId | Yes | ||
| limit | No |
Implementation Reference
- src/lib/handlers/smart.ts:159-188 (handler)The handler function that implements the find_related tool logic: fetches the target document, performs a semantic search using brain.search on its title and initial text, filters out the source document, and returns a list of related documents with titles, URLs, and excerpts.async find_related(args: { documentId: string; limit?: number }) { if (!brain.isEnabled()) { return { error: ERROR_MESSAGES.SMART_FEATURES_DISABLED }; } // Fetch document const { data } = await apiCall(() => apiClient.post<OutlineDocument>('/documents.info', { id: args.documentId }) ); if (!data.text) { return { error: ERROR_MESSAGES.NO_CONTENT_TO_ANALYZE }; } // Search for similar documents const results = await brain.search(data.title + ' ' + data.text.substring(0, 500), args.limit || 5); // Filter out the source document const related = results.filter((r) => !r.id.startsWith(args.documentId)); return { documentId: data.id, title: data.title, related: related.map((r) => ({ title: r.title, url: r.url, excerpt: r.text.substring(0, 200) + '...', })), }; },
- src/lib/schemas.ts:159-162 (schema)Zod schema definition for the find_related tool input: requires documentId and optional limit (default 5).export const findRelatedSchema = z.object({ documentId, limit: limit.default(5).optional(), });
- src/lib/tools.ts:220-224 (registration)Registration of the find_related tool in the allTools array using createTool, providing name, description, and schema reference.createTool( 'find_related', 'Find documents semantically related to a specific document.', 'find_related' ),
- src/lib/schemas.ts:248-248 (registration)Mapping of 'find_related' to its schema in the central toolSchemas record used for tool definitions.find_related: findRelatedSchema,
- src/lib/schemas.ts:204-204 (schema)TypeScript type definition for find_related input inferred from the Zod schema.export type FindRelatedInput = z.infer<typeof findRelatedSchema>;