Repository navigation
Add docs chat #3749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
Draft
Add docs chat #3749
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
c7b063c
Add docs RAG ingestion pipeline for Meilisearch
Strift 4e3ca9e
Add custom Ask AI chat widget (Vite bundle, AI SDK, Meilisearch)
Strift a437430
Add expand_page chat tool and make chunks lossless
Strift 7f5b8f6
checkpoint before checking out main
Strift c787718
update prompt
Strift 0d9aea4
Widen the Ask AI panel and list each source page once.
Strift ddc46af
Send the reader's code-sample language with each chat request.
Strift b8f962d
Index API routes and mounted code samples so chat can answer with req…
Strift ee7c404
Style Ask AI code samples to match the documentation code groups.
Strift 525d003
Always load the docs chat and read its settings from environment vari…
Strift 1db24b0
Load each docs preview's chat from that branch's Vercel deployment.
Strift 0ab2e23
Load the chat from the local dev server when previewing docs on local…
Strift fa9be89
Import the compiled samples module so the chat function can start on …
Strift b94f06b
Make the Ask AI panel push the docs column aside so the page stays re…
Strift 6e6caab
Let the docs chat find API routes by SDK method name and rerank a wid…
Strift 0b1dc30
Log a federated chat trace so search latency and relevancy can be tuned.
Strift 2d48fef
Match the Ask Meilisearch header to the docs navbar.
Strift 2826d06
Cap the docs chat at two searches and run it in London so answers sta…
Strift becf6e4
Pin the docs chat to OpenAI so follow-ups can decrypt prior reasoning.
Strift d4c2c68
Raise the docs chat reasoning effort to medium.
Strift 7c5bd61
Index changelog releases separately so the docs chat can cite when a …
Strift badb9b9
Show only the pages an answer cites, ranked by the final rerank score.
Strift 740f5d2
Let the docs chat answer release-window questions from changelog dates.
Strift 9c95c52
Remove the unused model latency benchmark script.
Strift 9217ff9
Derive chat links from page paths so they stay on the reader's domain.
Strift 8ad3fef
Catch .ts import specifiers in chat/ with oxlint.
Strift 2f1f52c
Split the docs chat into an agent, a widget, and shared helpers.
Strift 485ba97
Test the docs chat and ingestion through one Vitest runner.
Strift 5193b41
Select the sink tests as a Vitest project instead of a second config.
Strift 3f740f6
Revert Node bumps in unrelated workflows and rename the test workflow.
Strift 2f71486
Route docs chat questions through a guardrail router before answering.
Strift 9fa25ad
Filter the chat tests by path and move the test notes into CONTRIBUTING.
Strift 022f2d6
Trace each docs chat answer in PostHog and log feedback clicks.
cursoragent 431fc14
Keep chat traces and conversation ids intact when a step fails.
cursoragent cdcdb9d
Add on-demand evals so docs chat retrieval and answers can be scored …
Strift a5de42b
Score docs chat answers by the fact they state, and keep each eval re…
Strift 04c62e7
Improve docs chat prompts, tools, and evals to reach 41/41 passing.
Strift 62ffbcd
Space docs chat replies like the rest of the page.
Strift 2c01154
Send docs chat click events without PostHog identity
Strift 99b4ef7
Send docs chat thumbs as PostHog survey responses so they show on AI …
Strift bbe581c
Call OpenAI directly for the docs chat and use one env var naming sch…
Strift b6c3346
Make the docs chat reranking model configurable and group .env exampl…
Strift 2aa99b7
Fix truncated chat code blocks and steer HTTP examples to cURL route …
Strift ee052d2
Optimize docs chat prompt caching and support code language overrides
Strift 70f163a
Align chat UI tokens, collapse tool steps, and add API source breadcr…
Strift File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| # Meilisearch (indexing) | ||
| MEILISEARCH_URL=https://ms-909f535664f8-173.lon.meilisearch.io | ||
| MEILISEARCH_ADMIN_KEY= | ||
| MEILISEARCH_DOCS_INDEX=docs-chunks | ||
| MEILISEARCH_ROUTES_INDEX=api-routes | ||
| MEILISEARCH_CHANGELOG_INDEX=changelog-chunks | ||
| MEILISEARCH_EMBEDDER=voyage | ||
|
|
||
| # Voyage (embedding, reranking in evals) | ||
| VOYAGE_API_KEY= | ||
|
|
||
| # OpenAI API key (completion in evals, embedding in search staging) | ||
| OPENAI_API_KEY= | ||
|
|
||
| # AI assistant models (evals) | ||
| CHAT_MODEL=gpt-6-luna | ||
| CHAT_RERANKING_MODEL=rerank-3 | ||
|
|
||
| # Meilisearch (search in evals, falls back to MEILISEARCH_ADMIN_KEY) | ||
| MEILISEARCH_SEARCH_KEY= | ||
|
|
||
| # Meilisearch (Mintlify search staging) | ||
| MEILISEARCH_HOST_URL=https://ms-909f535664f8-173.lon.meilisearch.io | ||
| MEILISEARCH_API_KEY= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # Keeps the docs chat indexes in sync. Sync state lives in Meilisearch, so unchanged pages are skipped. | ||
| name: Ingest chat indexes | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| inputs: | ||
| force: | ||
| description: Re-sync every page, even unchanged ones | ||
| type: boolean | ||
| default: false | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| jobs: | ||
| ingest: | ||
| name: Ingest docs into Meilisearch | ||
| if: github.repository == 'meilisearch/documentation' | ||
| runs-on: ubuntu-latest | ||
| concurrency: | ||
| group: ingest | ||
| cancel-in-progress: false | ||
| steps: | ||
| - uses: actions/checkout@v6 | ||
|
|
||
| # `--env-file-if-exists` in the ingest script needs Node.js 22. | ||
| - uses: actions/setup-node@v7 | ||
| with: | ||
| node-version: "22" | ||
| cache: "npm" | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci | ||
|
|
||
| - name: Ingest | ||
| run: npm run ingest -- ${{ github.event_name == 'workflow_dispatch' && inputs.force && '--force' || '' }} | ||
| env: | ||
| MEILISEARCH_URL: ${{ vars.MEILISEARCH_URL }} | ||
| MEILISEARCH_ADMIN_KEY: ${{ secrets.MEILISEARCH_ADMIN_KEY }} | ||
| VOYAGE_API_KEY: ${{ secrets.VOYAGE_API_KEY }} | ||
| MEILISEARCH_DOCS_INDEX: ${{ vars.MEILISEARCH_DOCS_INDEX }} | ||
| MEILISEARCH_ROUTES_INDEX: ${{ vars.MEILISEARCH_ROUTES_INDEX }} | ||
| MEILISEARCH_CHANGELOG_INDEX: ${{ vars.MEILISEARCH_CHANGELOG_INDEX }} | ||
| MEILISEARCH_EMBEDDER: ${{ vars.MEILISEARCH_EMBEDDER }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| name: Test the docs chat | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "chat/**" | ||
| - "scripts/ingest/**" | ||
| - "config/navigation.json" | ||
| - "assets/release-assets/**" | ||
| - "package.json" | ||
| - "package-lock.json" | ||
| - "vitest.config.ts" | ||
| - ".oxlintrc.json" | ||
| - ".github/workflows/test-chat.yml" | ||
|
|
||
| jobs: | ||
| lint: | ||
| name: Lint and typecheck | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v7 | ||
| with: | ||
| node-version: "22" | ||
| cache: npm | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| npm ci | ||
| npm ci --prefix chat | ||
|
|
||
| - name: Lint | ||
| run: npm run lint | ||
|
|
||
| - name: Typecheck | ||
| run: npm run typecheck | ||
|
|
||
| ingest: | ||
| name: Test ingestion | ||
| runs-on: ubuntu-latest | ||
| services: | ||
| meilisearch: | ||
| image: getmeili/meilisearch:v1.58 | ||
| ports: | ||
| - 7700:7700 | ||
| env: | ||
| MEILI_ENV: development | ||
| MEILI_MASTER_KEY: masterKey | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v7 | ||
| with: | ||
| node-version: "22" | ||
| cache: npm | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| npm ci | ||
| npm ci --prefix chat | ||
|
|
||
| - name: Wait for Meilisearch | ||
| run: | | ||
| for _ in $(seq 1 30); do | ||
| curl -sf http://localhost:7700/health && exit 0 | ||
| sleep 1 | ||
| done | ||
| echo "Meilisearch did not become healthy" >&2 | ||
| exit 1 | ||
|
|
||
| - name: Unit tests | ||
| run: npm run ingest:test | ||
|
|
||
| - name: Integration tests | ||
| run: npm run ingest:integration | ||
| env: | ||
| MEILI_TEST_URL: http://localhost:7700 | ||
| MEILI_TEST_KEY: masterKey | ||
|
|
||
| chat: | ||
| name: Test chat | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - uses: actions/setup-node@v7 | ||
| with: | ||
| node-version: "22" | ||
| cache: npm | ||
|
|
||
| - name: Install dependencies | ||
| run: | | ||
| npm ci | ||
| npm ci --prefix chat | ||
|
|
||
| - name: Unit tests | ||
| run: npm run chat:test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| # Agent instruction files are not documentation pages. | ||
| **/AGENTS.md | ||
| chat/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| { | ||
| "$schema": "./node_modules/oxlint/configuration_schema.json", | ||
| "ignorePatterns": [ | ||
| "node_modules", | ||
| "chat/dist", | ||
| "chat/.vercel", | ||
| "snippets", | ||
| "assets/release-assets" | ||
| ], | ||
| "overrides": [ | ||
| { | ||
| // Only chat/ is bundled by Vite | ||
| "files": [ | ||
| "chat/**/*.ts", | ||
| "chat/**/*.tsx" | ||
| ], | ||
| "excludeFiles": [ | ||
| "chat/**/__tests__/**" | ||
| ], | ||
| "rules": { | ||
| "no-restricted-imports": [ | ||
| "error", | ||
| { | ||
| "patterns": [ | ||
| { | ||
| // Vite compiles api/*.ts to *.js but copies relative specifiers | ||
| // verbatim, so a .ts import ships a function that crashes at startup | ||
| // with ERR_MODULE_NOT_FOUND. chat/tsconfig.json sets | ||
| // allowImportingTsExtensions and Vite resolves .ts in dev, so this | ||
| // only shows up in production. | ||
| "group": [ | ||
| "**/*.ts", | ||
| "**/*.tsx", | ||
| "**/*.mts", | ||
| "**/*.cts" | ||
| ], | ||
| "message": "Import the .js specifier instead. Vercel compiles chat/ to JavaScript and keeps the specifier verbatim, so a .ts import crashes the deployed function with ERR_MODULE_NOT_FOUND." | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| // Loads the "Ask AI" chat widget (source in /chat, built with Vite and hosted on Vercel). | ||
| // Mintlify serves this file on every page; the widget itself is not part of the docs build. | ||
| // | ||
| // Mintlify cannot read Vercel's env vars. A preview hostname already ends with the branch | ||
| // slug Vercel puts in VERCEL_BRANCH_URL: | ||
| // meilisearch-6b28dec2-<branch>.mintlify.site | ||
| // -> documentation-chat-git-<branch>-meili.vercel.app | ||
| // The bundle then calls the API on the origin baked in from that env var. | ||
|
|
||
| const MEILI_CHAT_PROD_URL = 'https://documentation-chat.vercel.app' | ||
| // Used only when `npm run dev` is running in chat/. 127.0.0.1 avoids an IPv6-only bind. | ||
| const MEILI_CHAT_DEV_URL = 'http://127.0.0.1:5173' | ||
| const MINTLIFY_PREVIEW = /^meilisearch-6b28dec2-(.+)\.mintlify\.site$/ | ||
| // DNS labels are at most 63 characters. Vercel truncates the branch alias to fit. | ||
| const BRANCH_PREFIX = 'documentation-chat-git-' | ||
| const BRANCH_SUFFIX = '-meili' | ||
|
|
||
| function branchChatUrl(hostname) { | ||
| const match = hostname.match(MINTLIFY_PREVIEW) | ||
| if (!match || !/^[a-z0-9-]+$/.test(match[1])) return '' | ||
| const room = 63 - BRANCH_PREFIX.length - BRANCH_SUFFIX.length | ||
| const branch = match[1].slice(0, room).replace(/-+$/, '') | ||
| if (!branch) return '' | ||
| return `https://${BRANCH_PREFIX}${branch}${BRANCH_SUFFIX}.vercel.app` | ||
| } | ||
|
|
||
| function loadMeilisearchChat() { | ||
| if (window.__meiliChatLoaded) { | ||
| return | ||
| } | ||
|
|
||
| const { hostname } = window.location | ||
| const isLocal = hostname === 'localhost' || hostname === '127.0.0.1' | ||
| // Local docs always use the chat dev server (`npm run dev` in chat/). | ||
| const base = (isLocal ? MEILI_CHAT_DEV_URL : branchChatUrl(hostname) || MEILI_CHAT_PROD_URL).replace(/\/$/, '') | ||
| window.__meiliChatLoaded = true | ||
|
|
||
| const script = document.createElement('script') | ||
| script.src = `${base}/chat.js` | ||
| script.async = true | ||
| script.onload = () => window.MeiliChat && window.MeiliChat.mount({ apiBase: base }) | ||
| script.onerror = () => { | ||
| window.__meiliChatLoaded = false | ||
| console.warn('Meilisearch chat widget failed to load from', script.src) | ||
| } | ||
| document.head.appendChild(script) | ||
| } | ||
|
|
||
| if (document.readyState === 'loading') { | ||
| document.addEventListener('DOMContentLoaded', loadMeilisearchChat) | ||
| } else { | ||
| loadMeilisearchChat() | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| # OpenAI API key (completion) | ||
| OPENAI_API_KEY= | ||
|
|
||
| # AI assistant models | ||
| CHAT_MODEL=gpt-6-luna | ||
| CHAT_RERANKING_MODEL=rerank-3 | ||
|
|
||
| # Meilisearch (search) | ||
| MEILISEARCH_URL=https://ms-909f535664f8-173.lon.meilisearch.io | ||
| MEILISEARCH_SEARCH_KEY= | ||
| MEILISEARCH_DOCS_INDEX=docs-chunks | ||
| MEILISEARCH_ROUTES_INDEX=api-routes | ||
| MEILISEARCH_CHANGELOG_INDEX=changelog-chunks | ||
| MEILISEARCH_EMBEDDER=voyage | ||
|
|
||
| # Voyage (reranking) | ||
| VOYAGE_API_KEY= | ||
|
|
||
| # Chat API (CORS) | ||
| CHAT_ALLOWED_ORIGINS=meilisearch.com,*.meilisearch.com,*.mintlify.site | ||
|
|
||
| # PostHog (analytics, optional) | ||
| POSTHOG_PROJECT_TOKEN= | ||
| POSTHOG_HOST=https://eu.i.posthog.com | ||
| POSTHOG_FEEDBACK_SURVEY_ID= | ||
| POSTHOG_FEEDBACK_QUESTION_ID= |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.