@n8n/ai-utilities 0.4.2 → 0.5.1

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 (123) hide show
  1. package/dist/cjs/index.d.ts +6 -0
  2. package/dist/cjs/index.js +18 -2
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/typecheck.tsbuildinfo +1 -1
  5. package/dist/cjs/utils/fromai-tool-factory.d.ts +14 -0
  6. package/dist/cjs/utils/fromai-tool-factory.js +45 -0
  7. package/dist/cjs/utils/fromai-tool-factory.js.map +1 -0
  8. package/dist/cjs/utils/shared-fields.d.ts +8 -0
  9. package/dist/cjs/utils/shared-fields.js +159 -0
  10. package/dist/cjs/utils/shared-fields.js.map +1 -0
  11. package/dist/cjs/utils/vector-store/MemoryManager/MemoryCalculator.d.ts +7 -0
  12. package/dist/cjs/utils/vector-store/MemoryManager/MemoryCalculator.js +60 -0
  13. package/dist/cjs/utils/vector-store/MemoryManager/MemoryCalculator.js.map +1 -0
  14. package/dist/cjs/utils/vector-store/MemoryManager/MemoryVectorStoreManager.d.ts +34 -0
  15. package/dist/cjs/utils/vector-store/MemoryManager/MemoryVectorStoreManager.js +186 -0
  16. package/dist/cjs/utils/vector-store/MemoryManager/MemoryVectorStoreManager.js.map +1 -0
  17. package/dist/cjs/utils/vector-store/MemoryManager/StoreCleanupService.d.ts +16 -0
  18. package/dist/cjs/utils/vector-store/MemoryManager/StoreCleanupService.js +105 -0
  19. package/dist/cjs/utils/vector-store/MemoryManager/StoreCleanupService.js.map +1 -0
  20. package/dist/cjs/utils/vector-store/MemoryManager/config.d.ts +4 -0
  21. package/dist/cjs/utils/vector-store/MemoryManager/config.js +48 -0
  22. package/dist/cjs/utils/vector-store/MemoryManager/config.js.map +1 -0
  23. package/dist/cjs/utils/vector-store/MemoryManager/types.d.ts +39 -0
  24. package/dist/cjs/utils/vector-store/MemoryManager/types.js +13 -0
  25. package/dist/cjs/utils/vector-store/MemoryManager/types.js.map +1 -0
  26. package/dist/cjs/utils/vector-store/createVectorStoreNode/constants.d.ts +4 -0
  27. package/dist/cjs/utils/vector-store/createVectorStoreNode/constants.js +55 -0
  28. package/dist/cjs/utils/vector-store/createVectorStoreNode/constants.js.map +1 -0
  29. package/dist/cjs/utils/vector-store/createVectorStoreNode/createVectorStoreNode.d.ts +18 -0
  30. package/dist/cjs/utils/vector-store/createVectorStoreNode/createVectorStoreNode.js +294 -0
  31. package/dist/cjs/utils/vector-store/createVectorStoreNode/createVectorStoreNode.js.map +1 -0
  32. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/index.d.ts +6 -0
  33. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/index.js +33 -0
  34. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/index.js.map +1 -0
  35. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/insertOperation.d.ts +5 -0
  36. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/insertOperation.js +48 -0
  37. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/insertOperation.js.map +1 -0
  38. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/loadOperation.d.ts +5 -0
  39. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/loadOperation.js +55 -0
  40. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/loadOperation.js.map +1 -0
  41. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolExecuteOperation.d.ts +5 -0
  42. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolExecuteOperation.js +74 -0
  43. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolExecuteOperation.js.map +1 -0
  44. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolOperation.d.ts +5 -0
  45. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolOperation.js +70 -0
  46. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolOperation.js.map +1 -0
  47. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/retrieveOperation.d.ts +5 -0
  48. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/retrieveOperation.js +39 -0
  49. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/retrieveOperation.js.map +1 -0
  50. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/updateOperation.d.ts +5 -0
  51. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/updateOperation.js +49 -0
  52. package/dist/cjs/utils/vector-store/createVectorStoreNode/operations/updateOperation.js.map +1 -0
  53. package/dist/cjs/utils/vector-store/createVectorStoreNode/types.d.ts +39 -0
  54. package/dist/cjs/utils/vector-store/createVectorStoreNode/types.js +13 -0
  55. package/dist/cjs/utils/vector-store/createVectorStoreNode/types.js.map +1 -0
  56. package/dist/cjs/utils/vector-store/createVectorStoreNode/utils.d.ts +6 -0
  57. package/dist/cjs/utils/vector-store/createVectorStoreNode/utils.js +30 -0
  58. package/dist/cjs/utils/vector-store/createVectorStoreNode/utils.js.map +1 -0
  59. package/dist/cjs/utils/vector-store/processDocuments.d.ts +25 -0
  60. package/dist/cjs/utils/vector-store/processDocuments.js +52 -0
  61. package/dist/cjs/utils/vector-store/processDocuments.js.map +1 -0
  62. package/dist/esm/index.d.ts +6 -0
  63. package/dist/esm/index.js +17 -1
  64. package/dist/esm/index.js.map +1 -1
  65. package/dist/esm/typecheck.tsbuildinfo +1 -1
  66. package/dist/esm/utils/fromai-tool-factory.d.ts +14 -0
  67. package/dist/esm/utils/fromai-tool-factory.js +35 -0
  68. package/dist/esm/utils/fromai-tool-factory.js.map +1 -0
  69. package/dist/esm/utils/shared-fields.d.ts +8 -0
  70. package/dist/esm/utils/shared-fields.js +149 -0
  71. package/dist/esm/utils/shared-fields.js.map +1 -0
  72. package/dist/esm/utils/vector-store/MemoryManager/MemoryCalculator.d.ts +7 -0
  73. package/dist/esm/utils/vector-store/MemoryManager/MemoryCalculator.js +50 -0
  74. package/dist/esm/utils/vector-store/MemoryManager/MemoryCalculator.js.map +1 -0
  75. package/dist/esm/utils/vector-store/MemoryManager/MemoryVectorStoreManager.d.ts +34 -0
  76. package/dist/esm/utils/vector-store/MemoryManager/MemoryVectorStoreManager.js +176 -0
  77. package/dist/esm/utils/vector-store/MemoryManager/MemoryVectorStoreManager.js.map +1 -0
  78. package/dist/esm/utils/vector-store/MemoryManager/StoreCleanupService.d.ts +16 -0
  79. package/dist/esm/utils/vector-store/MemoryManager/StoreCleanupService.js +95 -0
  80. package/dist/esm/utils/vector-store/MemoryManager/StoreCleanupService.js.map +1 -0
  81. package/dist/esm/utils/vector-store/MemoryManager/config.d.ts +4 -0
  82. package/dist/esm/utils/vector-store/MemoryManager/config.js +38 -0
  83. package/dist/esm/utils/vector-store/MemoryManager/config.js.map +1 -0
  84. package/dist/esm/utils/vector-store/MemoryManager/types.d.ts +39 -0
  85. package/dist/esm/utils/vector-store/MemoryManager/types.js +3 -0
  86. package/dist/esm/utils/vector-store/MemoryManager/types.js.map +1 -0
  87. package/dist/esm/utils/vector-store/createVectorStoreNode/constants.d.ts +4 -0
  88. package/dist/esm/utils/vector-store/createVectorStoreNode/constants.js +45 -0
  89. package/dist/esm/utils/vector-store/createVectorStoreNode/constants.js.map +1 -0
  90. package/dist/esm/utils/vector-store/createVectorStoreNode/createVectorStoreNode.d.ts +18 -0
  91. package/dist/esm/utils/vector-store/createVectorStoreNode/createVectorStoreNode.js +284 -0
  92. package/dist/esm/utils/vector-store/createVectorStoreNode/createVectorStoreNode.js.map +1 -0
  93. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/index.d.ts +6 -0
  94. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/index.js +23 -0
  95. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/index.js.map +1 -0
  96. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/insertOperation.d.ts +5 -0
  97. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/insertOperation.js +38 -0
  98. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/insertOperation.js.map +1 -0
  99. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/loadOperation.d.ts +5 -0
  100. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/loadOperation.js +45 -0
  101. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/loadOperation.js.map +1 -0
  102. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolExecuteOperation.d.ts +5 -0
  103. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolExecuteOperation.js +64 -0
  104. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolExecuteOperation.js.map +1 -0
  105. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolOperation.d.ts +5 -0
  106. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolOperation.js +60 -0
  107. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolOperation.js.map +1 -0
  108. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/retrieveOperation.d.ts +5 -0
  109. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/retrieveOperation.js +29 -0
  110. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/retrieveOperation.js.map +1 -0
  111. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/updateOperation.d.ts +5 -0
  112. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/updateOperation.js +39 -0
  113. package/dist/esm/utils/vector-store/createVectorStoreNode/operations/updateOperation.js.map +1 -0
  114. package/dist/esm/utils/vector-store/createVectorStoreNode/types.d.ts +39 -0
  115. package/dist/esm/utils/vector-store/createVectorStoreNode/types.js +3 -0
  116. package/dist/esm/utils/vector-store/createVectorStoreNode/types.js.map +1 -0
  117. package/dist/esm/utils/vector-store/createVectorStoreNode/utils.d.ts +6 -0
  118. package/dist/esm/utils/vector-store/createVectorStoreNode/utils.js +20 -0
  119. package/dist/esm/utils/vector-store/createVectorStoreNode/utils.js.map +1 -0
  120. package/dist/esm/utils/vector-store/processDocuments.d.ts +25 -0
  121. package/dist/esm/utils/vector-store/processDocuments.js +42 -0
  122. package/dist/esm/utils/vector-store/processDocuments.js.map +1 -0
  123. package/package.json +9 -6
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleRetrieveAsToolExecuteOperation = handleRetrieveAsToolExecuteOperation;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const helpers_1 = require("../../../helpers");
6
+ const log_ai_event_1 = require("../../../log-ai-event");
7
+ async function handleRetrieveAsToolExecuteOperation(context, args, embeddings, itemIndex) {
8
+ const filter = (0, helpers_1.getMetadataFiltersValues)(context, itemIndex);
9
+ const vectorStore = await args.getVectorStoreClient(context, undefined, embeddings, itemIndex);
10
+ try {
11
+ const inputData = context.getInputData();
12
+ const item = inputData[itemIndex];
13
+ const query = typeof item.json.input === 'string' ? item.json.input : undefined;
14
+ if (!query || typeof query !== 'string') {
15
+ throw new Error('Input data must contain a "input" field with the search query');
16
+ }
17
+ const topK = context.getNodeParameter('topK', itemIndex, 4);
18
+ (0, n8n_workflow_1.assertParamIsNumber)('topK', topK, context.getNode());
19
+ const useReranker = context.getNodeParameter('useReranker', itemIndex, false);
20
+ (0, n8n_workflow_1.assertParamIsBoolean)('useReranker', useReranker, context.getNode());
21
+ const includeDocumentMetadata = context.getNodeParameter('includeDocumentMetadata', itemIndex, true);
22
+ (0, n8n_workflow_1.assertParamIsBoolean)('includeDocumentMetadata', includeDocumentMetadata, context.getNode());
23
+ const embeddedQuery = await embeddings.embedQuery(query);
24
+ let docs = await vectorStore.similaritySearchVectorWithScore(embeddedQuery, topK, filter);
25
+ if (useReranker && docs.length > 0) {
26
+ const reranker = (await context.getInputConnectionData(n8n_workflow_1.NodeConnectionTypes.AiReranker, 0));
27
+ const documents = docs.map(([doc]) => doc);
28
+ const rerankedDocuments = await reranker.compressDocuments(documents, query);
29
+ docs = rerankedDocuments.map((doc) => {
30
+ const { relevanceScore, ...metadata } = doc.metadata || {};
31
+ return [{ ...doc, metadata }, relevanceScore ?? 0];
32
+ });
33
+ }
34
+ const serializedDocs = docs.map(([doc]) => {
35
+ if (includeDocumentMetadata) {
36
+ return {
37
+ type: 'text',
38
+ text: JSON.stringify({ ...doc }),
39
+ };
40
+ }
41
+ else {
42
+ return {
43
+ type: 'text',
44
+ pageContent: JSON.stringify({ pageContent: doc.pageContent }),
45
+ };
46
+ }
47
+ });
48
+ (0, log_ai_event_1.logAiEvent)(context, 'ai-vector-store-searched', { input: query });
49
+ return [
50
+ {
51
+ json: {
52
+ response: serializedDocs,
53
+ },
54
+ pairedItem: {
55
+ item: itemIndex,
56
+ },
57
+ },
58
+ ];
59
+ }
60
+ finally {
61
+ args.releaseVectorStoreClient?.(vectorStore);
62
+ }
63
+ }
64
+ //# sourceMappingURL=retrieveAsToolExecuteOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrieveAsToolExecuteOperation.js","sourceRoot":"","sources":["../../../../../../src/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolExecuteOperation.ts"],"names":[],"mappings":";;AAeA,oFA0FC;AAtGD,+CAA8F;AAG9F,8CAA4D;AAC5D,wDAAmD;AAQ5C,KAAK,UAAU,oCAAoC,CACzD,OAA0B,EAC1B,IAAuC,EACvC,UAAsB,EACtB,SAAiB;IAEjB,MAAM,MAAM,GAAG,IAAA,kCAAwB,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC5D,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAClD,OAAO,EAEP,SAAS,EACT,UAAU,EACV,SAAS,CACT,CAAC;IAEF,IAAI,CAAC;QAEJ,MAAM,SAAS,GAAG,OAAO,CAAC,YAAY,EAAE,CAAC;QACzC,MAAM,IAAI,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC;QAClC,MAAM,KAAK,GAAG,OAAO,IAAI,CAAC,IAAI,CAAC,KAAK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'@langchain/core/vectorstores';
3
+ import type { ISupplyDataFunctions, SupplyData } from 'n8n-workflow';
4
+ import type { VectorStoreNodeConstructorArgs } from '../types';
5
+ export declare function handleRetrieveAsToolOperation<T extends VectorStore = VectorStore>(context: ISupplyDataFunctions, args: VectorStoreNodeConstructorArgs<T>, embeddings: Embeddings, itemIndex: number): Promise<SupplyData>;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleRetrieveAsToolOperation = handleRetrieveAsToolOperation;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const fromai_tool_factory_1 = require("../../../fromai-tool-factory");
6
+ const helpers_1 = require("../../../helpers");
7
+ const log_wrapper_1 = require("../../../log-wrapper");
8
+ async function handleRetrieveAsToolOperation(context, args, embeddings, itemIndex) {
9
+ const toolDescription = context.getNodeParameter('toolDescription', itemIndex);
10
+ const node = context.getNode();
11
+ const { typeVersion } = node;
12
+ const toolName = typeVersion < 1.3
13
+ ? context.getNodeParameter('toolName', itemIndex)
14
+ : (0, n8n_workflow_1.nodeNameToToolName)(node);
15
+ const vectorStoreTool = (0, fromai_tool_factory_1.createToolFromNode)(node, {
16
+ name: toolName,
17
+ description: toolDescription,
18
+ extraArgs: [{ key: 'input', description: 'Query to search for. Required' }],
19
+ func: async (query) => {
20
+ const topK = context.getNodeParameter('topK', itemIndex, 4);
21
+ const useReranker = context.getNodeParameter('useReranker', itemIndex, false);
22
+ const includeDocumentMetadata = context.getNodeParameter('includeDocumentMetadata', itemIndex, true);
23
+ const filter = (0, helpers_1.getMetadataFiltersValues)(context, itemIndex);
24
+ const queryString = typeof query === 'string' ? query : query.input;
25
+ (0, n8n_workflow_1.assert)(typeof queryString === 'string', 'Query must be of type string');
26
+ const vectorStore = await args.getVectorStoreClient(context, undefined, embeddings, itemIndex);
27
+ try {
28
+ const embeddedPrompt = await embeddings.embedQuery(queryString);
29
+ let documents = await vectorStore.similaritySearchVectorWithScore(embeddedPrompt, topK, filter);
30
+ if (useReranker && documents.length > 0) {
31
+ const reranker = (await context.getInputConnectionData(n8n_workflow_1.NodeConnectionTypes.AiReranker, 0));
32
+ const docs = documents.map(([doc]) => doc);
33
+ const rerankedDocuments = await reranker.compressDocuments(docs, queryString);
34
+ documents = rerankedDocuments.map((doc) => {
35
+ const { relevanceScore, ...metadata } = doc.metadata;
36
+ return [{ ...doc, metadata }, relevanceScore];
37
+ });
38
+ }
39
+ return documents
40
+ .map((document) => {
41
+ if (includeDocumentMetadata) {
42
+ return { type: 'text', text: JSON.stringify(document[0]) };
43
+ }
44
+ return {
45
+ type: 'text',
46
+ text: JSON.stringify({ pageContent: document[0].pageContent }),
47
+ };
48
+ })
49
+ .filter((document) => !!document);
50
+ }
51
+ finally {
52
+ args.releaseVectorStoreClient?.(vectorStore);
53
+ }
54
+ },
55
+ });
56
+ return {
57
+ response: (0, log_wrapper_1.logWrapper)(vectorStoreTool, context),
58
+ };
59
+ }
60
+ //# sourceMappingURL=retrieveAsToolOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrieveAsToolOperation.js","sourceRoot":"","sources":["../../../../../../src/utils/vector-store/createVectorStoreNode/operations/retrieveAsToolOperation.ts"],"names":[],"mappings":";;AAeA,sEAgGC;AA5GD,+CAA+E;AAG/E,sEAAkE;AAClE,8CAA4D;AAC5D,sDAAkD;AAO3C,KAAK,UAAU,6BAA6B,CAClD,OAA6B,EAC7B,IAAuC,EACvC,UAAsB,EACtB,SAAiB;IAGjB,MAAM,eAAe,GAAG,OAAO,CAAC,gBAAgB,CAAC,iBAAiB,EAAE,SAAS,CAAW,CAAC;IAEzF,MAAM,IAAI,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAC/B,MAAM,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;IAC7B,MAAM,QAAQ,GACb,WAAW,GAAG,GAAG;QAChB,CAAC,CAAE,OAAO,CAAC,gBAAgB,CAAC,UAAU,EAAE,SAAS,CAAY;QAC7D,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AAC,eAAe,EAAE,OAAO,CAAC;KAC9C,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Embeddings } from '@langchain/core/embeddings';
2
+ import type { VectorStore } from '@langchain/core/vectorstores';
3
+ import type { ISupplyDataFunctions, SupplyData } from 'n8n-workflow';
4
+ import type { VectorStoreNodeConstructorArgs } from '../types';
5
+ export declare function handleRetrieveOperation<T extends VectorStore = VectorStore>(context: ISupplyDataFunctions, args: VectorStoreNodeConstructorArgs<T>, embeddings: Embeddings, itemIndex: number): Promise<SupplyData>;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleRetrieveOperation = handleRetrieveOperation;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const helpers_1 = require("../../../helpers");
6
+ const log_wrapper_1 = require("../../../log-wrapper");
7
+ async function handleRetrieveOperation(context, args, embeddings, itemIndex) {
8
+ const filter = (0, helpers_1.getMetadataFiltersValues)(context, itemIndex);
9
+ const useReranker = context.getNodeParameter('useReranker', itemIndex, false);
10
+ const vectorStore = await args.getVectorStoreClient(context, filter, embeddings, itemIndex);
11
+ let response = vectorStore;
12
+ if (useReranker) {
13
+ const reranker = (await context.getInputConnectionData(n8n_workflow_1.NodeConnectionTypes.AiReranker, 0));
14
+ response = {
15
+ reranker,
16
+ vectorStore: (0, log_wrapper_1.logWrapper)(vectorStore, context),
17
+ };
18
+ }
19
+ else {
20
+ response = (0, log_wrapper_1.logWrapper)(vectorStore, context);
21
+ }
22
+ return {
23
+ response,
24
+ closeFunction: async () => {
25
+ args.releaseVectorStoreClient?.(vectorStore);
26
+ },
27
+ };
28
+ }
29
+ //# sourceMappingURL=retrieveOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"retrieveOperation.js","sourceRoot":"","sources":["../../../../../../src/utils/vector-store/createVectorStoreNode/operations/retrieveOperation.ts"],"names":[],"mappings":";;AAcA,0DAsCC;AAjDD,+CAAmD;AAGnD,8CAA4D;AAC5D,sDAAkD;AAO3C,KAAK,UAAU,uBAAuB,CAC5C,OAA6B,EAC7B,IAAuC,EACvC,UAAsB,EACtB,SAAiB;IAGjB,MAAM,MAAM,GAAG,IAAA,kCAAwB,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IAC5D,MAAM,WAAW,GAAG,OAAO,CAAC,gBAAgB,CAAC,aAAa,EAAE,SAAS,EAAE,KAAK,CAAY,CAAC;IAGzF,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,SAAS,CAAC,CAAC;IAC5F,IAAI,QAAQ,GACX,WAAW,CAAC;IAEb,IAAI,WAAW,EAAE,CAAC;QACjB,MAAM,QAAQ,GAAG,CAAC,MAAM,OAAO,CAAC,sBAAsB,CACrD,kCAAmB,CAAC,UAAU,EAC9B,CAAC,CACD,CAA2B,CAAC;QAG7B,QAAQ,GAAG;YACV,QAAQ;YACR,WAAW,EAAE,IAAA,wBAAU,EAAC,WAAW,EAAE,OAAO,CAAC;SAC7C,CAAC;IACH,CAAC;SAAM,CAAC;QAEP,QAAQ,GAAG,IAAA,wBAAU,EAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO;QACN,QAAQ;QACR,aAAa,EAAE,KAAK,IAAI,EAAE;YAEzB,IAAI,CAAC,wBAAwB,EAAE,CAAC,WAAW,CAAC,CAAC;QAC9C,CAAC;KACD,CAAC;AACH,CAAC"}
@@ -0,0 +1,5 @@
1
+ import type { Embeddings } from '@langchain/core/embeddings';
2
+ import type { VectorStore } from '@langchain/core/vectorstores';
3
+ import type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';
4
+ import type { VectorStoreNodeConstructorArgs } from '../types';
5
+ export declare function handleUpdateOperation<T extends VectorStore = VectorStore>(context: IExecuteFunctions, args: VectorStoreNodeConstructorArgs<T>, embeddings: Embeddings): Promise<INodeExecutionData[]>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.handleUpdateOperation = handleUpdateOperation;
4
+ const n8n_workflow_1 = require("n8n-workflow");
5
+ const log_ai_event_1 = require("../../../log-ai-event");
6
+ const n8n_json_loader_1 = require("../../../n8n-json-loader");
7
+ const processDocuments_1 = require("../../processDocuments");
8
+ const utils_1 = require("../utils");
9
+ async function handleUpdateOperation(context, args, embeddings) {
10
+ if (!(0, utils_1.isUpdateSupported)(args)) {
11
+ throw new n8n_workflow_1.NodeOperationError(context.getNode(), 'Update operation is not implemented for this Vector Store');
12
+ }
13
+ const items = context.getInputData();
14
+ const loader = new n8n_json_loader_1.N8nJsonLoader(context);
15
+ const resultData = [];
16
+ for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
17
+ const itemData = items[itemIndex];
18
+ const documentId = context.getNodeParameter('id', itemIndex, '', {
19
+ extractValue: true,
20
+ });
21
+ const vectorStore = await args.getVectorStoreClient(context, undefined, embeddings, itemIndex);
22
+ try {
23
+ const { processedDocuments, serializedDocuments } = await (0, processDocuments_1.processDocument)(loader, itemData, itemIndex);
24
+ if (processedDocuments?.length !== 1) {
25
+ throw new n8n_workflow_1.NodeOperationError(context.getNode(), 'Single document per item expected');
26
+ }
27
+ resultData.push(...serializedDocuments);
28
+ await vectorStore.addDocuments(processedDocuments, {
29
+ ids: [documentId],
30
+ });
31
+ (0, log_ai_event_1.logAiEvent)(context, 'ai-vector-store-updated');
32
+ }
33
+ finally {
34
+ args.releaseVectorStoreClient?.(vectorStore);
35
+ }
36
+ }
37
+ return resultData;
38
+ }
39
+ //# sourceMappingURL=updateOperation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"updateOperation.js","sourceRoot":"","sources":["../../../../../../src/utils/vector-store/createVectorStoreNode/operations/updateOperation.ts"],"names":[],"mappings":";;AAeA,sDA8DC;AA3ED,+CAAkD;AAGlD,wDAAmD;AACnD,8DAAyD;AACzD,6DAAyD;AAEzD,o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jB,CAAC,CAAC;YAGH,IAAA,yBAAU,EAAC,OAAO,EAAE,yBAAyB,CAAC,CAAC;QAChD,CAAC;gBAAS,CAAC;YAEV,IAAI,CAAC,wBAAwB,EAAE,CAAC,WAAW,CAAC,CAAC;QAC9C,CAAC;IACF,CAAC;IAED,OAAO,UAAU,CAAC;AACnB,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { Document } from '@langchain/core/documents';
2
+ import type { Embeddings } from '@langchain/core/embeddings';
3
+ import type { VectorStore } from '@langchain/core/vectorstores';
4
+ import type { IExecuteFunctions, INodeCredentialDescription, INodeProperties, ILoadOptionsFunctions, INodeListSearchResult, Icon, ISupplyDataFunctions, ThemeIconColor, IDataObject, NodeParameterValueType, IBuilderHint } from 'n8n-workflow';
5
+ export type NodeOperationMode = 'insert' | 'load' | 'retrieve' | 'update' | 'retrieve-as-tool';
6
+ export interface NodeMeta {
7
+ displayName: string;
8
+ name: string;
9
+ hidden?: boolean;
10
+ description: string;
11
+ docsUrl: string;
12
+ icon: Icon;
13
+ iconColor?: ThemeIconColor;
14
+ credentials?: INodeCredentialDescription[];
15
+ operationModes?: NodeOperationMode[];
16
+ categories?: string[];
17
+ subcategories?: Record<string, string[]>;
18
+ builderHint?: IBuilderHint;
19
+ }
20
+ export interface VectorStoreNodeConstructorArgs<T extends VectorStore = VectorStore> {
21
+ meta: NodeMeta;
22
+ methods?: {
23
+ listSearch?: {
24
+ [key: string]: (this: ILoadOptionsFunctions, filter?: string, paginationToken?: string) => Promise<INodeListSearchResult>;
25
+ };
26
+ actionHandler?: {
27
+ [functionName: string]: (this: ILoadOptionsFunctions, payload: IDataObject | string | undefined) => Promise<NodeParameterValueType>;
28
+ };
29
+ };
30
+ sharedFields: INodeProperties[];
31
+ insertFields?: INodeProperties[];
32
+ loadFields?: INodeProperties[];
33
+ retrieveFields?: INodeProperties[];
34
+ updateFields?: INodeProperties[];
35
+ beforeInsert?: (context: IExecuteFunctions | ISupplyDataFunctions, embeddings: Embeddings, itemIndex: number) => Promise<void>;
36
+ populateVectorStore: (context: IExecuteFunctions | ISupplyDataFunctions, embeddings: Embeddings, documents: Array<Document<Record<string, unknown>>>, itemIndex: number) => Promise<void>;
37
+ getVectorStoreClient: (context: IExecuteFunctions | ISupplyDataFunctions, filter: Record<string, never> | undefined, embeddings: Embeddings, itemIndex: number) => Promise<T>;
38
+ releaseVectorStoreClient?: (vectorStore: T) => void;
39
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/utils/vector-store/createVectorStoreNode/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ import type { VectorStore } from '@langchain/core/vectorstores';
2
+ import type { INodeProperties, INodePropertyOptions } from 'n8n-workflow';
3
+ import type { NodeOperationMode, VectorStoreNodeConstructorArgs } from './types';
4
+ export declare function transformDescriptionForOperationMode(fields: INodeProperties[], mode: NodeOperationMode | NodeOperationMode[]): INodeProperties[];
5
+ export declare function isUpdateSupported<T extends VectorStore>(args: VectorStoreNodeConstructorArgs<T>): boolean;
6
+ export declare function getOperationModeOptions<T extends VectorStore>(args: VectorStoreNodeConstructorArgs<T>): INodePropertyOptions[];
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.transformDescriptionForOperationMode = transformDescriptionForOperationMode;
4
+ exports.isUpdateSupported = isUpdateSupported;
5
+ exports.getOperationModeOptions = getOperationModeOptions;
6
+ const constants_1 = require("./constants");
7
+ function transformDescriptionForOperationMode(fields, mode) {
8
+ return fields.map((field) => ({
9
+ ...field,
10
+ displayOptions: { show: { mode: Array.isArray(mode) ? mode : [mode] } },
11
+ }));
12
+ }
13
+ function isUpdateSupported(args) {
14
+ return args.meta.operationModes?.includes('update') ?? false;
15
+ }
16
+ function getOperationModeOptions(args) {
17
+ const enabledOperationModes = args.meta.operationModes ?? constants_1.DEFAULT_OPERATION_MODES;
18
+ return constants_1.OPERATION_MODE_DESCRIPTIONS.filter(({ value }) => enabledOperationModes.includes(value));
19
+ }
20
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../../../src/utils/vector-store/createVectorStoreNode/utils.ts"],"names":[],"mappings":";;AAUA,oFAQC;AAMD,8CAIC;AAMD,0DAQC;AAvCD,2CAAmF;AAOnF,SAAgB,oCAAoC,CACnD,MAAyB,EACzB,IAA6C;IAE7C,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAC7B,GAAG,KAAK;QACR,cAAc,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE;KACvE,CAAC,CAAC,CAAC;AACL,CAAC;AAMD,SAAgB,iBAAiB,CAChC,IAAuC;IAEvC,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAC,QAAQ,CAAC,IAAI,KAAK,CAAC;AAC9D,CAAC;AAMD,SAAgB,uBAAuB,CACtC,IAAuC;IAEvC,MAAM,qBAAqB,GAAG,IAAI,CAAC,IAAI,CAAC,cAAc,IAAI,mCAAuB,CAAC;IAElF,OAAO,uCAA2B,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,CACvD,qBAAqB,CAAC,QAAQ,CAAC,KAA0B,CAAC,CAC1D,CAAC;AACH,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { Document } from '@langchain/core/documents';
2
+ import type { INodeExecutionData } from 'n8n-workflow';
3
+ import { N8nBinaryLoader } from '../n8n-binary-loader';
4
+ import { N8nJsonLoader } from '../n8n-json-loader';
5
+ export declare function processDocuments(documentInput: N8nJsonLoader | N8nBinaryLoader | Array<Document<Record<string, unknown>>>, inputItems: INodeExecutionData[]): Promise<{
6
+ processedDocuments: Document<Record<string, any>>[];
7
+ serializedDocuments: {
8
+ json: {
9
+ metadata: Record<string, any>;
10
+ pageContent: string;
11
+ };
12
+ }[];
13
+ }>;
14
+ export declare function processDocument(documentInput: N8nJsonLoader | N8nBinaryLoader | Array<Document<Record<string, unknown>>>, inputItem: INodeExecutionData, itemIndex: number): Promise<{
15
+ processedDocuments: Document<Record<string, any>>[];
16
+ serializedDocuments: {
17
+ json: {
18
+ metadata: Record<string, any>;
19
+ pageContent: string;
20
+ };
21
+ pairedItem: {
22
+ item: number;
23
+ };
24
+ }[];
25
+ }>;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.processDocuments = processDocuments;
4
+ exports.processDocument = processDocument;
5
+ const n8n_binary_loader_1 = require("../n8n-binary-loader");
6
+ const n8n_json_loader_1 = require("../n8n-json-loader");
7
+ async function processDocuments(documentInput, inputItems) {
8
+ let processedDocuments;
9
+ if (documentInput instanceof n8n_json_loader_1.N8nJsonLoader || documentInput instanceof n8n_binary_loader_1.N8nBinaryLoader) {
10
+ processedDocuments = await documentInput.processAll(inputItems);
11
+ }
12
+ else {
13
+ processedDocuments = documentInput;
14
+ }
15
+ const serializedDocuments = processedDocuments.map(({ metadata, pageContent }) => ({
16
+ json: { metadata, pageContent },
17
+ }));
18
+ return {
19
+ processedDocuments,
20
+ serializedDocuments,
21
+ };
22
+ }
23
+ async function processDocument(documentInput, inputItem, itemIndex) {
24
+ let processedDocuments;
25
+ if (documentInput instanceof n8n_json_loader_1.N8nJsonLoader || documentInput instanceof n8n_binary_loader_1.N8nBinaryLoader) {
26
+ processedDocuments = await documentInput.processItem(inputItem, itemIndex);
27
+ }
28
+ else {
29
+ processedDocuments = documentInput;
30
+ }
31
+ const serializedDocuments = processedDocuments.map(({ metadata, pageContent }) => ({
32
+ json: { metadata, pageContent },
33
+ pairedItem: {
34
+ item: itemIndex,
35
+ },
36
+ }));
37
+ return {
38
+ processedDocuments,
39
+ serializedDocuments,
40
+ };
41
+ }
42
+ //# sourceMappingURL=processDocuments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processDocuments.js","sourceRoot":"","sources":["../../../../src/utils/vector-store/processDocuments.ts"],"names":[],"mappings":";;AAMA,4CAoBC;AACD,0CAwBC;AAhDD,4DAAuD;AACvD,wDAAmD;AAE5C,KAAK,UAAU,gBAAgB,CACrC,aAAyF,EACzF,UAAgC;IAEhC,IAAI,kBAA8B,CAAC;IAEnC,IAAI,aAAa,YAAY,+BAAa,IAAI,aAAa,YAAY,mCAAe,EAAE,CAAC;QACxF,kBAAkB,GAAG,MAAM,aAAa,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC;IACjE,CAAC;SAAM,CAAC;QACP,kBAAkB,GAAG,aAAa,CAAC;IACpC,CAAC;IAED,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;QAClF,IAAI,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE;KAC/B,CAAC,CAAC,CAAC;IAEJ,OAAO;QACN,kBAAkB;QAClB,mBAAmB;KACnB,CAAC;AACH,CAAC;AACM,KAAK,UAAU,eAAe,CACpC,aAAyF,EACzF,SAA6B,EAC7B,SAAiB;IAEjB,IAAI,kBAA8B,CAAC;IAEnC,IAAI,aAAa,YAAY,+BAAa,IAAI,aAAa,YAAY,mCAAe,EAAE,CAAC;QACxF,kBAAkB,GAAG,MAAM,aAAa,CAAC,WAAW,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;IAC5E,CAAC;SAAM,CAAC;QACP,kBAAkB,GAAG,aAAa,CAAC;IACpC,CAAC;IAED,MAAM,mBAAmB,GAAG,kBAAkB,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;QAClF,IAAI,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE;QAC/B,UAAU,EAAE;YACX,IAAI,EAAE,SAAS;SACf;KACD,CAAC,CAAC,CAAC;IAEJ,OAAO;QACN,kBAAkB;QAClB,mBAAmB;KACnB,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@n8n/ai-utilities",
3
- "version": "0.4.2",
3
+ "version": "0.5.1",
4
4
  "description": "Utilities for building AI nodes in n8n",
5
5
  "types": "dist/esm/index.d.ts",
6
6
  "module": "dist/esm/index.js",
@@ -15,15 +15,16 @@
15
15
  },
