Algolia
Use Algolia for MainSDK search - application and API keys, main.yaml, indexing, results scoped to the searcher, testing and swapping.
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.
searchBuilding for 0.4Driver algolia AlgoliaPlanned driver
later; not in the search spec for 0.4
search:
driver: algoliaBefore you start
You need an Algolia account.
- Create an application and pick the region where its data is hosted, close to your users and in line with your data rules.
- 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.
- 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
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
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
searchfake forcreateTestApp()from@mainsdk/testingarrives 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()andsearch.query()calls on every engine, so moving off Algolia is one line plus a re-index. - Hits that can ground an AI answer through
aiwithout leaking another customer's records.
See Search and vector search for the full contract.
Limits and notes
algoliais a plannedsearchdriver for phase 2, andsearchhas no spec yet.- An index is a copy of your data, held in the Algolia region you chose. Keep
personalandsensitivefields 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
search:
driver: algolia # was typesenseFAQ
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?