Skip to content

feat: interactive retrieval citations with unified hover cards - #3654

Open
EDDIWARD wants to merge 13 commits into
developfrom
edward/feature-retrieval-citations-clean
Open

feat: interactive retrieval citations with unified hover cards#3654
EDDIWARD wants to merge 13 commits into
developfrom
edward/feature-retrieval-citations-clean

Conversation

@EDDIWARD

@EDDIWARD EDDIWARD commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

Summary

Interactive retrieval citations in both chat experiences.

  1. Render citation markers by the full source key (tool_sign + cite_index), preventing collisions between different retrieval tools.
  2. Hovering a citation marker shows a source card with the same layout as the right sources panel (title, index badge, summary, source label).
image
  1. Clicking a marker opens the right panel and selects + scrolls to the matching source card, in both /newchat and the legacy /chat page.

  2. Sentence-level highlight inside the retrieved Chunk is kept but gated behind ENABLE_CITATION_CLICK_HIGHLIGHT (frontend/const/citation.ts, default off). Flip the flag to true to re-enable it.

  3. Removed the citation write guard experiment entirely: the CitationWriteGuard tool, the agent-level "preserve citations in tool output" toggle (backend + frontend UI), and the related SQL migration.

Why

Users can see which retrieved source supports a statement directly from the marker (hover card), and jump to the matching source card (click) in both chat pages. The sentence-level Chunk highlight stays available behind a feature flag while its visual behavior is still being tuned.

Validation

  • Frontend tsc --noEmit type check passed (after merging latest develop).
  • Frontend production build passed.
  • Backend unit tests passed for the affected paths: test_core_agent (142), test_knowledge_base_search_tool (76), test_context_utils (27).
  • Verified locally in both chat pages with knowledge-base retrieval.

prompt suggestion

If the user wishes not to include citation tags in his/her tool content, he/she is recommended to utilize agentic level prompt as such:(using few-shot example) These prompt enables citation in normal conversations but not included in contents of tools (such as file writer).
image
image
Uploading image.png…

@codecov

codecov Bot commented Aug 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.31250% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ackend/services/conversation_management_service.py 50.00% 1 Missing and 1 partial ⚠️
sdk/nexent/vector_database/elasticsearch_core.py 93.33% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

…ions

- Remove the CitationWriteGuard tool and the agent-level 'preserve citations
  in tool output' toggle from backend, SDK, SQL migrations and frontend UI
- Show a source-card hover popover on citation markers in both chat pages
- Keep click-to-select source card working; gate sentence-level highlight
  behind ENABLE_CITATION_CLICK_HIGHLIGHT flag (default off)
…rieval-citations-clean

# Conflicts:
#	frontend/app/[locale]/newchat/ui/markdown-text.tsx
#	frontend/app/[locale]/newchat/ui/sources-panel.tsx
@EDDIWARD EDDIWARD changed the title feat: display retrieval citation highlights feat: interactive retrieval citations with unified hover cards Aug 18, 2026
- Extract shared highlight helpers (escapeRegExp, extractHighlightTerms, splitSourceTextIntoSentences) into frontend/lib/citationHighlight.ts, removing duplication between the /chat right panel and /newchat sources panel
- Add keyboard activation (Enter/Space, role=button, aria-label) to citation markers in markdownRenderer so interactive elements are accessible
- Consolidate the three duplicated search-result formatting loops in knowledge_base_search_tool.py into one _format_search_results helper
- Extend unit tests to cover score/highlight-term merging, no-mutation guarantees, and source_search persistence of retrieval highlight terms
- Extract CiteIndexBadge and HighlightedChunkText into components/common/highlightedSourceText.tsx, removing duplicated copies from the /chat right panel, /newchat sources panel, and cite marker
- Unify the three source-card variants in sources-panel around a shared SourceCardBody
- Split extractHighlightTerms into focused helpers to reduce cognitive complexity and share the term merge/dedupe pipeline via mergeHighlightTerms
- Use a native <button> for citation markers in markdownRenderer and flatten nested ternaries flagged by SonarCloud
- Replace escaped string regexes with String.raw / RegExp.exec in getCitedAnswerContext
@EDDIWARD
EDDIWARD marked this pull request as ready for review August 18, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant