strapi-content-embeddings 0.1.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.
Files changed (61) hide show
  1. package/README.md +276 -0
  2. package/dist/_chunks/App-7LMg3lrX.mjs +1004 -0
  3. package/dist/_chunks/App-wC2qv6kC.js +1008 -0
  4. package/dist/_chunks/en-B4KWt_jN.js +4 -0
  5. package/dist/_chunks/en-Byx4XI2L.mjs +4 -0
  6. package/dist/_chunks/index-Cz9cEuvw.mjs +411 -0
  7. package/dist/_chunks/index-o-tbBpJG.js +413 -0
  8. package/dist/admin/index.js +4 -0
  9. package/dist/admin/index.mjs +5 -0
  10. package/dist/admin/src/components/Initializer.d.ts +5 -0
  11. package/dist/admin/src/components/PluginIcon.d.ts +2 -0
  12. package/dist/admin/src/components/custom/BackLink.d.ts +5 -0
  13. package/dist/admin/src/components/custom/ChatModal.d.ts +1 -0
  14. package/dist/admin/src/components/custom/EmbeddingsModal.d.ts +1 -0
  15. package/dist/admin/src/components/custom/EmbeddingsTable.d.ts +12 -0
  16. package/dist/admin/src/components/custom/EmbeddingsWidget.d.ts +1 -0
  17. package/dist/admin/src/components/custom/EmptyState.d.ts +1 -0
  18. package/dist/admin/src/components/custom/Illo.d.ts +1 -0
  19. package/dist/admin/src/components/custom/Markdown.d.ts +5 -0
  20. package/dist/admin/src/components/custom/MarkdownEditor.d.ts +9 -0
  21. package/dist/admin/src/components/custom/RobotIcon.d.ts +6 -0
  22. package/dist/admin/src/components/forms/CreateEmbeddingForm.d.ts +15 -0
  23. package/dist/admin/src/index.d.ts +12 -0
  24. package/dist/admin/src/pages/App.d.ts +2 -0
  25. package/dist/admin/src/pages/CreateEmbeddings.d.ts +1 -0
  26. package/dist/admin/src/pages/EmbeddingDetails.d.ts +1 -0
  27. package/dist/admin/src/pages/HomePage.d.ts +1 -0
  28. package/dist/admin/src/pluginId.d.ts +1 -0
  29. package/dist/admin/src/utils/api.d.ts +33 -0
  30. package/dist/admin/src/utils/getTranslation.d.ts +2 -0
  31. package/dist/server/index.js +1359 -0
  32. package/dist/server/index.mjs +1360 -0
  33. package/dist/server/src/bootstrap.d.ts +5 -0
  34. package/dist/server/src/config/index.d.ts +26 -0
  35. package/dist/server/src/content-types/embedding/index.d.ts +54 -0
  36. package/dist/server/src/content-types/index.d.ts +56 -0
  37. package/dist/server/src/controllers/controller.d.ts +12 -0
  38. package/dist/server/src/controllers/index.d.ts +18 -0
  39. package/dist/server/src/controllers/mcp.d.ts +18 -0
  40. package/dist/server/src/destroy.d.ts +5 -0
  41. package/dist/server/src/index.d.ts +154 -0
  42. package/dist/server/src/mcp/index.d.ts +6 -0
  43. package/dist/server/src/mcp/schemas/index.d.ts +65 -0
  44. package/dist/server/src/mcp/server.d.ts +8 -0
  45. package/dist/server/src/mcp/tools/create-embedding.d.ts +38 -0
  46. package/dist/server/src/mcp/tools/get-embedding.d.ts +34 -0
  47. package/dist/server/src/mcp/tools/index.d.ts +114 -0
  48. package/dist/server/src/mcp/tools/list-embeddings.d.ts +40 -0
  49. package/dist/server/src/mcp/tools/rag-query.d.ts +34 -0
  50. package/dist/server/src/mcp/tools/semantic-search.d.ts +34 -0
  51. package/dist/server/src/middlewares/index.d.ts +2 -0
  52. package/dist/server/src/plugin-manager.d.ts +45 -0
  53. package/dist/server/src/policies/index.d.ts +2 -0
  54. package/dist/server/src/register.d.ts +5 -0
  55. package/dist/server/src/routes/admin.d.ts +14 -0
  56. package/dist/server/src/routes/content-api.d.ts +15 -0
  57. package/dist/server/src/routes/index.d.ts +36 -0
  58. package/dist/server/src/services/embeddings.d.ts +45 -0
  59. package/dist/server/src/services/index.d.ts +26 -0
  60. package/dist/style.css +95 -0
  61. package/package.json +104 -0
