mirror of
https://github.com/logancyang/obsidian-copilot.git
synced 2026-07-22 07:50:24 +00:00
- Renamed docs/ to designdocs/ - Moved draft/todo docs into designdocs/todo/ subfolder - Added OBSIDIAN_CLI_INTEGRATION.md from master's todo/ folder - Updated all docs/ path references in CLAUDE.md, AGENTS.md, and designdocs Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
4.1 KiB
4.1 KiB
Inline Citation System
This guide explains how inline citations are produced across Copilot Plus, Vault QA, and web search, and how the feature is exercised by automated tests.
Feature Toggle & Surface Area
enableInlineCitations(defaulttrue) lives insrc/settings/model.tsand is exposed in the QA settings UI (src/settings/v2/components/QASettings.tsx).- The toggle gates prompt instructions, fallback post-processing, and chat rendering. When disabled the system falls back to a collapsible sources list without inline markers.
Pipeline Overview
- Retrieval Conditioning
- Both
CopilotPlusChainRunner.prepareLocalSearchResultandVaultQAChainRunnersanitize note content withsanitizeContentForCitationsto strip stray[^n]/[n]markers before prompting. - Retrieved notes receive stable
__sourceIdvalues and are serialized withformatSearchResultsForLLM;deduplicateSourceskeeps the highest-scoring entry per path/title. - A compact source catalog is built via
formatSourceCatalog, and Copilot Plus caches the first 20 entries inlastCitationSourcesfor fallback footnotes.
- Both
- Prompt Assembly
CITATION_RULESandWEB_CITATION_RULESlive insrc/LLMProviders/chainRunner/utils/citationUtils.ts.getCitationInstructions(Copilot Plus) andgetQACitationInstructionsConditional(Vault QA) append guidance and a source catalog only when inline citations are enabled.- Web search calls
getWebSearchCitationInstructionsso external sources emit[title](url)definitions while vault answers stay on[[Note]]links.
- Response Safeguards
addFallbackSourcesappends a#### Sourcesblock when the model produced inline markers but no definitions. Detection relies onhasExistingCitations, which now accepts alternate headings (e.g.,## Sources,Sources -) and<summary>Sources</summary>blocks.- Copilot Plus passes structured
lastCitationSourcesinto the fallback helper; Vault QA derives titles from the retriever output.
- Chat Rendering
src/components/chat-components/ChatSingleMessage.tsxalways pipes assistant messages throughprocessInlineCitations.- The helper extracts the trailing sources section, builds a first-mention map with
buildCitationMap, normalizes references (normalizeCitations) so constructs like[^7][^8]become[1][2], and converts definitions (convertFootnoteDefinitions) into clickable wiki links or Markdown anchors. - Duplicate definitions collapse via
consolidateDuplicateSources+updateCitationsForConsolidation, keeping numbering stable. When the sources block is not footnote formatted or citations are disabled, the renderer falls back to a simple<details>list.
Testing
src/LLMProviders/chainRunner/utils/citationUtils.test.ts- Sanitization, catalog formatting, and fallback insertion.
hasExistingCitationscoverage for markdown headings, plainSourceslabels, and<summary>wrappers.- Regression suites for non-sequential citations, duplicate source consolidation, and consecutive markers (
[^7][^8]).
src/LLMProviders/chainRunner/utils/searchResultUtils.test.ts- Ensures retrieved documents are serialized with stable IDs and filtered for
includeInContextbefore prompting.
- Ensures retrieved documents are serialized with stable IDs and filtered for
src/tools/ToolResultFormatter.test.ts- Verifies the local search tool emits JSON with the
{ type: "local_search", documents: [...] }shape expected by the chain runners.
- Verifies the local search tool emits JSON with the
Manual QA Checklist
- Vault QA turn using only local search: confirm inline
[1]markers and numbered sources render without duplication. - Mixed Copilot Plus turn (local search + another tool): ensure fallback still works if the model omits the sources block.
- Web search answer: verify footnote definitions render as
[title](url)links when citations are enabled.
Watchlist
sanitizeContentForCitationsintentionally strips bracketed numbers; keep an eye on domains (math, law) where literal[1990]values might be desirable.- Inline citations remain model-dependent.
addFallbackSourcesguarantees a sources list, but the UI still reflects whatever inline markers the provider returns.