Integration Module 2.0 for Medusa is outRead the announcement
T

Typesense

Full-featured Typesense search, vector/hybrid AI search, merchandising (synonyms, curations, stopwords), custom entity indexing, and InstantSearch plugin for Medusa v2

npm install @vicacha-devs/medusa-plugin-typesense
Category
Built by
Version
0.1.1
Last updated
4 days ago
Monthly downloads
Loading downloads

medusa-plugin-typesense

A full-featured Typesense Search, Vector/Hybrid AI Discovery, Merchandising, and Custom Entity Indexing Plugin for Medusa v2 ().

Built specifically for Medusa with a Dual Architecture:

  1. Standalone Typesense Module, Workflows, Subscribers, REST APIs & Admin UI (): 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.
  2. Native Medusa Search Module Provider () & Index Factories (): Plugs directly into with , , , and .

Table of Contents


Features

  • Typo-Tolerant Full-Text Search — Prefix matching, configurable field weights (), custom token separators (, , ), highlighting (), snippets, and result grouping ().
  • Faceted & Disjunctive Search — Value facets, numeric range facets (), statistical facets (, , , ), and automatic disjunctive faceting batched into a single Typesense request.
  • Vector, Semantic & Hybrid AI Search — Supports Typesense built-in local ONNX models (, , — no external API keys required), OpenAI/external embedders (), or custom vectors with configurable rank fusion ( keyword to semantic).
  • Conversational Search (RAG) — Multi-turn natural-language shopping assistant powered by Typesense Conversation Models ().
  • Built-in & Custom Entity Indexing — Out-of-the-box schemas and transformers for , , and , plus first-class support for custom entities (, , , , etc.) via config, runtime Admin UI registration, or .
  • Multi-Language / Localization — Per-locale collections (, ) with Typesense field-level locale tokenization (, , , , , , etc.) and automatic translation resolution.
  • Zero-Downtime Alias Reindexing — Builds a fresh timestamped physical collection (), migrates existing Synonyms and Curations/Overrides, imports documents in batches, atomically swaps the collection alias (), 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 — , , and combine Typesense search speed with Medusa's to return live , tax, , and automatic scoping.
  • Scoped Search-Only API Keys for InstantSearch — generates short-lived HMAC-signed Typesense Scoped Search Keys with embedded and restrictions for safe 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 ().
  • Admin Dashboard & Product Widget — Full Admin UI at (Overview, Collections & Custom Entities, Merchandising Studio, AI Search Playground, Search Analytics) plus a Product Detail sidebar widget ().

Compatibility

PackageVersionMedusaTypesense ServerNode.js
( tested) ( recommended)

Architecture


Installation


Configuration ()

Environment Variables ()

Registering the Plugin & Modules

You can use the Standalone Typesense Module, the Native Medusa 2.21 Search Provider, or both together:

Run database migrations to create the , , and tables:

npx medusa db:migrate

Full Configuration Reference

OptionTypeDefaultDescription
Primary Typesense URL () or hostname
/ Typesense port if not specified in
Protocol if not specified in
Multi-node High Availability cluster array ()
RequiredServer-side Typesense Admin API Key (never exposed to clients)
Search-only parent key used to sign HMAC Scoped Keys in
Client request timeout in seconds
Delay between retries across cluster nodes
Number of automatic retries on transient errors
Prefix for collection aliases ()
Number of documents per JSONL import chunk
Automatically index changes on Medusa , , events
Build physical collection and atomically flip alias
Default locale code
All active locales to index (creates when or non-default)
Global default vector embedder configuration
Default Typesense Conversation Model ID for
Default TTL (in seconds) for scoped search tokens (capped at )
Search analytics logging configuration
Override schemas, , , or for built-in , , or
Register custom Medusa module entities (e.g., , , )

Medusa 2.21 Native Search Index Factories ()

When using Medusa 's native module (), create index definitions inside your Medusa app's directory using the factories exported from :


Built-In Schemas & Custom Entities

Built-In Entities (, , )

  1. ():

    • Full-text fields (): (weight ), (), (), (), (), (), (), (), (), ().
    • Facet fields (): , , , , , , , , , , , , , , , , .
    • Sortable numeric fields: , , , , , , , , .
    • Storefront security filter: + active .
  2. ():

    • Full-text fields (): (), (), (), ().
    • Facet fields (): , , , , .
    • Storefront security filter: .
  3. ():

    • Full-text fields (): (), ().
    • Sortable fields: , , .

Indexing Custom Entities (, , , etc.)

You can index any custom Medusa module entity in three ways:

Method 1: Static Configuration in

Method 2: Dynamic Runtime Registration via Admin API or Admin UI

Use the Collections & Custom Entities tab in or :

Method 3: Syncing Custom Entities from Your Custom Subscribers


supports three vector embedding strategies:

  1. Typesense Built-in Local ONNX Models (Zero External API Keys):
  2. External Embedding Providers (OpenAI / PaLM / Vertex AI):
  3. Custom Pre-Computed Vectors ():

When querying , , or , specify:

  • — Pure lexical BM25/typo-tolerant search.
  • — Pure vector nearest-neighbor search ( neighbors, optional ).
  • — Combines lexical and vector search using rank fusion ( weights 70% keyword + 30% vector similarity).