package/README.md ADDED
@@ -0,0 +1,276 @@
1
+ # Strapi Content Embeddings
2
+
3
+ A Strapi v5 plugin that creates vector embeddings from your content using OpenAI and stores them in Neon PostgreSQL with pgvector. Enables semantic search, RAG (Retrieval-Augmented Generation) chat, and MCP (Model Context Protocol) integration for AI assistants like Claude Desktop.
4
+
5
+ ## Features
6
+
7
+ - **Vector Embeddings**: Generate embeddings from your content using OpenAI's embedding models
8
+ - **Neon PostgreSQL Storage**: Store embeddings in Neon DB with pgvector for efficient similarity search
9
+ - **RAG Chat Interface**: Built-in chat widget to ask questions about your content
10
+ - **MCP Server**: Expose your embeddings to AI assistants via Model Context Protocol
11
+ - **Content Manager Integration**: Create embeddings directly from any content type's edit view
12
+ - **Standalone Embeddings**: Create embeddings independent of content types
13
+ - **Multiple Embedding Models**: Support for OpenAI's text-embedding-3-small, text-embedding-3-large, and text-embedding-ada-002
14
+
15
+ ## Requirements
16
+
17
+ - Strapi v5.x
18
+ - Node.js 18+
19
+ - OpenAI API key
20
+ - Neon PostgreSQL database with pgvector extension
21
+
22
+ ## Installation
23
+
24
+ ```bash
25
+ npm install strapi-content-embeddings
26
+ # or
27
+ yarn add strapi-content-embeddings
28
+ ```
29
+
30
+ ## Configuration
31
+
32
+ ### 1. Enable the Plugin
33
+
34
+ Add the plugin to your `config/plugins.ts` (or `config/plugins.js`):
35
+
36
+ ```typescript
37
+ export default ({ env }) => ({
38
+ "strapi-content-embeddings": {
39
+ enabled: true,
40
+ config: {
41
+ openAIApiKey: env("OPENAI_API_KEY"),
42
+ neonConnectionString: env("NEON_CONNECTION_STRING"),
43
+ // Optional: Choose embedding model (default: "text-embedding-3-small")
44
+ embeddingModel: env("EMBEDDING_MODEL", "text-embedding-3-small"),
45
+ },
46
+ },
47
+ });
48
+ ```
49
+
50
+ ### 2. Set Environment Variables
51
+
52
+ Add the following to your `.env` file:
53
+
54
+ ```bash
55
+ OPENAI_API_KEY=sk-your-openai-api-key
56
+ NEON_CONNECTION_STRING=postgresql://user:password@your-neon-host.neon.tech/dbname?sslmode=require
57
+ # Optional
58
+ EMBEDDING_MODEL=text-embedding-3-small
59
+ ```
60
+
61
+ ### 3. Get Your Neon Connection String
62
+
63
+ 1. Sign up at [Neon](https://neon.tech)
64
+ 2. Create a new project
65
+ 3. Navigate to your project's **Connection Details**
66
+ 4. Copy the connection string (it should look like `postgresql://user:password@ep-xxx.region.aws.neon.tech/dbname?sslmode=require`)
67
+
68
+ The plugin will automatically:
69
+ - Enable the pgvector extension
70
+ - Create the `embeddings_documents` table
71
+ - Set up HNSW indexes for fast similarity search
72
+
73
+ ## MCP Integration
74
+
75
+ This plugin exposes an MCP (Model Context Protocol) server that allows AI assistants like Claude Desktop to search your embeddings.
76
+
77
+ ### MCP Endpoint
78
+
79
+ ```
80
+ POST /api/strapi-content-embeddings/mcp
81
+ ```
82
+
83
+ ### Available MCP Tools
84
+
85
+ | Tool | Description | Trigger |
86
+ |------|-------------|---------|
87
+ | `rag_query` | Ask questions and get AI-generated answers from your content | `/rag [question]` |
88
+ | `semantic_search` | Find semantically similar content | `/rag search [query]` |
89
+ | `list_embeddings` | List all stored embeddings | - |
90
+ | `get_embedding` | Get a specific embedding by ID | - |
91
+ | `create_embedding` | Create a new embedding | - |
92
+
93
+ ### Claude Desktop Configuration
94
+
95
+ Add to your Claude Desktop config (`~/Library/Application Support/Claude/claude_desktop_config.json`):
96
+
97
+ ```json
98
+ {
99
+ "mcpServers": {
100
+ "strapi-content-embeddings": {
101
+ "command": "npx",
102
+ "args": [
103
+ "mcp-remote",
104
+ "https://your-strapi-url.com/api/strapi-content-embeddings/mcp",
105
+ "--header",
106
+ "Authorization: Bearer YOUR_STRAPI_API_TOKEN"
107
+ ]
108
+ }
109
+ }
110
+ }
111
+ ```
112
+
113
+ ### Usage in Claude Desktop
114
+
115
+ Type `/rag` followed by your question to search your embeddings:
116
+
117
+ ```
118
+ /rag What is Strapi?
119
+ /rag Who is Paul Bratslavsky?
120
+ ```
121
+
122
+ ## Available Embedding Models
123
+
124
+ | Model | Dimensions | Description |
125
+ |-------|------------|-------------|
126
+ | `text-embedding-3-small` | 1536 | Fast, cost-effective (default) |
127
+ | `text-embedding-3-large` | 3072 | Higher accuracy, more expensive |
128
+ | `text-embedding-ada-002` | 1536 | Legacy model |
129
+
130
+ ## Usage
131
+
132
+ ### Admin Panel
133
+
134
+ #### Create Embeddings Page
135
+
136
+ Navigate to **Content Embeddings** in the Strapi admin sidebar to:
137
+ - View all existing embeddings
138
+ - Create new standalone embeddings
139
+ - Delete embeddings
140
+ - Search and filter embeddings
141
+
142
+ #### Content Manager Integration
143
+
144
+ When editing any content type, you'll see an **Embeddings** panel in the right sidebar:
145
+ - **Create Embedding**: Generate an embedding from the current content
146
+ - **View Embedding**: Navigate to the embedding details
147
+ - **Update Embedding**: Update the embedding with current content changes
148
+
149
+ #### Chat Widget
150
+
151
+ Click the robot icon in the bottom-right corner to open the RAG chat interface:
152
+ - Ask questions about your embedded content
153
+ - View source documents used to generate answers
154
+ - Navigate to source embeddings
155
+
156
+ ### Programmatic Usage
157
+
158
+ #### Create an Embedding
159
+
160
+ ```typescript
161
+ const result = await strapi
162
+ .plugin("strapi-content-embeddings")
163
+ .service("embeddings")
164
+ .createEmbedding({
165
+ data: {
166
+ title: "My Document",
167
+ content: "This is the content to embed...",
168
+ collectionType: "api::article.article", // optional
169
+ fieldName: "content", // optional
170
+ metadata: { customField: "value" }, // optional
171
+ },
172
+ });
173
+ ```
174
+
175
+ #### Query Embeddings (RAG)
176
+
177
+ ```typescript
178
+ const response = await strapi
179
+ .plugin("strapi-content-embeddings")
180
+ .service("embeddings")
181
+ .queryEmbeddings("What is this document about?");
182
+
183
+ // response.text - The AI-generated answer
184
+ // response.sourceDocuments - The documents used for context
185
+ ```
186
+
187
+ #### Similarity Search
188
+
189
+ ```typescript
190
+ const documents = await strapi
191
+ .plugin("strapi-content-embeddings")
192
+ .service("embeddings")
193
+ .similaritySearch("search query", 4); // returns top 4 similar documents
194
+ ```
195
+
196
+ ## API Endpoints
197
+
198
+ All endpoints require admin authentication.
199
+
200
+ | Method | Endpoint | Description |
201
+ |--------|----------|-------------|
202
+ | `POST` | `/strapi-content-embeddings/embeddings/create-embedding` | Create a new embedding |
203
+ | `PUT` | `/strapi-content-embeddings/embeddings/update-embedding/:id` | Update an existing embedding |
204
+ | `DELETE` | `/strapi-content-embeddings/embeddings/delete-embedding/:id` | Delete an embedding |
205
+ | `GET` | `/strapi-content-embeddings/embeddings/find` | List all embeddings |
206
+ | `GET` | `/strapi-content-embeddings/embeddings/find/:id` | Get a single embedding |
207
+ | `GET` | `/strapi-content-embeddings/embeddings/embeddings-query?query=...` | RAG query |
208
+
209
+ ## How It Works
210
+
211
+ 1. **Embedding Creation**: When you create an embedding, the content is sent to OpenAI's embedding API to generate a vector representation (1536 or 3072 dimensions depending on the model).
212
+
213
+ 2. **Storage**: The embedding vector is stored in Neon PostgreSQL using the pgvector extension, along with the content and metadata.
214
+
215
+ 3. **Similarity Search**: When querying, the search query is converted to an embedding and compared against stored embeddings using cosine similarity via pgvector's HNSW index.
216
+
217
+ 4. **RAG Response**: For chat queries, the most relevant documents are retrieved and passed to GPT-4o-mini as context to generate an accurate response.
218
+
219
+ ## Database Schema
220
+
221
+ The plugin creates an `embeddings_documents` table in your Neon database:
222
+
223
+ ```sql
224
+ CREATE TABLE embeddings_documents (
225
+ id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
226
+ content TEXT,
227
+ metadata JSONB,
228
+ embedding vector(1536) -- or 3072 for text-embedding-3-large
229
+ );
230
+ ```
231
+
232
+ Indexes:
233
+ - HNSW index on `embedding` for fast similarity search
234
+ - GIN index on `metadata` for filtering
235
+
236
+ ## Permissions
237
+
238
+ The plugin registers the following RBAC permissions:
239
+ - `plugin::strapi-content-embeddings.read` - View embeddings
240
+ - `plugin::strapi-content-embeddings.create` - Create embeddings
241
+ - `plugin::strapi-content-embeddings.update` - Update embeddings
242
+ - `plugin::strapi-content-embeddings.delete` - Delete embeddings
243
+ - `plugin::strapi-content-embeddings.chat` - Use the RAG chat feature
244
+
245
+ Configure these in **Settings > Roles** for each admin role.
246
+
247
+ ## Troubleshooting
248
+
249
+ ### Embeddings not being created
250
+
251
+ 1. Check that `OPENAI_API_KEY` is set correctly
252
+ 2. Check that `NEON_CONNECTION_STRING` is valid
253
+ 3. Look for errors in the Strapi console
254
+
255
+ ### Chat returns "cannot find the answer"
256
+
257
+ 1. Ensure embeddings exist in the database
258
+ 2. Try creating more specific content
259
+ 3. Check that the embedding model matches between creation and query
260
+
261
+ ### Connection errors
262
+
263
+ 1. Verify your Neon connection string includes `?sslmode=require`
264
+ 2. Check that your Neon project is active (not paused)
265
+ 3. Ensure the pgvector extension is enabled
266
+
267
+ ### MCP not connecting
268
+
269
+ 1. Verify the MCP endpoint URL is correct
270
+ 2. Check the Authorization header has a valid Strapi API token
271
+ 3. Ensure the plugin is properly configured and Strapi is running
272
+
273
+ ## License
274
+
275
+ MIT
276
+ # strapi-content-embeddings