Sign up and create a dataset. Then obtain 2 API keys where one has only read access and the other has admin access to create and delete chunks.
Store these credentials in environment variables.
Notice
One API Key should have only read access for the public facing search and the
other should have admin access to create and delete chunks.
You can export the search indexes from Next.js using a route handler:
app/static.json/route.ts
import { NextResponse } from 'next/server';import { source } from '@/lib/source';import { type TrieveDocument } from 'trieve-fumadocs-adapter/search/sync';export const revalidate = false;export function GET() { const results: TrieveDocument[] = []; for (const page of source.getPages()) { results.push({ _id: page.url, structured: page.data.structuredData, url: page.url, title: page.data.title, description: page.data.description, }); } return NextResponse.json(results);}
Create a script, the sync function will sync search indexes.
update-index.mjs
import * as fs from 'node:fs';import { sync } from 'trieve-fumadocs-adapter/search/sync';import { TrieveSDK } from 'trieve-ts-sdk';const content = fs.readFileSync('.next/server/app/static.json.body');// now you can pass it to `sync`/** @type {import('trieve-fumadocs-adapter/search/sync').TrieveDocument[]} **/const records = JSON.parse(content.toString());const client = new TrieveSDK({ apiKey: 'adminApiKey', datasetId: 'datasetId',});sync(client, records);