Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(llm): add Perplexity as a search provider
Elian Dorancf45c2bb2999
diff --git a/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx b/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsxindex 37af5c5434..87c1a9f6c0 100644--- a/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx+++ b/apps/client/src/widgets/type_widgets/options/llm/AddProviderModal.tsx@@ -168,6 +168,7 @@ export const SEARCH_PROVIDER_TYPES: ProviderType[] = [{ id: "tavily", name: "Tavily", group: "search-cloud", defaultBaseUrl: "https://api.tavily.com", iconUrl: PROVIDER_ICONS.tavily },{ id: "exa", name: "Exa", group: "search-cloud", defaultBaseUrl: "https://api.exa.ai", iconUrl: PROVIDER_ICONS.exa },{ id: "serper", name: "Serper", group: "search-cloud", defaultBaseUrl: "https://google.serper.dev", iconUrl: PROVIDER_ICONS.serper },+ { id: "perplexity", name: "Perplexity", group: "search-cloud", defaultBaseUrl: "https://api.perplexity.ai", iconUrl: PROVIDER_ICONS.perplexity },{id: "searxng", name: "SearXNG", group: "search-local", defaultBaseUrl: "http://localhost:8888", prefillBaseUrl: true,iconUrl: PROVIDER_ICONS.searxng,diff --git a/apps/client/src/widgets/type_widgets/options/llm/icons/perplexity.svg b/apps/client/src/widgets/type_widgets/options/llm/icons/perplexity.svgnew file mode 100644index 0000000000..f7c917ca5c--- /dev/null+++ b/apps/client/src/widgets/type_widgets/options/llm/icons/perplexity.svg@@ -0,0 +1 @@+<svg fill="currentColor" fill-rule="evenodd" height="1em" style="flex:none;line-height:1" viewBox="0 0 24 24" width="1em" xmlns="http://www.w3.org/2000/svg"><title>Perplexity</title><path d="M19.785 0v7.272H22.5V17.62h-2.935V24l-7.037-6.194v6.145h-1.091v-6.152L4.392 24v-6.465H1.5V7.188h2.884V0l7.053 6.494V.19h1.09v6.49L19.786 0zm-7.257 9.044v7.319l5.946 5.234V14.44l-5.946-5.397zm-1.099-.08l-5.946 5.398v7.235l5.946-5.234V8.965zm8.136 7.58h1.844V8.349H13.46l6.105 5.54v2.655zm-8.982-8.28H2.59v8.195h1.8v-2.576l6.192-5.62zM5.475 2.476v4.71h5.115l-5.115-4.71zm13.219 0l-5.115 4.71h5.115v-4.71z"></path></svg>\ No newline at end of filediff --git a/apps/client/src/widgets/type_widgets/options/llm/provider_icons.ts b/apps/client/src/widgets/type_widgets/options/llm/provider_icons.tsindex 92f5389f3b..507a3df1bd 100644--- a/apps/client/src/widgets/type_widgets/options/llm/provider_icons.ts+++ b/apps/client/src/widgets/type_widgets/options/llm/provider_icons.ts@@ -23,6 +23,7 @@ import githubCopilotIcon from "./icons/github-copilot.svg?url";import lmStudioIcon from "./icons/lmstudio.svg?url";import ollamaIcon from "./icons/ollama.svg?url";import openaiIcon from "./icons/openai.svg?url";+import perplexityIcon from "./icons/perplexity.svg?url";import openAiCompatibleIcon from "./icons/robot.svg?url";import searchIcon from "./icons/search.svg?url";import searxngIcon from "./icons/searxng.svg?url";@@ -42,6 +43,7 @@ export const PROVIDER_ICONS: Record<string, string> = {ollama: ollamaIcon,openai: openaiIcon,"openai-compatible": openAiCompatibleIcon,+ perplexity: perplexityIcon,searxng: searxngIcon,serper: searchIcon,tavily: tavilyIcondiff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.htmlindex e7d272eec3..5ef29483f2 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI.html@@ -122,10 +122,10 @@models have one, as do Claude Code, Google Antigravity and OpenAI Codex.DeepSeek, Ollama, LM Studio and custom endpoints don't, so this choiceis disabled for their models.</li>- <li>A search provider (Brave Search, Tavily, Exa, Serper or SearXNG) searches- through that service instead, whichever model is answering. Search providers- are added in the <em>Search Providers</em> section of the AI settings, which- the <span class="tn-icon bx bx-cog"></span> button beside the <em>Web search</em> heading+ <li>A search provider (Brave Search, Tavily, Exa, Serper, Perplexity or SearXNG)+ searches through that service instead, whichever model is answering. Search+ providers are added in the <em>Search Providers</em> section of the AI settings,+ which the <span class="tn-icon bx bx-cog"></span> button beside the <em>Web search</em> headingin the menu opens.</li></ul><p>Whether web search is on is kept per chat; the search source is shareddiff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Privacy.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Privacy.htmlindex d8a4548317..11de033373 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Privacy.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/AI/Privacy.html@@ -76,8 +76,8 @@makes that note fetchable.</li><li><strong>Your search query</strong>, when web search is enabled, the model'ssearch terms reach the provider's own search infrastructure, or the search- provider chosen in the <em>Tools</em> menu (Brave Search, Tavily, Exa, Serper- or your SearXNG instance).</li>+ provider chosen in the <em>Tools</em> menu (Brave Search, Tavily, Exa, Serper,+ Perplexity or your SearXNG instance).</li><li><strong>The pages the model reads</strong>, when web search goes througha search provider: Trilium fetches each page the model asks for from thesite itself, so the site sees a request from the machine running Trilium.diff --git a/docs/User Guide/User Guide/AI.md b/docs/User Guide/User Guide/AI.mdindex f82bab4f8f..12058d0bb6 100644--- a/docs/User Guide/User Guide/AI.md+++ b/docs/User Guide/User Guide/AI.md@@ -89,7 +89,7 @@ Where the search comes from is chosen under _Web search_ in the <span class="tn-* _Disabled_ turns web search off for this chat.* _Use the model's built-in search_, the default, lets the model search with its provider's own search. Anthropic, OpenAI and Google Gemini models have one, as do Claude Code, Google Antigravity and OpenAI Codex. DeepSeek, Ollama, LM Studio and custom endpoints don't, so this choice is disabled for their models.-* A search provider (Brave Search, Tavily, Exa, Serper or SearXNG) searches through that service instead, whichever model is answering. Search providers are added in the _Search Providers_ section of the AI settings, which the <span class="tn-icon bx bx-cog"></span> button beside the _Web search_ heading in the menu opens.+* A search provider (Brave Search, Tavily, Exa, Serper, Perplexity or SearXNG) searches through that service instead, whichever model is answering. Search providers are added in the _Search Providers_ section of the AI settings, which the <span class="tn-icon bx bx-cog"></span> button beside the _Web search_ heading in the menu opens.Whether web search is on is kept per chat; the search source is shared by all chats. A choice the current model can't use stays in the menu, disabled; hover the <span class="tn-icon bx bx-info-circle"></span> icon next to it to see why. Claude Code, GitHub Copilot, Google Antigravity and OpenAI Codex run their own tools, so they can't use a search provider.diff --git a/docs/User Guide/User Guide/AI/Privacy.md b/docs/User Guide/User Guide/AI/Privacy.mdindex 3cdcd0f880..3216c060c2 100644--- a/docs/User Guide/User Guide/AI/Privacy.md+++ b/docs/User Guide/User Guide/AI/Privacy.md@@ -30,7 +30,7 @@ This is the reason the provider list is grouped this way, and why Trilium pre-se* Tools let the model search your tree and read notes, attributes and attachments beyond the current one.* It decides what to fetch; there is no per-note permission system, so the reachable scope is your whole tree.* **Attachments and mentions**, when you add them: images, PDFs and text files are sent to the provider, and an `@` mention makes that note fetchable.-* **Your search query**, when web search is enabled, the model's search terms reach the provider's own search infrastructure, or the search provider chosen in the _Tools_ menu (Brave Search, Tavily, Exa, Serper or your SearXNG instance).+* **Your search query**, when web search is enabled, the model's search terms reach the provider's own search infrastructure, or the search provider chosen in the _Tools_ menu (Brave Search, Tavily, Exa, Serper, Perplexity or your SearXNG instance).* **The pages the model reads**, when web search goes through a search provider: Trilium fetches each page the model asks for from the site itself, so the site sees a request from the machine running Trilium. The page's text is then sent to the model's provider.## The in-editor AI assistantdiff --git a/packages/trilium-core/src/services/llm/web_search.spec.ts b/packages/trilium-core/src/services/llm/web_search.spec.tsindex e90f4e7675..67aa49bbfa 100644--- a/packages/trilium-core/src/services/llm/web_search.spec.ts+++ b/packages/trilium-core/src/services/llm/web_search.spec.ts@@ -74,6 +74,18 @@ describe("searchWeb", () => {expect(sources).toEqual([ { ...PAGE, snippet: "From Google" } ]);});+ it("posts to Perplexity's Search API with its key and reads its snippets", async () => {+ respond({ id: "r1", results: [ { ...PAGE, snippet: "From Perplexity", date: "2026-10-01" } ] });+ const sources = await searchWeb({ provider: "perplexity", apiKey: "pk" }, "q");++ const { url, init, headers, body } = request();+ expect(url).toBe("https://api.perplexity.ai/search");+ expect(init.method).toBe("POST");+ expect(headers.Authorization).toBe("Bearer pk");+ expect(body).toEqual({ query: "q", max_results: 8 });+ expect(sources).toEqual([ { ...PAGE, snippet: "From Perplexity" } ]);+ });+it("asks SearXNG for JSON, sends a key only when there is one, and keeps web URLs only", async () => {respond({ results: [ { ...PAGE, content: "Hit" }, { title: "Local", url: "file:///etc/passwd" }, { url: "https://untitled.example" } ] });const sources = await searchWeb({ provider: "searxng", apiKey: "", baseURL: "http://localhost:8888/" }, "q");diff --git a/packages/trilium-core/src/services/llm/web_search.ts b/packages/trilium-core/src/services/llm/web_search.tsindex 16895f0e92..cb53859514 100644--- a/packages/trilium-core/src/services/llm/web_search.ts+++ b/packages/trilium-core/src/services/llm/web_search.ts@@ -96,6 +96,14 @@ export async function searchWeb(setup: WebSearchSetup, query: string): Promise<W}) as { organic?: unknown[] };return toSources(payload.organic, "snippet", "link");}+ case "perplexity": {+ const payload = await requestJson(`${setup.baseURL ?? "https://api.perplexity.ai"}/search`, {+ method: "POST",+ headers: { "Content-Type": "application/json", "Authorization": `Bearer ${setup.apiKey}` },+ body: JSON.stringify({ query, max_results: MAX_RESULTS })+ }) as { results?: unknown[] };+ return toSources(payload.results, "snippet");+ }case "searxng": {if (!setup.baseURL) {throw new Error("The SearXNG search provider has no address.");