@nexo-labs/payload-typesense 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,185 @@
1
+ # @nexo-labs/payload-typesense
2
+
3
+ A powerful, production-ready search plugin that integrates [Typesense](https://typesense.org/) with [Payload CMS](https://payloadcms.com/). This plugin provides lightning-fast, typo-tolerant search capabilities with real-time synchronization, and a comprehensive RAG (Retrieval Augmented Generation) system for building AI-powered conversational agents.
4
+
5
+ ## Features
6
+
7
+ * **Real-time Sync**: Automatically syncs your Payload collections to Typesense.
8
+ * **Flexible Indexing**: Map a single Payload collection to multiple Typesense indices (tables) with different configurations.
9
+ * **Advanced Search**:
10
+ * **Semantic Search**: Vector-based search using embeddings.
11
+ * **Keyword Search**: Traditional text matching with typo tolerance.
12
+ * **Hybrid Search**: Combines vector and keyword search for optimal relevance.
13
+ * **RAG & AI Agents**:
14
+ * Built-in support for conversational AI agents.
15
+ * Integrates with OpenAI and Gemini.
16
+ * Manages chat sessions and history.
17
+ * Streaming responses (SSE).
18
+ * **Optimized Performance**: Configurable HNSW parameters for vector search and batch processing for sync.
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ pnpm add @nexo-labs/payload-typesense
24
+ ```
25
+
26
+ ## Configuration
27
+
28
+ The plugin is configured in your `payload.config.ts`.
29
+
30
+ ### Basic Setup
31
+
32
+ ```typescript
33
+ import { buildConfig } from 'payload/config';
34
+ import { typesenseSearch } from '@nexo-labs/payload-typesense';
35
+
36
+ export default buildConfig({
37
+ // ...
38
+ plugins: [
39
+ typesenseSearch({
40
+ typesense: {
41
+ apiKey: process.env.TYPESENSE_API_KEY,
42
+ nodes: [
43
+ {
44
+ host: process.env.TYPESENSE_HOST,
45
+ port: 443,
46
+ protocol: 'https',
47
+ },
48
+ ],
49
+ },
50
+ features: {
51
+ sync: { enabled: true },
52
+ search: { enabled: true },
53
+ embedding: {
54
+ type: 'openai',
55
+ apiKey: process.env.OPENAI_API_KEY,
56
+ model: 'text-embedding-3-small',
57
+ },
58
+ },
59
+ collections: {
60
+ posts: [
61
+ {
62
+ enabled: true,
63
+ tableSuffix: 'v1',
64
+ searchFields: ['title', 'content'],
65
+ chunkingStrategy: { type: 'markdown' },
66
+ },
67
+ ],
68
+ },
69
+ }),
70
+ ],
71
+ });
72
+ ```
73
+
74
+ ### Sync Configuration
75
+
76
+ You can define how each collection is synced to Typesense. The `collections` object maps collection slugs to an array of `CollectionTableConfig`.
77
+
78
+ ```typescript
79
+ collections: {
80
+ posts: [
81
+ {
82
+ enabled: true,
83
+ // Optional suffix for the Typesense collection name
84
+ // Result: "posts_summary"
85
+ tableSuffix: 'summary',
86
+ // Fields to include in the Typesense document
87
+ searchFields: ['title', 'excerpt'],
88
+ // Chunking strategy for long text
89
+ chunkingStrategy: { type: 'simple', chunkSize: 500 },
90
+ },
91
+ {
92
+ enabled: true,
93
+ // Explicitly naming the table overrides the default naming convention
94
+ // Result: "my_custom_posts_index"
95
+ tableName: 'my_custom_posts_index',
96
+ searchFields: ['title', 'content'],
97
+ chunkingStrategy: { type: 'markdown' },
98
+ }
99
+ ]
100
+ }
101
+ ```
102
+
103
+ ### RAG & Agents Configuration
104
+
105
+ Enable RAG to build chat interfaces on top of your data.
106
+
107
+ ```typescript
108
+ features: {
109
+ rag: {
110
+ enabled: true,
111
+ agents: [
112
+ {
113
+ slug: 'support-bot',
114
+ name: 'Support Assistant',
115
+ systemPrompt: 'You are a helpful support assistant.',
116
+ llmModel: 'gpt-4o-mini',
117
+ // Collections this agent can access
118
+ searchCollections: ['posts_full_text'],
119
+ }
120
+ ]
121
+ }
122
+ }
123
+ ```
124
+
125
+ ## Usage
126
+
127
+ ### Search API
128
+
129
+ The plugin exposes endpoints for searching your data.
130
+
131
+ **Endpoint:** `/api/typesense/search`
132
+
133
+ ```typescript
134
+ // Example using fetch
135
+ const response = await fetch('/api/typesense/search', {
136
+ method: 'POST',
137
+ body: JSON.stringify({
138
+ query: 'how to install',
139
+ collections: ['posts_full_text'],
140
+ })
141
+ });
142
+ ```
143
+
144
+ ### RAG Chat API
145
+
146
+ **Endpoint:** `/api/typesense/rag/chat`
147
+
148
+ This endpoint supports Server-Sent Events (SSE) for streaming AI responses.
149
+
150
+ ```typescript
151
+ // Example client-side code (simplified)
152
+ const eventSource = new EventSource('/api/typesense/rag/chat?message=hello');
153
+
154
+ eventSource.onmessage = (event) => {
155
+ const data = JSON.parse(event.data);
156
+ if (data.type === 'token') {
157
+ console.log(data.data); // Streamed text
158
+ }
159
+ };
160
+ ```
161
+
162
+ ## Roadmap
163
+
164
+ We are actively working to improve the modularity and flexibility of the plugin.
165
+
166
+ ### 1. Modular Embedding Strategies (High Priority)
167
+ **Goal:** Allow different embedding models for different collections (tables).
168
+ * **Current State:** Global embedding configuration only.
169
+ * **Future:**
170
+ * Move `embedding` config to `CollectionTableConfig`.
171
+ * Support "Table X" -> Gemini, "Table Y" -> OpenAI Large.
172
+ * Update RAG agents to dynamically select the correct embedding model based on the collection being queried.
173
+
174
+ ### 2. Expanded Provider Support
175
+ * **Embeddings:** Add support for Cohere, HuggingFace, and local models (via Ollama).
176
+ * **LLMs:** Add support for Anthropic (Claude), Mistral, and local LLMs.
177
+
178
+ ### 4. Admin UI
179
+ * Dashboard within Payload Admin to view Typesense collection status.
180
+ * Buttons to manually trigger re-sync or re-indexing.
181
+ * Visual management of RAG agents.
182
+
183
+ ### 5. Advanced Sync Controls
184
+ * **Soft Deletes:** Option to mark documents as deleted in Typesense instead of removing them.
185
+ * **Conditional Sync:** specialized `syncCondition` function to control which documents are synced based on their content (e.g., only sync `published` posts).