Repository navigation
feat(platform): @-mention knowledge-base documents in chat - #1864
Conversation
Typing @ in the chat composer now opens a picker over RAG-indexed, team-accessible knowledge documents. Selected documents render as chips (the source of truth for the pin), travel as referencedDocumentIds on chatWithAgentTurn, are re-validated server-side (org, team access, active, indexed), and are appended to the saved message as the existing enriched fileId marker block so sent-bubble chips and the rag_search tool's fileId-priority behavior work unchanged. The per-turn auto-RAG query is forced on for pinned turns (explicit user intent overrides the agent's knowledgeMode), scoped to exactly the pinned fileIds, and run with a relaxed similarity threshold (0.3, the rag_search tool default). Backed by a new documents title-search strategy on the shared runEntitySearch seam (no services/rag changes — the existing /search file_ids filter does the scoping). Arena mode hides the trigger in v1. Failed sends restore the chips, mirroring the video-link rollback.
|
Warning Review limit reached
More reviews will be available in 27 minutes and 32 seconds. Learn how PR review limits work. Your organization has run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (29)
✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Billing warning: we have not been able to collect payment for this subscription for more than 72 hours. Please update the payment method or pay any pending invoices in Billing to avoid service interruption. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Closes #1337
What / why
There was no way to reference a specific knowledge-base document directly in chat — KB grounding was automatic-only (agent-scoped RAG) and the only manual path was attach-upload, which re-uploads and re-indexes a blob that is already in the knowledge base. This adds a Cursor-style
@-mention picker to the composer that pins specific indexed documents to a single turn.Flow:
@in the composer → anchored picker over RAG-indexed, team-accessible documents (title search) → selection adds a chip + inserts@Titleprose → on send the client passesreferencedDocumentIds(cap 5) →chatWithAgentTurnre-validates each reference synchronously (same org, active, team access, blob-backed,ragStatus === 'completed'; one opaqueKB_REF_INVALIDerror for all failure modes) → the resolved refs are appended to the saved user message as the existing enriched*(fileId: …)*marker block and the turn's auto-RAG query is scoped to exactly the pinned fileIds.Key pieces:
convex/lib/search/strategies/documents.ts— documents title-search strategy on the sharedrunEntitySearchseam (scan engine; flips to search-index with zero call-site changes when the bootstrap lands).convex/documents/search_documents_for_mention.ts+ public querysearchDocumentsForMention— bounded scan (≤5 slices × 50 rows), post-filtered to team-accessible + RAG-indexed docs, slim rows.chatWithAgentTurn→runChatTurnGeneration→startChat→startAgentChat:referencedFilesthreading;kb_reference_block.tsemits the marker block (byte-compatible withENRICHED_ATTACHMENT_MARKER, locked by a round-trip test against the client regexes), so sent-bubble chips and therag_searchtool's "prioritize fileIds found in the message" behavior work with zero new display plumbing.generate_response.ts:pinnedFileIdsforces knowledge-context injection, replaces the agent scope for the turn, and relaxes the similarity threshold to 0.3.useKbMentions(chips state + caret-based(^|\s)@(\S*)$trigger detection),KbMentionPopover(listbox, full keyboard nav viachat-input.tsx#handleKeyDown,aria-activedescendantcombobox pattern, IME-guarded), send-failure rollback mirroring the video-link chip pattern.No
services/ragchanges — the existing/api/v1/searchfile_idsfilter does the scoping.Decision-gate recommendations baked in (veto at review)
knowledgeModeisoff/tool(explicit user intent overrides admin agent config).@Titleprose does not drop the pin; remove the chip instead.@trigger hidden in v1 (referencedDocumentIdsnot wired througharena_chat).Merge-order note (#662 / #1517)
This PR makes no changes to
agent_tools/rag/rag_search_tool.tsor to the RAG service — the tool benefit comes for free from the marker block in the message text. #662/#1517 are changing that tool's parameter surface in parallel; per the plan's merge order, #1337 rebases last if anything overlaps (expected overlap: none).Deviations from the plan
KbMentionPopoveris purely presentational; theSearchSourcehook is consumed inchat-input.tsx(which owns keyboard nav state) instead of inside the popover — keeps Up/Down/Enter/Escape interception and the highlighted index in one place.fileMetadatadirectly (single pass also yieldsfileName/contentType/size) instead ofgetDocumentRagProjectionBatch; semantics identical (ragStatus === 'completed').chat.toast.kbRefInvalid(thechat.errors.*namespace the plan implied doesn't exist).Verification
Performed:
bun run checkat repo root — green (format, lint incl. type-aware oxlint, typecheck, 366 server/pii test files).test:uifull suite — 283 files / 2216 tests green (includes the newuse-kb-mentions,kb-mention-popovera11y, and marker round-trip tests).search_documents_for_mention.test.ts(access/indexed-only filtering, title fallback),use-kb-mentions.test.ts(trigger detection incl. email/mid-word non-triggers, cap/dedupe/rollback),start_agent_chat.test.ts(marker block on saved message,pinnedFileIdsin generation args, prewarm drops refs), KB-block round-trip lock inuse-message-processing.test.tsagainst the client regexes.bun run --filter @tale/docs lint && test— green (locale/structure parity for the new docs section).Manual verification required (needs the running local stack with a live RAG deployment — not performed here):
knowledgeContextResult.citations).knowledgeMode: 'off'still injects pinned context.isComposingRefguards).Pre-PR checklist
bun run check(format, lint, typecheck, all tests).h-[…]on skeletons — N/A (no loading states added).services/platform/messages/{en,de,fr}.json(composer.kbMention.*,chat.toast.kbRefInvalid; de-CH carries no override)./docs/{en,de,fr}/platform/chat/attachments.md("Referencing knowledge documents with @" section).bun run --filter @tale/docs lintandbun run --filter @tale/docs test.