Skip to content

feat(llm): add knowledge base mode for source-grounded conversations#9343

Draft
Kureii wants to merge 2 commits intoTriliumNext:mainfrom
Kureii:feat/llm-knowledge-base
Draft

feat(llm): add knowledge base mode for source-grounded conversations#9343
Kureii wants to merge 2 commits intoTriliumNext:mainfrom
Kureii:feat/llm-knowledge-base

Conversation

@Kureii
Copy link
Copy Markdown
Contributor

@Kureii Kureii commented Apr 8, 2026

Summary

Add a Knowledge Base feature that allows users to select specific notes as context sources for LLM conversations. The AI uses these notes as primary reference material with Harvard-style numbered citations.

Changes

  • KB panel: Note autocomplete with chip display in ChatInputBar
  • System prompt: buildKnowledgeBaseSources() injects extended content previews (up to 1500 chars per note) with numbered reference lists
  • Citation format: Harvard-style [1], [2] with a ## References section linking back to notes via [[noteId]]
  • Note tools automatically enabled when KB sources are selected
  • sourceNoteIds persisted in chat content and restored on load
  • Documentation page added

Files (9 files, +392/-8)

  • apps/server/src/services/llm/providers/base_provider.ts - KB system prompt + tool enablement
  • apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts - sourceNoteIds state + persistence
  • apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.tsx - KB panel UI
  • apps/client/src/widgets/type_widgets/llm_chat/ChatInputBar.css - KB styling
  • apps/client/src/widgets/type_widgets/llm_chat/llm_chat_types.ts - sourceNoteIds field
  • apps/client/src/services/note_autocomplete.ts - closeOnBlur option
  • packages/commons/src/lib/llm_api.ts - sourceNoteIds on config
  • apps/client/src/translations/en/translation.json - KB translation keys
  • docs/.../AI/Knowledge Base.html - New: Documentation page

Add a Knowledge Base feature that allows users to select specific notes
as context sources for LLM conversations. The AI uses these notes as
primary reference material, providing Harvard-style citations.

- Add KB panel in ChatInputBar with note autocomplete and chip display
- Add buildKnowledgeBaseSources() for extended content previews
- Enable note tools automatically when KB sources are selected
- Add sourceNoteIds to chat config and state persistence
- Add KB documentation page and translation keys
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Apr 8, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a 'Knowledge Base' feature for the AI chat, allowing users to select specific notes as sources for AI responses. The changes include UI components for managing these sources, backend logic to incorporate note previews and metadata into the system prompt, and necessary type definitions. I have provided feedback regarding the use of !important in CSS and suggested simplifying the logic for generating content previews in the backend.

Build extended preview directly from note content instead of calling
getContentPreview() first and then re-fetching for longer preview.
Removes unused getContentPreview import.
Copy link
Copy Markdown
Contributor

@eliandoran eliandoran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Toggling "Knowledge base" on or off completely wipes the source note IDs. Is this intended?
  • The references could use a UI/UX improvement. I would suggest taking inspiration from the already existing sources indicator that appears for web searches. Make sure not to create too much duplication.
  • The contrast of the "Knowledge base sources" on the dark theme is not that great.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many changes to an already big file, extract to a separate component with its own stylesheet.

@eliandoran eliandoran marked this pull request as draft April 11, 2026 22:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-conflicts size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants