medusa-plugin-typesense
A full-featured Typesense Search, Vector/Hybrid AI Discovery, Merchandising, and Custom Entity Indexing Plugin for Medusa v2 (^2.21.0).
Built specifically for Medusa 2.21+ with a Dual Architecture:
- Standalone Typesense Module, Workflows, Subscribers, REST APIs & Admin UI (
/app/typesense): Zero-downtime collection alias rebuilds, Multi-way & One-way Synonyms, Curations/Overrides (pinning, hiding, promo banners, scheduled windows), Stopwords, Vector/Hybrid search, Conversational RAG, Search Analytics, Custom Entities indexing, and Hydrated Storefront APIs.
- Native Medusa
2.21 Search Module Provider (medusa-plugin-typesense/providers/typesense) & Index Factories (medusa-plugin-typesense/indexes): Plugs directly into @medusajs/medusa/search with defineProductSearchIndex, defineCategorySearchIndex, defineCollectionSearchIndex, and defineCustomSearchIndex.
Table of Contents
- Features
- Compatibility
- Architecture
- Installation
- Configuration (
medusa-config.ts)
- Environment Variables (
.env)
- Full Configuration Reference
- Medusa 2.21 Native Search Index Factories (
src/search/)
- Built-In Schemas & Custom Entities
- Built-In Entities (
products, categories, collections)
- Indexing Custom Entities (
brands, vendors, reviews, etc.)
- Vector, Semantic & Hybrid AI Search
- Multi-Language & Localization
- Merchandising: Synonyms, Curations & Stopwords
- Storefront API Reference (
/store/typesense/*)
- Hydrated Product Search (
GET / POST /store/typesense/products)
- Hydrated Category & Collection Search
- Federated Multi-Entity Search (
POST /store/typesense/search)
- Structured Filter DSL
- Scoped InstantSearch Key (
GET /store/typesense/token)
- Conversational RAG Search (
POST /store/typesense/chat)
- Search Analytics Tracking (
POST /store/typesense/analytics)
- Admin API Reference (
/admin/typesense/*)
- Admin UI Dashboard & Product Widget
- Workflows & Programmatic Usage
- Security & Multi-Tenant Guarantees
- Development & Testing
- License
Features
- Typo-Tolerant Full-Text Search — Prefix matching, configurable field weights (
query_by_weights), custom token separators (-, _, /), highlighting (<mark>), snippets, and result grouping (group_by).
- Faceted & Disjunctive Search — Value facets, numeric range facets (
min_price), statistical facets (min, max, avg, sum), and automatic disjunctive faceting batched into a single Typesense multi_search request.
- Vector, Semantic & Hybrid AI Search — Supports Typesense built-in local ONNX models (
ts/all-MiniLM-L6-v2, ts/e5-small, ts/multilingual-e5-small — no external API keys required), OpenAI/external embedders (openai/text-embedding-3-small), or custom float[] vectors with configurable alpha rank fusion (0.0 keyword to 1.0 semantic).
- Conversational Search (RAG) — Multi-turn natural-language shopping assistant powered by Typesense Conversation Models (
POST /store/typesense/chat).
- Built-in & Custom Entity Indexing — Out-of-the-box schemas and transformers for
products, categories, and collections, plus first-class support for custom entities (brands, vendors, reviews, articles, etc.) via customEntities config, runtime Admin UI registration, or defineCustomSearchIndex().
- Multi-Language / Localization — Per-locale collections (
medusa_products_en, medusa_products_es) with Typesense field-level locale tokenization (ja, zh, ko, de, fr, es, etc.) and automatic translation resolution.
- Zero-Downtime Alias Reindexing — Builds a fresh timestamped physical collection (
medusa_products_v_1791000000), migrates existing Synonyms and Curations/Overrides, imports documents in batches, atomically swaps the collection alias (medusa_products), and prunes old physical collections.
- Merchandising Studio — Manage Multi-way & One-way Synonyms, Curations/Overrides (pin products to exact positions, exclude products, custom filter/sort rules, attach promo banner metadata, schedule active date windows), and Stopwords Sets via Admin UI and REST APIs.
- Hydrated Storefront Endpoints —
/store/typesense/products, /store/typesense/categories, and /store/typesense/collections combine Typesense search speed with Medusa's query.graph to return live calculated_price, tax, variants.inventory_quantity, and automatic sales_channel_id scoping.
- Scoped Search-Only API Keys for InstantSearch —
GET /store/typesense/token generates short-lived HMAC-signed Typesense Scoped Search Keys with embedded status:=published and sales_channel_ids restrictions for safe typesense-instantsearch-adapter usage in storefronts.
- Search Analytics & Telemetry — Tracks search queries, hit counts, execution latency, zero-result queries, click-through rate (CTR), and conversion rate in PostgreSQL (
mpt_search_analytics).
- Admin Dashboard & Product Widget — Full Admin UI at
/app/typesense (Overview, Collections & Custom Entities, Merchandising Studio, AI Search Playground, Search Analytics) plus a Product Detail sidebar widget (product.details.side.after).
Compatibility
| Package |
Version |
Medusa |
Typesense Server |
Node.js |
medusa-plugin-typesense |
^1.0.0 |
^2.21.0 (2.21.2 tested) |
>= 26.0 (27.x – 29.x recommended) |
>= 20.19.0 \|\| >= 22.12.0 |
Architecture
flowchart TB
subgraph Medusa["Medusa v2.21 Host Application"]
NativeSearch["@medusajs/medusa/search Module"]
Sub["Event Subscribers & Nightly Cron Job"]
WF["Workflows (Rollback & Zero-Downtime Reindex)"]
StoreAPI["Store REST APIs (/store/typesense/*)"]
AdminAPI["Admin REST APIs (/admin/typesense/*)"]
AdminUI["Admin UI (/app/typesense + Product Widget)"]
end
subgraph Plugin["medusa-plugin-typesense"]
Provider["TypesenseSearchProviderService\n(medusa-plugin-typesense/providers/typesense)"]
Indexes["Index Factories\n(medusa-plugin-typesense/indexes)"]
Module["TypesenseModuleService\n(medusa-plugin-typesense/modules/typesense)"]
Filter["Safe Filter Compiler & Scoped Key Generator"]
end
subgraph TS["Typesense Cluster"]
Aliases["Collection Aliases\n({prefix}_products, {prefix}_{entity}_{locale})"]
Embeddings["Vector / Hybrid Search & Conversational RAG"]
Merch["Synonyms, Curations (Overrides) & Stopwords"]
end
NativeSearch --> Provider
NativeSearch --> Indexes
Sub --> WF
WF --> Module
StoreAPI --> Module
StoreAPI --> Filter
AdminAPI --> Module
AdminUI --> AdminAPI
Provider --> Aliases
Module --> Aliases
Module --> Embeddings
Module --> Merch
Installation
npm install medusa-plugin-typesense typesense
# or
yarn add medusa-plugin-typesense typesense
# or
pnpm add medusa-plugin-typesense typesense
Configuration (medusa-config.ts)
Environment Variables (.env)
TYPESENSE_HOST=http://127.0.0.1:8108
TYPESENSE_API_KEY=xyz_admin_api_key
TYPESENSE_SEARCH_ONLY_API_KEY=xyz_search_only_api_key
TYPESENSE_COLLECTION_PREFIX=medusa
Registering the Plugin & Modules
You can use the Standalone Typesense Module, the Native Medusa 2.21 Search Provider, or both together:
import { defineConfig, Modules } from "@medusajs/framework/utils"
export default defineConfig({
plugins: [
{
resolve: "medusa-plugin-typesense",
options: {},
},
],
modules: [
// 1. Standalone Typesense Module
// Powers /store/typesense/*, /admin/typesense/*, Admin UI (/app/typesense),
// Event Subscribers, Workflows, Merchandising, Analytics & Zero-Downtime Alias Sync
{
resolve: "medusa-plugin-typesense/modules/typesense",
options: {
host: process.env.TYPESENSE_HOST || "http://127.0.0.1:8108",
apiKey: process.env.TYPESENSE_API_KEY!,
searchOnlyApiKey: process.env.TYPESENSE_SEARCH_ONLY_API_KEY,
collectionPrefix: process.env.TYPESENSE_COLLECTION_PREFIX || "medusa",
batchSize: 250,
autoIndex: true,
zeroDowntimeSwap: true,
defaultLocale: "en",
locales: ["en"],
embedder: {
enabled: false, // Set to true to enable vector/hybrid search
model_name: "ts/all-MiniLM-L6-v2",
field_name: "embedding",
},
analytics: {
enabled: true,
retentionDays: 90,
},
// Optional: Register custom indexable entities
customEntities: {
brands: {
graphEntity: "brand",
graphFields: [
"id",
"name",
"slug",
"description",
"logo_url",
"is_active",
"created_at",
],
queryBy: ["name", "slug", "description"],
queryByWeights: [5, 3, 2],
facetBy: ["is_active"],
storefrontFilterConstraint: "is_active:=true",
},
},
},
},
// 2. Optional: Native Medusa 2.21 Search Module Provider (@medusajs/medusa/search)
{
resolve: Modules.SEARCH,
options: {
providers: [
{
resolve: "medusa-plugin-typesense/providers/typesense",
id: "typesense",
options: {
host: process.env.TYPESENSE_HOST || "http://127.0.0.1:8108",
apiKey: process.env.TYPESENSE_API_KEY!,
collectionPrefix:
process.env.TYPESENSE_COLLECTION_PREFIX || "medusa",
zeroDowntimeSwap: true,
},
},
],
},
},
],
})
Run database migrations to create the mpt_sync_job, mpt_entity_config, and mpt_search_analytics tables:
npx medusa db:migrate
Full Configuration Reference