Meilisearch is a search engine for user-facing search and AI retrieval. This library provides search tools to integrate with the Vercel AI SDK.
npm install @meilisearch/ai-sdkimport { generateText } from "ai";
import { openai } from "@ai-sdk/openai";
import { meilisearchSearch } from "@meilisearch/ai-sdk";
const { text } = await generateText({
model: openai("gpt-5.4-mini"),
system:
"You are a movie assistant. Recommend films and where to stream them using the search tool.",
tools: {
search: meilisearchSearch({
host: "MEILISEARCH_HOST",
apiKey: "YOUR_SEARCH_API_KEY",
indexUid: "movies",
description: "Search movies by title or synopsis",
}),
},
});
console.log(text);- Create a project on Meilisearch Cloud or self-host
- Create a
moviesindex and add documents - Add your host and API key to
.env:
MEILISEARCH_HOST=https://your-project.meilisearch.io
MEILISEARCH_API_KEY=your-search-api-keyHybrid search with filters, sorting:
const { text } = await generateText({
model: openai("gpt-5.4-mini"),
system: "You are a movie assistant. Recommend films using the search tool.",
prompt: "Recommend recent action movies about revenge",
tools: {
search: meilisearchSearch({
host: "MEILISEARCH_HOST",
apiKey: "YOUR_SEARCH_API_KEY",
indexUid: "movies",
description: "Search movies by title or synopsis",
searchParams: {
limit: 10,
sort: ["release_date:desc"],
hybrid: {
embedder: "default",
semanticRatio: 0.5,
},
},
}),
},
});
console.log(text);meilisearchSearch({
// Connect with host + API key
host: "MEILISEARCH_HOST",
apiKey: "YOUR_SEARCH_API_KEY",
// or reuse an existing Meilisearch client instance
// client,
description: "Search movies by title or synopsis",
// Search target
indexUid: "movies",
// Optional SearchParams (except q, provided at runtime by the tool call)
searchParams: {
limit: 10,
filter: "genres = Action",
sort: ["release_date:desc"],
},
});For more details, see the Search API reference.
meilisearchMultiSearch({
// Connect with host + API key
host: "MEILISEARCH_HOST",
apiKey: "YOUR_SEARCH_API_KEY",
// or reuse an existing Meilisearch client instance
// client,
description: "Search movies and actors",
// Required per-index queries (q is injected at runtime)
queries: [
{ indexUid: "movies", limit: 5 },
{ indexUid: "actors", limit: 3 },
],
// Optional federation config
federation: {
limit: 10,
},
});For more details, see the Multi-search API reference.
meilisearchSearchSimilar({
// Connect with host + API key
host: "MEILISEARCH_HOST",
apiKey: "YOUR_SEARCH_API_KEY",
// or reuse an existing Meilisearch client instance
// client,
description: "Find similar movies by document ID",
// Search target
indexUid: "movies",
// Optional similar-documents params (except id, provided at runtime)
searchSimilarParams: {
embedder: "default",
limit: 5,
},
});For more details, see the Similar documents API reference.
See CONTRIBUTING.md for details.
MIT