strapi-content-embeddings 0.1.4 → 0.1.5

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 (36) hide show
  1. package/README.md +187 -0
  2. package/dist/_chunks/{App-CnXhqiao.js → App-Rq72tIgS.js} +35 -37
  3. package/dist/_chunks/App-Rq72tIgS.js.map +1 -0
  4. package/dist/_chunks/{App-4UwemHRe.mjs → App-j180lztd.mjs} +35 -37
  5. package/dist/_chunks/App-j180lztd.mjs.map +1 -0
  6. package/dist/_chunks/en-B4KWt_jN.js +1 -0
  7. package/dist/_chunks/en-B4KWt_jN.js.map +1 -0
  8. package/dist/_chunks/en-Byx4XI2L.mjs +1 -0
  9. package/dist/_chunks/en-Byx4XI2L.mjs.map +1 -0
  10. package/dist/_chunks/{index-BWSiu_nE.mjs → index-B3j0IFUi.mjs} +70 -27
  11. package/dist/_chunks/index-B3j0IFUi.mjs.map +1 -0
  12. package/dist/_chunks/{index-BaPVw3mi.js → index-jf6vikTZ.js} +70 -27
  13. package/dist/_chunks/index-jf6vikTZ.js.map +1 -0
  14. package/dist/admin/index.js +2 -1
  15. package/dist/admin/index.js.map +1 -0
  16. package/dist/admin/index.mjs +2 -1
  17. package/dist/admin/index.mjs.map +1 -0
  18. package/dist/admin/src/components/custom/MarkdownEditor.d.ts +1 -1
  19. package/dist/server/index.js +850 -57
  20. package/dist/server/index.js.map +1 -0
  21. package/dist/server/index.mjs +850 -57
  22. package/dist/server/index.mjs.map +1 -0
  23. package/dist/server/src/config/index.d.ts +9 -0
  24. package/dist/server/src/controllers/controller.d.ts +14 -0
  25. package/dist/server/src/controllers/index.d.ts +2 -0
  26. package/dist/server/src/index.d.ts +38 -2
  27. package/dist/server/src/mcp/tools/create-embedding.d.ts +6 -0
  28. package/dist/server/src/mcp/tools/index.d.ts +4 -0
  29. package/dist/server/src/plugin-manager.d.ts +16 -0
  30. package/dist/server/src/routes/content-api.d.ts +10 -0
  31. package/dist/server/src/routes/index.d.ts +10 -0
  32. package/dist/server/src/services/embeddings.d.ts +43 -2
  33. package/dist/server/src/services/index.d.ts +23 -2
  34. package/dist/server/src/services/sync.d.ts +48 -0
  35. package/dist/server/src/utils/chunking.d.ts +44 -0
  36. package/package.json +1 -1
@@ -1,4 +1,5 @@
1
1
  import type { Core } from "@strapi/strapi";
2
+ import type { PluginConfigSchema } from "../config";
2
3
  export interface CreateEmbeddingData {
3
4
  data: {
4
5
  title: string;
@@ -10,6 +11,8 @@ export interface CreateEmbeddingData {
10
11
  __type: string;
11
12
  id: number;
12
13
  };
14
+ /** Enable chunking for large content (overrides config.autoChunk) */
15
+ autoChunk?: boolean;
13
16
  };
14
17
  }
15
18
  export interface UpdateEmbeddingData {
@@ -17,17 +20,55 @@ export interface UpdateEmbeddingData {
17
20
  title?: string;
18
21
  content?: string;
19
22
  metadata?: Record<string, any>;
23
+ /** Enable chunking for large content on update (overrides config.autoChunk) */
24
+ autoChunk?: boolean;
20
25
  };
21
26
  }
