Typesense
Use Typesense for MainSDK search - self-hosted or cloud, API key, main.yaml, results scoped to the searcher, testing and swapping.
Typesense is an open-source search engine, self-hosted or on Typesense Cloud, and the driver in the search examples. MainSDK limits every result to what the person searching may see. Pick it for fast, typo-tolerant search you can run in your own region.
Interfaces it serves
Pick Typesense in main.yaml for any of these. Your calls stay the same, and you can swap later.
searchBuilding for 0.4Driver typesense Typesense
search:
driver: typesenseBefore you start
- Run Typesense yourself or create a Typesense Cloud cluster, in the region your records belong to.
- Create an API key for the app scoped to the collections and actions it needs, and store it in your secrets manager.
Configure
search:
driver: typesense
# key: secret:TYPESENSE_API_KEY # suggested name; host and collection keys are [to be decided]Use it
import { auth, search } from "mainsdk";
export async function GET(req: Request) {
const session = await auth.require(req);
const q = new URL(req.url).searchParams.get("q") ?? "";
return Response.json(await search.query({ q, for: session.user, limit: 10 }));
}Local development and testing
Run Typesense in a container for development. A search fake for createTestApp() from @mainsdk/testing, and chaos.on("search", { outage: true }), arrive with the spec.
What MainSDK adds on top
- Results scoped to the person searching (
for: user). - The same calls on every engine. See Search and vector search.
Limits and notes
typesenseis a plannedsearchdriver for phase 2;searchhas no spec yet.- An index is a copy of your data; keep
personalandsensitivefields out unless needed, and keep the cluster in US, EU or India as your data requires.
Swap to or from it
search:
driver: pgvector # was typesenseFAQ
Typesense or pgvector? Both serve search. Typesense is a separate engine; pgvector runs inside your Postgres, so there is no second system to operate.
Next
Was this page helpful?