MainSDK
Search⌘K
Integrations

Algolia

Use Algolia for MainSDK search - application and API keys, main.yaml, indexing, results scoped to the searcher, testing and swapping.

1 interface1 driverWritten guide
Updated 2026-10-28

Algolia is a hosted search service, and a driver behind search. Your app indexes records with search.index() and queries them with search.query({ for: user }), and MainSDK limits results to what the person searching may see. Pick Algolia when you want hosted, fast-as-you-type search for a catalogue or help centre without running a search server.

Interfaces it serves

Pick Algolia in main.yaml for any of these. Your calls stay the same, and you can swap later.

Before you start

You need an Algolia account.

  1. Create an application and pick the region where its data is hosted, close to your users and in line with your data rules.
  2. Copy the application ID and an API key. Algolia gives you an admin key, a search-only key, and lets you create keys with narrower rights. Use a key restricted to the indexes and operations the app needs, rather than the admin key, and keep it server side.
  3. Create the indexes your app searches. Whether the driver creates them for you is not decided yet.

Store the key in your secrets manager, never in code or a committed env file.

Configure

main.yaml
search:
  driver: algolia
  # key: secret:ALGOLIA_API_KEY   # suggested name; application ID, key and index names are [to be decided]

Not decided yet: index names and fields, the document shape search.index() takes, and the connection settings per driver.

Use it

app/api/search/route.ts
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") ?? "";
  const hits = await search.query({ q, for: session.user, limit: 10 });
  return Response.json(hits);
}

Index a record when it changes with search.index(product).

Local development and testing

  • No account: a search fake for createTestApp() from @mainsdk/testing arrives with the spec. Until then, use a separate Algolia application or index for development.
  • The test that matters: prove a user never gets another user's records. When the fake lands, chaos.on("search", { outage: true }) drills an Algolia outage.

What MainSDK adds on top

  • Results scoped to the person searching (for: user).
  • The same search.index() and search.query() calls on every engine, so moving off Algolia is one line plus a re-index.
  • Hits that can ground an AI answer through ai without leaking another customer's records.

See Search and vector search for the full contract.

Limits and notes

  • algolia is a planned search driver for phase 2, and search has no spec yet.
  • An index is a copy of your data, held in the Algolia region you chose. Keep personal and sensitive fields out of it unless the feature needs them; see Data and regions. MainSDK regions are US, EU and India.
  • Never ship the admin key to the browser. How MainSDK scopes results when the browser queries Algolia directly is not decided yet; query through your server.

Swap to or from it

main.yaml
search:
  driver: algolia   # was typesense

FAQ

Can I use Algolia for vector search? search covers vector search, but how a driver takes a vector is not decided yet. pgvector runs it inside your Postgres.

Which key goes in main.yaml? None directly. Store a restricted server key in your secrets manager and refer to it with secret:NAME.

Next

Open questions

Was this page helpful?

↑↓ moveEnter openEsc close

Not decided yet