27
+ export interface ChunkedEmbeddingResult {
28
+ /** The parent/first embedding entity */
29
+ entity: any;
30
+ /** All chunk entities created */
31
+ chunks: any[];
32
+ /** Total number of chunks created */
33
+ totalChunks: number;
34
+ /** Whether content was chunked */
35
+ wasChunked: boolean;
36
+ }
22
37
  declare const embeddings: ({ strapi }: {
23
38
  strapi: Core.Strapi;
24
39
  }) => {
25
- createEmbedding(data: CreateEmbeddingData): Promise<import("@strapi/types/dist/modules/documents").AnyDocument>;
40
+ /**
41
+ * Get plugin config with defaults
42
+ */
43
+ getConfig(): PluginConfigSchema;
44
+ /**
45
+ * Create a single embedding (no chunking)
46
+ */
47
+ createEmbedding(data: CreateEmbeddingData): Promise<any>;
48
+ /**
49
+ * Create embeddings with automatic chunking for large content
50
+ * Creates multiple embedding entities, one per chunk
51
+ */
52
+ createChunkedEmbedding(data: CreateEmbeddingData): Promise<ChunkedEmbeddingResult>;
26
53
  deleteEmbedding(id: number | string): Promise<{
27
54
  documentId: string;
28
55
  entries: import("@strapi/types/dist/modules/documents").AnyDocument[];
29
56
  }>;
30
- updateEmbedding(id: string, data: UpdateEmbeddingData): Promise<import("@strapi/types/dist/modules/documents").AnyDocument>;
57
+ /**
58
+ * Find all chunks related to a parent document
59
+ * Returns chunks including the parent itself
60
+ */
61
+ findRelatedChunks(documentId: string): Promise<any[]>;
62
+ /**
63
+ * Delete all chunks related to a parent document
64
+ */
65
+ deleteRelatedChunks(documentId: string): Promise<number>;
66
+ /**
67
+ * Update embeddings with automatic chunking support
68
+ * Handles re-chunking when content changes and exceeds chunk size
69
+ */
70
+ updateChunkedEmbedding(id: string, data: UpdateEmbeddingData): Promise<ChunkedEmbeddingResult>;
71
+ updateEmbedding(id: string, data: UpdateEmbeddingData): Promise<any>;
31
72
  queryEmbeddings(query: string): Promise<import("../plugin-manager").QueryResponse | {
32
73
  error: string;
33
74
  }>;
@@ -2,12 +2,17 @@ declare const _default: {
2
2
  embeddings: ({ strapi }: {
3
3
  strapi: import("@strapi/types/dist/core").Strapi;
4
4
  }) => {
5
- createEmbedding(data: import("./embeddings").CreateEmbeddingData): Promise<import("@strapi/types/dist/modules/documents").AnyDocument>;
5
+ getConfig(): import("../config").PluginConfigSchema;
6
+ createEmbedding(data: import("./embeddings").CreateEmbeddingData): Promise<any>;
7
+ createChunkedEmbedding(data: import("./embeddings").CreateEmbeddingData): Promise<import("./embeddings").ChunkedEmbeddingResult>;
6
8
  deleteEmbedding(id: string | number): Promise<{
7
9
  documentId: string;
8
10
  entries: import("@strapi/types/dist/modules/documents").AnyDocument[];
9
11
  }>;
10
- updateEmbedding(id: string, data: import("./embeddings").UpdateEmbeddingData): Promise<import("@strapi/types/dist/modules/documents").AnyDocument>;
12
+ findRelatedChunks(documentId: string): Promise<any[]>;
13
+ deleteRelatedChunks(documentId: string): Promise<number>;
14
+ updateChunkedEmbedding(id: string, data: import("./embeddings").UpdateEmbeddingData): Promise<import("./embeddings").ChunkedEmbeddingResult>;
15
+ updateEmbedding(id: string, data: import("./embeddings").UpdateEmbeddingData): Promise<any>;
11
16
  queryEmbeddings(query: string): Promise<import("../plugin-manager").QueryResponse | {
12
17
  error: string;
13
18
  }>;
@@ -22,5 +27,21 @@ declare const _default: {
22
27
  totalCount: number;
23
28
  }>;
24
29
  };
30
+ sync: ({ strapi }: {
31
+ strapi: import("@strapi/types/dist/core").Strapi;
32
+ }) => {
33
+ syncFromNeon(options?: {
34
+ removeOrphans?: boolean;
35
+ dryRun?: boolean;
36
+ }): Promise<import("./sync").SyncResult>;
37
+ getSyncStatus(): Promise<{
38
+ neonCount: number;
39
+ strapiCount: number;
40
+ inSync: boolean;
41
+ missingInStrapi: number;
42
+ missingInNeon: number;
43
+ contentDifferences: number;
44
+ }>;
45
+ };
25
46
  };
26
47
  export default _default;
@@ -0,0 +1,48 @@
1
+ import type { Core } from "@strapi/strapi";
2
+ export interface SyncResult {
3
+ success: boolean;
4
+ timestamp: string;
5
+ neonCount: number;
6
+ strapiCount: number;
7
+ actions: {
8
+ created: number;
9
+ updated: number;
10
+ orphansRemoved: number;
11
+ };
12
+ details: {
13
+ created: string[];
14
+ updated: string[];
15
+ orphansRemoved: string[];
16
+ };
17
+ errors: string[];
18
+ }
19
+ declare const sync: ({ strapi }: {
20
+ strapi: Core.Strapi;
21
+ }) => {
22
+ /**
23
+ * Sync embeddings from Neon DB to Strapi DB
24
+ *
25
+ * This performs the following operations:
26
+ * 1. Fetches all embeddings from Neon DB (source of truth)
27
+ * 2. Fetches all embeddings from Strapi DB
28
+ * 3. Creates missing entries in Strapi that exist in Neon
29
+ * 4. Updates Strapi entries where content differs from Neon
30
+ * 5. Optionally removes orphaned Strapi entries (no matching Neon record)
31
+ */
32
+ syncFromNeon(options?: {
33
+ removeOrphans?: boolean;
34
+ dryRun?: boolean;
35
+ }): Promise<SyncResult>;
36
+ /**
37
+ * Get sync status - compare Neon and Strapi without making changes
38
+ */
39
+ getSyncStatus(): Promise<{
40
+ neonCount: number;
41
+ strapiCount: number;
42
+ inSync: boolean;
43
+ missingInStrapi: number;
44
+ missingInNeon: number;
45
+ contentDifferences: number;
46
+ }>;
47
+ };
48
+ export default sync;
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Text chunking utilities for splitting large content into embeddable chunks
3
+ */
4
+ export interface ChunkOptions {
5
+ /** Maximum characters per chunk (default: 4000, roughly ~1000 tokens) */
6
+ chunkSize?: number;
7
+ /** Number of characters to overlap between chunks (default: 200) */
8
+ chunkOverlap?: number;
9
+ /** Separator to use when splitting (default: splits on paragraphs, sentences, then words) */
10
+ separators?: string[];
11
+ }
12
+ export interface TextChunk {
13
+ /** The chunk text content */
14
+ text: string;
15
+ /** Zero-based chunk index */
16
+ chunkIndex: number;
17
+ /** Total number of chunks */
18
+ totalChunks: number;
19
+ /** Character offset in original text */
20
+ startOffset: number;
21
+ /** Character end offset in original text */
22
+ endOffset: number;
23
+ }
24
+ /**
25
+ * Estimate token count from character count
26
+ * OpenAI models average ~4 characters per token for English text
27
+ */
28
+ export declare function estimateTokens(text: string): number;
29
+ /**
30
+ * Check if content exceeds the recommended chunk size
31
+ */
32
+ export declare function needsChunking(content: string, maxChars?: number): boolean;
33
+ /**
34
+ * Split content into chunks suitable for embedding
35
+ *
36
+ * @param content - The text content to split
37
+ * @param options - Chunking options
38
+ * @returns Array of TextChunk objects
39
+ */
40
+ export declare function chunkContent(content: string, options?: ChunkOptions): TextChunk[];
41
+ /**
42
+ * Format chunk title with index information
43
+ */
44
+ export declare function formatChunkTitle(baseTitle: string, chunkIndex: number, totalChunks: number): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strapi-content-embeddings",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "Strapi v5 plugin for vector embeddings with OpenAI and Neon PostgreSQL. Enables semantic search, RAG chat, and MCP (Model Context Protocol) integration.",
5
5
  "keywords": [
6
6
  "strapi",