Multi-Language & Localization

Configure multiple locales in :

  • Each locale gets an isolated collection alias (, , , ).
  • Text fields automatically apply Typesense's language-specific tokenizer (, , etc.).
  • Transformers automatically resolve localized field values from or before falling back to the base fields.
  • Pass (or ) in Storefront and Admin API requests to query that locale's index.

Merchandising: Synonyms, Curations & Stopwords

Manage merchandising rules from the Merchandising Studio tab at or via :

1. Multi-Way & One-Way Synonyms

  • Multi-Way Synonym (omit ): Searching any term matches all others ().
  • One-Way Synonym (specify ): Searching also matches and , but searching does not expand back.

2. Curations / Overrides

  • Pin Documents (): Pin specific product IDs to exact 1-based positions (, ) when a query matches ().
  • Hide Documents (): Exclude specific product IDs from appearing for a query.
  • Dynamic Filter & Sort Injection: Automatically apply (e.g., ) or () when a shopper searches a curated keyword.
  • Promo Banner Metadata (): Attach JSON metadata (e.g., ) returned in on storefront responses.
  • Scheduled Windows: Set and Unix timestamps for time-boxed campaigns.

3. Stopwords Sets

Define locale-specific stopword sets (e.g., ) that can be applied to queries via .


Storefront API Reference ()

All storefront endpoints automatically resolve the Publishable API Key () to its associated and enforce (or the entity's ).

1. Hydrated Product Search ( / )

Combines Typesense search with Medusa's to return full Medusa product objects with live and , ordered by Typesense relevance rank.

Response:

  • /
  • /

3. Federated Multi-Entity Search ()

Search across , , , and any custom entities (, , ) in a single HTTP request:

4. Structured Filter DSL

All search endpoints accept a structured object that is validated against the entity's schema allowlist and compiled into escaped Typesense syntax:

Supported operators: , , , , , , , , (), , .

5. Scoped InstantSearch Key ()

Generates a short-lived HMAC-signed Typesense Scoped Search-Only API Key with embedded and constraints so your storefront can query Typesense directly via :

6. Conversational RAG Search ()

7. Search Analytics Tracking ()


Admin API Reference ()

All Admin endpoints require standard Medusa Admin authentication (session cookie, bearer JWT, or secret API key).

Method & PathDescription
Cluster health, collection/alias metrics, and recent sync jobs
List all entity collections, active aliases, and document counts
Trigger zero-downtime reindex across all enabled entities
Trigger zero-downtime rebuild () or incremental sync () for
List built-in and custom entity index configurations
Register a new custom entity or update an existing entity config
Remove a custom entity configuration (and optionally drop its collection)
List or upsert multi-way / one-way synonyms
Delete a synonym rule
List or upsert curations/overrides (pinning, hiding, promo banners)
Delete a curation rule
List or upsert stopword sets
Delete a stopword set
Execute Admin Search Playground queries with full telemetry & highlight inspection
Retrieve popular queries, zero-result queries, CTR, conversion rate & latency
Inspect raw indexed JSON document, trigger single-item re-sync, or delete from index

Admin UI Dashboard & Product Widget

  1. Typesense Search Dashboard ():
    • Overview & Sync Jobs: Live cluster health indicator, total indexed documents, zero-downtime "Reindex All" button, and sync job history table (, , with duration and synced/deleted counts).
    • Collections & Custom Entities: Inspect every built-in and custom entity's collection alias, physical versioned collection, & configuration, trigger per-entity rebuilds, and register new custom Medusa entities via a modal drawer.
    • Merchandising Studio: Create and delete Multi-way / One-way Synonyms, Curations/Overrides (pinned IDs, excluded IDs, match type), and Stopwords Sets.
    • AI Search Playground: Test , , and search modes with an interactive blending slider, live latency/hit badges, safe highlight previews, and raw JSON inspection.
    • Search Analytics: View total searches, average latency, click-through rate (CTR), conversion rate, top queries, and zero-result queries (with a 1-click shortcut to create a Synonym for any zero-result query).
  2. Product Detail Widget ():
    • Embedded directly on every Medusa Admin Product page to display whether the product is indexed in Typesense, its indexed prices/SKUs/facets, a collapsible JSON document viewer, and a 1-click "Re-sync Now" button.

Workflows & Programmatic Usage

Invoking Workflows

Resolving Directly


Security & Multi-Tenant Guarantees

  • Admin Key Isolation: never leaves the server. Storefront clients using InstantSearch receive short-lived HMAC-signed Scoped Search Keys () capped at () with embedded constraints.
  • Filter Injection Prevention: in validates all user-supplied filter field names against the entity schema's allowlist, escapes all string values inside backticks (), and wraps mandatory storefront constraints () in outer parentheses so user clauses cannot bypass tenant or visibility boundaries.
  • Strict Input Validation: Every and route is protected by Zod validation schemas in .
  • Safe Highlighting in Admin UI: Search result highlights are tokenized into safe React JSX nodes without .

Development & Testing

License

MIT © Jose Luis