16
16
  "files": [
17
17
  "dist",
18
- "LICENSE.md",
19
- "LICENSE_EE.md"
18
+ "LICENSE_EE.md",
19
+ "LICENSE.md"
20
20
  ],
21
21
  "devDependencies": {
22
22
  "@types/json-schema": "^7.0.15",
23
23
  "jest-mock-extended": "^3.0.4",
24
24
  "@types/mime-types": "3.0.1",
25
25
  "tsx": "^4.19.3",
26
- "axios": "1.13.5"
26
+ "axios": "1.13.5",
27
+ "n8n-workflow": "2.11.1"
27
28
  },
28
29
  "dependencies": {
29
30
  "zod": "3.25.67",
@@ -39,9 +40,11 @@
39
40
  "https-proxy-agent": "7.0.6",
40
41
  "proxy-from-env": "^1.1.0",
41
42
  "undici": "^6.21.0",
42
- "@n8n/config": "2.9.0",
43
43
  "@n8n/typescript-config": "1.3.0",
44
- "n8n-workflow": "2.10.2"
44
+ "@n8n/config": "2.10.1"
45
+ },
46
+ "peerDependencies": {
47
+ "n8n-workflow": "*"
45
48
  },
46
49
  "license": "SEE LICENSE IN LICENSE.md",
47
50
  "homepage": "https://n8n.io",