@n8n/n8n-nodes-langchain 1.96.1 → 1.97.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 (72) hide show
  1. package/dist/known/credentials.json +2 -1
  2. package/dist/known/nodes.json +4 -0
  3. package/dist/nodes/ToolExecutor/ToolExecutor.node.js.map +1 -1
  4. package/dist/nodes/ToolExecutor/utils/executeTool.js.map +1 -1
  5. package/dist/nodes/agents/Agent/V2/AgentV2.node.js +2 -1
  6. package/dist/nodes/agents/Agent/V2/AgentV2.node.js.map +1 -1
  7. package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/execute.js +12 -2
  8. package/dist/nodes/agents/Agent/agents/ToolsAgent/V1/execute.js.map +1 -1
  9. package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js +12 -2
  10. package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js.map +1 -1
  11. package/dist/nodes/agents/OpenAiAssistant/utils.js.map +1 -1
  12. package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js +9 -13
  13. package/dist/nodes/chains/InformationExtractor/InformationExtractor.node.js.map +1 -1
  14. package/dist/nodes/document_loaders/DocumentDefaultDataLoader/DocumentDefaultDataLoader.node.js +54 -13
  15. package/dist/nodes/document_loaders/DocumentDefaultDataLoader/DocumentDefaultDataLoader.node.js.map +1 -1
  16. package/dist/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.js +54 -12
  17. package/dist/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.js.map +1 -1
  18. package/dist/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.js +2 -2
  19. package/dist/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.js.map +1 -1
  20. package/dist/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.js +1 -1
  21. package/dist/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.js.map +1 -1
  22. package/dist/nodes/llms/N8nLlmTracing.js +12 -2
  23. package/dist/nodes/llms/N8nLlmTracing.js.map +1 -1
  24. package/dist/nodes/mcp/McpClientTool/utils.js +5 -2
  25. package/dist/nodes/mcp/McpClientTool/utils.js.map +1 -1
  26. package/dist/nodes/memory/MemoryManager/MemoryManager.node.js +20 -15
  27. package/dist/nodes/memory/MemoryManager/MemoryManager.node.js.map +1 -1
  28. package/dist/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.js +1 -1
  29. package/dist/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.js.map +1 -1
  30. package/dist/nodes/output_parser/OutputParserStructured/OutputParserStructured.node.js +94 -16
  31. package/dist/nodes/output_parser/OutputParserStructured/OutputParserStructured.node.js.map +1 -1
  32. package/dist/nodes/output_parser/OutputParserStructured/prompt.js +44 -0
  33. package/dist/nodes/output_parser/OutputParserStructured/prompt.js.map +1 -0
  34. package/dist/nodes/rerankers/RerankerCohere/RerankerCohere.node.js +107 -0
  35. package/dist/nodes/rerankers/RerankerCohere/RerankerCohere.node.js.map +1 -0
  36. package/dist/nodes/rerankers/RerankerCohere/cohere.dark.svg +5 -0
  37. package/dist/nodes/rerankers/RerankerCohere/cohere.svg +5 -0
  38. package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js +11 -1
  39. package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js.map +1 -1
  40. package/dist/nodes/tools/ToolCode/ToolCode.node.js +15 -4
  41. package/dist/nodes/tools/ToolCode/ToolCode.node.js.map +1 -1
  42. package/dist/nodes/tools/ToolWorkflow/v1/ToolWorkflowV1.node.js +1 -1
  43. package/dist/nodes/tools/ToolWorkflow/v1/ToolWorkflowV1.node.js.map +1 -1
  44. package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js +4 -3
  45. package/dist/nodes/tools/ToolWorkflow/v2/utils/WorkflowToolService.js.map +1 -1
  46. package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js +13 -3
  47. package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js.map +1 -1
  48. package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js +8 -2
  49. package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js.map +1 -1
  50. package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.js +23 -3
  51. package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.js.map +1 -1
  52. package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.js +15 -1
  53. package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.js.map +1 -1
  54. package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js +18 -2
  55. package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.js.map +1 -1
  56. package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.js +16 -1
  57. package/dist/nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.js.map +1 -1
  58. package/dist/nodes/vector_store/shared/createVectorStoreNode/types.js.map +1 -1
  59. package/dist/nodes/vendors/OpenAi/helpers/utils.js.map +1 -1
  60. package/dist/nodes/vendors/OpenAi/methods/listSearch.js +1 -1
  61. package/dist/nodes/vendors/OpenAi/methods/listSearch.js.map +1 -1
  62. package/dist/types/credentials.json +1 -1
  63. package/dist/types/nodes.json +19 -18
  64. package/dist/utils/descriptions.js +17 -2
  65. package/dist/utils/descriptions.js.map +1 -1
  66. package/dist/utils/logWrapper.js +23 -0
  67. package/dist/utils/logWrapper.js.map +1 -1
  68. package/dist/utils/output_parsers/N8nStructuredOutputParser.js +5 -1
  69. package/dist/utils/output_parsers/N8nStructuredOutputParser.js.map +1 -1
  70. package/dist/utils/schemaParsing.js +29 -5
  71. package/dist/utils/schemaParsing.js.map +1 -1
  72. package/package.json +10 -9
@@ -35,14 +35,16 @@ const createVectorStoreNode = (args) => class VectorStoreNodeType {
35
35
  iconColor: args.meta.iconColor,
36
36
  group: ["transform"],
37
37
  // 1.2 has changes to VectorStoreInMemory node.
38
- version: [1, 1.1, 1.2],
38
+ // 1.3 drops `toolName` and uses node name as the tool name.
39
+ version: [1, 1.1, 1.2, 1.3],
39
40
  defaults: {
40
41
  name: args.meta.displayName
41
42
  },
42
43
  codex: {
43
- categories: ["AI"],
44
- subcategories: {
44
+ categories: args.meta.categories ?? ["AI"],
45
+ subcategories: args.meta.subcategories ?? {
45
46
  AI: ["Vector Stores", "Tools", "Root Nodes"],
47
+ "Vector Stores": ["Other Vector Stores"],
46
48
  Tools: ["Other Tools"]
47
49
  },
48
50
  resources: {
@@ -58,8 +60,13 @@ const createVectorStoreNode = (args) => class VectorStoreNodeType {
58
60
  inputs: `={{
59
61
  ((parameters) => {
60
62
  const mode = parameters?.mode;
63
+ const useReranker = parameters?.useReranker;
61
64
  const inputs = [{ displayName: "Embedding", type: "${import_n8n_workflow.NodeConnectionTypes.AiEmbedding}", required: true, maxConnections: 1}]
62
65
 
66
+ if (['load', 'retrieve', 'retrieve-as-tool'].includes(mode) && useReranker) {
67
+ inputs.push({ displayName: "Reranker", type: "${import_n8n_workflow.NodeConnectionTypes.AiReranker}", required: true, maxConnections: 1})
68
+ }
69
+
63
70
  if (mode === 'retrieve-as-tool') {
64
71
  return inputs;
65
72
  }
@@ -116,6 +123,7 @@ const createVectorStoreNode = (args) => class VectorStoreNodeType {
116
123
  validateType: "string-alphanumeric",
117
124
  displayOptions: {
118
125
  show: {
126
+ "@version": [{ _cnd: { lte: 1.2 } }],
119
127
  mode: ["retrieve-as-tool"]
120
128
  }
121
129
  }
@@ -188,6 +196,18 @@ const createVectorStoreNode = (args) => class VectorStoreNodeType {
188
196
  }
189
197
  }
190
198
  },
199
+ {
200
+ displayName: "Rerank Results",
201
+ name: "useReranker",
202
+ type: "boolean",
203
+ default: false,
204
+ description: "Whether or not to rerank results",
205
+ displayOptions: {
206
+ show: {
207
+ mode: ["load", "retrieve", "retrieve-as-tool"]
208
+ }
209
+ }
210
+ },
191
211
  // ID is always used for update operation
192
212
  {
193
213
  displayName: "ID",
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-filename-against-convention */\n/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport type { Embeddings } from '@langchain/core/embeddings';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeTypeDescription,\n\tSupplyData,\n\tISupplyDataFunctions,\n\tINodeType,\n} from 'n8n-workflow';\n\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\n// Import custom types\nimport {\n\thandleLoadOperation,\n\thandleInsertOperation,\n\thandleUpdateOperation,\n\thandleRetrieveOperation,\n\thandleRetrieveAsToolOperation,\n} from './operations';\nimport type { NodeOperationMode, VectorStoreNodeConstructorArgs } from './types';\n// Import utility functions\nimport { transformDescriptionForOperationMode, getOperationModeOptions } from './utils';\n\n// Import operation handlers\n\n/**\n * Creates a vector store node with the given configuration\n * This factory function produces a complete node class that implements all vector store operations\n */\nexport const createVectorStoreNode = <T extends VectorStore = VectorStore>(\n\targs: VectorStoreNodeConstructorArgs<T>,\n) =>\n\tclass VectorStoreNodeType implements INodeType {\n\t\tdescription: INodeTypeDescription = {\n\t\t\tdisplayName: args.meta.displayName,\n\t\t\tname: args.meta.name,\n\t\t\tdescription: args.meta.description,\n\t\t\ticon: args.meta.icon,\n\t\t\ticonColor: args.meta.iconColor,\n\t\t\tgroup: ['transform'],\n\t\t\t// 1.2 has changes to VectorStoreInMemory node.\n\t\t\tversion: [1, 1.1, 1.2],\n\t\t\tdefaults: {\n\t\t\t\tname: args.meta.displayName,\n\t\t\t},\n\t\t\tcodex: {\n\t\t\t\tcategories: ['AI'],\n\t\t\t\tsubcategories: {\n\t\t\t\t\tAI: ['Vector Stores', 'Tools', 'Root Nodes'],\n\t\t\t\t\tTools: ['Other Tools'],\n\t\t\t\t},\n\t\t\t\tresources: {\n\t\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\turl: args.meta.docsUrl,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t\tcredentials: args.meta.credentials,\n\t\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\t\tinputs: `={{\n\t\t\t((parameters) => {\n\t\t\t\tconst mode = parameters?.mode;\n\t\t\t\tconst inputs = [{ displayName: \"Embedding\", type: \"${NodeConnectionTypes.AiEmbedding}\", required: true, maxConnections: 1}]\n\n\t\t\t\tif (mode === 'retrieve-as-tool') {\n\t\t\t\t\treturn inputs;\n\t\t\t\t}\n\n\t\t\t\tif (['insert', 'load', 'update'].includes(mode)) {\n\t\t\t\t\tinputs.push({ displayName: \"\", type: \"${NodeConnectionTypes.Main}\"})\n\t\t\t\t}\n\n\t\t\t\tif (['insert'].includes(mode)) {\n\t\t\t\t\tinputs.push({ displayName: \"Document\", type: \"${NodeConnectionTypes.AiDocument}\", required: true, maxConnections: 1})\n\t\t\t\t}\n\t\t\t\treturn inputs\n\t\t\t})($parameter)\n\t\t}}`,\n\t\t\toutputs: `={{\n\t\t\t((parameters) => {\n\t\t\t\tconst mode = parameters?.mode ?? 'retrieve';\n\n\t\t\t\tif (mode === 'retrieve-as-tool') {\n\t\t\t\t\treturn [{ displayName: \"Tool\", type: \"${NodeConnectionTypes.AiTool}\"}]\n\t\t\t\t}\n\n\t\t\t\tif (mode === 'retrieve') {\n\t\t\t\t\treturn [{ displayName: \"Vector Store\", type: \"${NodeConnectionTypes.AiVectorStore}\"}]\n\t\t\t\t}\n\t\t\t\treturn [{ displayName: \"\", type: \"${NodeConnectionTypes.Main}\"}]\n\t\t\t})($parameter)\n\t\t}}`,\n\t\t\tproperties: [\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Operation Mode',\n\t\t\t\t\tname: 'mode',\n\t\t\t\t\ttype: 'options',\n\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\tdefault: 'retrieve',\n\t\t\t\t\toptions: getOperationModeOptions(args),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t...getConnectionHintNoticeField([NodeConnectionTypes.AiRetriever]),\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['retrieve'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Name',\n\t\t\t\t\tname: 'toolName',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefault: '',\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: 'Name of the vector store',\n\t\t\t\t\tplaceholder: 'e.g. company_knowledge_base',\n\t\t\t\t\tvalidateType: 'string-alphanumeric',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['retrieve-as-tool'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Description',\n\t\t\t\t\tname: 'toolDescription',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefault: '',\n\t\t\t\t\trequired: true,\n\t\t\t\t\ttypeOptions: { rows: 2 },\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Explain to the LLM what this tool does, a good, specific description would allow LLMs to produce expected results much more often',\n\t\t\t\t\tplaceholder: `e.g. ${args.meta.description}`,\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['retrieve-as-tool'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...args.sharedFields,\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Embedding Batch Size',\n\t\t\t\t\tname: 'embeddingBatchSize',\n\t\t\t\t\ttype: 'number',\n\t\t\t\t\tdefault: 200,\n\t\t\t\t\tdescription: 'Number of documents to embed in a single batch',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['insert'],\n\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.1 } }],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...transformDescriptionForOperationMode(args.insertFields ?? [], 'insert'),\n\t\t\t\t// Prompt and topK are always used for the load operation\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Prompt',\n\t\t\t\t\tname: 'prompt',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefault: '',\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Search prompt to retrieve matching documents from the vector store using similarity-based ranking',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['load'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Limit',\n\t\t\t\t\tname: 'topK',\n\t\t\t\t\ttype: 'number',\n\t\t\t\t\tdefault: 4,\n\t\t\t\t\tdescription: 'Number of top results to fetch from vector store',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['load', 'retrieve-as-tool'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Include Metadata',\n\t\t\t\t\tname: 'includeDocumentMetadata',\n\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\tdefault: true,\n\t\t\t\t\tdescription: 'Whether or not to include document metadata',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['load', 'retrieve-as-tool'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t// ID is always used for update operation\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'ID',\n\t\t\t\t\tname: 'id',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefault: '',\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: 'ID of an embedding entry',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['update'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...transformDescriptionForOperationMode(args.loadFields ?? [], [\n\t\t\t\t\t'load',\n\t\t\t\t\t'retrieve-as-tool',\n\t\t\t\t]),\n\t\t\t\t...transformDescriptionForOperationMode(args.retrieveFields ?? [], 'retrieve'),\n\t\t\t\t...transformDescriptionForOperationMode(args.updateFields ?? [], 'update'),\n\t\t\t],\n\t\t};\n\n\t\tmethods = args.methods;\n\n\t\t/**\n\t\t * Method to execute the node in regular workflow mode\n\t\t * Supports 'load', 'insert', and 'update' operation modes\n\t\t */\n\t\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\t\tconst mode = this.getNodeParameter('mode', 0) as NodeOperationMode;\n\n\t\t\t// Get the embeddings model connected to this node\n\t\t\tconst embeddings = (await this.getInputConnectionData(\n\t\t\t\tNodeConnectionTypes.AiEmbedding,\n\t\t\t\t0,\n\t\t\t)) as Embeddings;\n\n\t\t\t// Handle each operation mode with dedicated modules\n\t\t\tif (mode === 'load') {\n\t\t\t\tconst items = this.getInputData(0);\n\t\t\t\tconst resultData = [];\n\n\t\t\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\t\t\tconst docs = await handleLoadOperation(this, args, embeddings, itemIndex);\n\t\t\t\t\tresultData.push(...docs);\n\t\t\t\t}\n\n\t\t\t\treturn [resultData];\n\t\t\t}\n\n\t\t\tif (mode === 'insert') {\n\t\t\t\tconst resultData = await handleInsertOperation(this, args, embeddings);\n\t\t\t\treturn [resultData];\n\t\t\t}\n\n\t\t\tif (mode === 'update') {\n\t\t\t\tconst resultData = await handleUpdateOperation(this, args, embeddings);\n\t\t\t\treturn [resultData];\n\t\t\t}\n\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Only the \"load\", \"update\" and \"insert\" operation modes are supported with execute',\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Method to supply data to AI nodes\n\t\t * Supports 'retrieve' and 'retrieve-as-tool' operation modes\n\t\t */\n\t\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\t\tconst mode = this.getNodeParameter('mode', 0) as NodeOperationMode;\n\n\t\t\t// Get the embeddings model connected to this node\n\t\t\tconst embeddings = (await this.getInputConnectionData(\n\t\t\t\tNodeConnectionTypes.AiEmbedding,\n\t\t\t\t0,\n\t\t\t)) as Embeddings;\n\n\t\t\t// Handle each supply data operation mode with dedicated modules\n\t\t\tif (mode === 'retrieve') {\n\t\t\t\treturn await handleRetrieveOperation(this, args, embeddings, itemIndex);\n\t\t\t}\n\n\t\t\tif (mode === 'retrieve-as-tool') {\n\t\t\t\treturn await handleRetrieveAsToolOperation(this, args, embeddings, itemIndex);\n\t\t\t}\n\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Only the \"retrieve\" and \"retrieve-as-tool\" operation mode is supported to supply data',\n\t\t\t);\n\t\t}\n\t};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,0BAAwD;AAUxD,0BAA6C;AAG7C,wBAMO;AAGP,mBAA8E;AAQvE,MAAM,wBAAwB,CACpC,SAEA,MAAM,oBAAyC;AAAA,EAA/C;AACC,uBAAoC;AAAA,MACnC,aAAa,KAAK,KAAK;AAAA,MACvB,MAAM,KAAK,KAAK;AAAA,MAChB,aAAa,KAAK,KAAK;AAAA,M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AAO,CAAC,UAAU;AAAA,IACnB;AAEA,QAAI,SAAS,UAAU;AACtB,YAAM,aAAa,UAAM,yCAAsB,MAAM,MAAM,UAAU;AACrE,aAAO,CAAC,UAAU;AAAA,IACnB;AAEA,UAAM,IAAI;AAAA,MACT,KAAK,QAAQ;AAAA,MACb;AAAA,IACD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAuC,WAAwC;AACpF,UAAM,OAAO,KAAK,iBAAiB,QAAQ,CAAC;AAG5C,UAAM,aAAc,MAAM,KAAK;AAAA,MAC9B,wCAAoB;AAAA,MACpB;AAAA,IACD;AAGA,QAAI,SAAS,YAAY;AACxB,aAAO,UAAM,2CAAwB,MAAM,MAAM,YAAY,SAAS;AAAA,IACvE;AAEA,QAAI,SAAS,oBAAoB;AAChC,aAAO,UAAM,iDAA8B,MAAM,MAAM,YAAY,SAAS;AAAA,IAC7E;AAEA,UAAM,IAAI;AAAA,MACT,KAAK,QAAQ;AAAA,MACb;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../../nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-filename-against-convention */\n/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport type { Embeddings } from '@langchain/core/embeddings';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\nimport type {\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeTypeDescription,\n\tSupplyData,\n\tISupplyDataFunctions,\n\tINodeType,\n} from 'n8n-workflow';\n\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\n// Import custom types\nimport {\n\thandleLoadOperation,\n\thandleInsertOperation,\n\thandleUpdateOperation,\n\thandleRetrieveOperation,\n\thandleRetrieveAsToolOperation,\n} from './operations';\nimport type { NodeOperationMode, VectorStoreNodeConstructorArgs } from './types';\n// Import utility functions\nimport { transformDescriptionForOperationMode, getOperationModeOptions } from './utils';\n\n// Import operation handlers\n\n/**\n * Creates a vector store node with the given configuration\n * This factory function produces a complete node class that implements all vector store operations\n */\nexport const createVectorStoreNode = <T extends VectorStore = VectorStore>(\n\targs: VectorStoreNodeConstructorArgs<T>,\n) =>\n\tclass VectorStoreNodeType implements INodeType {\n\t\tdescription: INodeTypeDescription = {\n\t\t\tdisplayName: args.meta.displayName,\n\t\t\tname: args.meta.name,\n\t\t\tdescription: args.meta.description,\n\t\t\ticon: args.meta.icon,\n\t\t\ticonColor: args.meta.iconColor,\n\t\t\tgroup: ['transform'],\n\t\t\t// 1.2 has changes to VectorStoreInMemory node.\n\t\t\t// 1.3 drops `toolName` and uses node name as the tool name.\n\t\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\t\tdefaults: {\n\t\t\t\tname: args.meta.displayName,\n\t\t\t},\n\t\t\tcodex: {\n\t\t\t\tcategories: args.meta.categories ?? ['AI'],\n\t\t\t\tsubcategories: args.meta.subcategories ?? {\n\t\t\t\t\tAI: ['Vector Stores', 'Tools', 'Root Nodes'],\n\t\t\t\t\t'Vector Stores': ['Other Vector Stores'],\n\t\t\t\t\tTools: ['Other Tools'],\n\t\t\t\t},\n\t\t\t\tresources: {\n\t\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\turl: args.meta.docsUrl,\n\t\t\t\t\t\t},\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t},\n\t\t\tcredentials: args.meta.credentials,\n\t\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\t\tinputs: `={{\n\t\t\t((parameters) => {\n\t\t\t\tconst mode = parameters?.mode;\n\t\t\t\tconst useReranker = parameters?.useReranker;\n\t\t\t\tconst inputs = [{ displayName: \"Embedding\", type: \"${NodeConnectionTypes.AiEmbedding}\", required: true, maxConnections: 1}]\n\n\t\t\t\tif (['load', 'retrieve', 'retrieve-as-tool'].includes(mode) && useReranker) {\n\t\t\t\t\tinputs.push({ displayName: \"Reranker\", type: \"${NodeConnectionTypes.AiReranker}\", required: true, maxConnections: 1})\n\t\t\t\t}\n\n\t\t\t\tif (mode === 'retrieve-as-tool') {\n\t\t\t\t\treturn inputs;\n\t\t\t\t}\n\n\t\t\t\tif (['insert', 'load', 'update'].includes(mode)) {\n\t\t\t\t\tinputs.push({ displayName: \"\", type: \"${NodeConnectionTypes.Main}\"})\n\t\t\t\t}\n\n\t\t\t\tif (['insert'].includes(mode)) {\n\t\t\t\t\tinputs.push({ displayName: \"Document\", type: \"${NodeConnectionTypes.AiDocument}\", required: true, maxConnections: 1})\n\t\t\t\t}\n\t\t\t\treturn inputs\n\t\t\t})($parameter)\n\t\t}}`,\n\t\t\toutputs: `={{\n\t\t\t((parameters) => {\n\t\t\t\tconst mode = parameters?.mode ?? 'retrieve';\n\n\t\t\t\tif (mode === 'retrieve-as-tool') {\n\t\t\t\t\treturn [{ displayName: \"Tool\", type: \"${NodeConnectionTypes.AiTool}\"}]\n\t\t\t\t}\n\n\t\t\t\tif (mode === 'retrieve') {\n\t\t\t\t\treturn [{ displayName: \"Vector Store\", type: \"${NodeConnectionTypes.AiVectorStore}\"}]\n\t\t\t\t}\n\t\t\t\treturn [{ displayName: \"\", type: \"${NodeConnectionTypes.Main}\"}]\n\t\t\t})($parameter)\n\t\t}}`,\n\t\t\tproperties: [\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Operation Mode',\n\t\t\t\t\tname: 'mode',\n\t\t\t\t\ttype: 'options',\n\t\t\t\t\tnoDataExpression: true,\n\t\t\t\t\tdefault: 'retrieve',\n\t\t\t\t\toptions: getOperationModeOptions(args),\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\t...getConnectionHintNoticeField([NodeConnectionTypes.AiRetriever]),\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['retrieve'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Name',\n\t\t\t\t\tname: 'toolName',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefault: '',\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: 'Name of the vector store',\n\t\t\t\t\tplaceholder: 'e.g. company_knowledge_base',\n\t\t\t\t\tvalidateType: 'string-alphanumeric',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\t'@version': [{ _cnd: { lte: 1.2 } }],\n\t\t\t\t\t\t\tmode: ['retrieve-as-tool'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Description',\n\t\t\t\t\tname: 'toolDescription',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefault: '',\n\t\t\t\t\trequired: true,\n\t\t\t\t\ttypeOptions: { rows: 2 },\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Explain to the LLM what this tool does, a good, specific description would allow LLMs to produce expected results much more often',\n\t\t\t\t\tplaceholder: `e.g. ${args.meta.description}`,\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['retrieve-as-tool'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...args.sharedFields,\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Embedding Batch Size',\n\t\t\t\t\tname: 'embeddingBatchSize',\n\t\t\t\t\ttype: 'number',\n\t\t\t\t\tdefault: 200,\n\t\t\t\t\tdescription: 'Number of documents to embed in a single batch',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['insert'],\n\t\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.1 } }],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...transformDescriptionForOperationMode(args.insertFields ?? [], 'insert'),\n\t\t\t\t// Prompt and topK are always used for the load operation\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Prompt',\n\t\t\t\t\tname: 'prompt',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefault: '',\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription:\n\t\t\t\t\t\t'Search prompt to retrieve matching documents from the vector store using similarity-based ranking',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['load'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Limit',\n\t\t\t\t\tname: 'topK',\n\t\t\t\t\ttype: 'number',\n\t\t\t\t\tdefault: 4,\n\t\t\t\t\tdescription: 'Number of top results to fetch from vector store',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['load', 'retrieve-as-tool'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Include Metadata',\n\t\t\t\t\tname: 'includeDocumentMetadata',\n\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\tdefault: true,\n\t\t\t\t\tdescription: 'Whether or not to include document metadata',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['load', 'retrieve-as-tool'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'Rerank Results',\n\t\t\t\t\tname: 'useReranker',\n\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\tdefault: false,\n\t\t\t\t\tdescription: 'Whether or not to rerank results',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['load', 'retrieve', 'retrieve-as-tool'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t// ID is always used for update operation\n\t\t\t\t{\n\t\t\t\t\tdisplayName: 'ID',\n\t\t\t\t\tname: 'id',\n\t\t\t\t\ttype: 'string',\n\t\t\t\t\tdefault: '',\n\t\t\t\t\trequired: true,\n\t\t\t\t\tdescription: 'ID of an embedding entry',\n\t\t\t\t\tdisplayOptions: {\n\t\t\t\t\t\tshow: {\n\t\t\t\t\t\t\tmode: ['update'],\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...transformDescriptionForOperationMode(args.loadFields ?? [], [\n\t\t\t\t\t'load',\n\t\t\t\t\t'retrieve-as-tool',\n\t\t\t\t]),\n\t\t\t\t...transformDescriptionForOperationMode(args.retrieveFields ?? [], 'retrieve'),\n\t\t\t\t...transformDescriptionForOperationMode(args.updateFields ?? [], 'update'),\n\t\t\t],\n\t\t};\n\n\t\tmethods = args.methods;\n\n\t\t/**\n\t\t * Method to execute the node in regular workflow mode\n\t\t * Supports 'load', 'insert', and 'update' operation modes\n\t\t */\n\t\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\t\tconst mode = this.getNodeParameter('mode', 0) as NodeOperationMode;\n\t\t\t// Get the embeddings model connected to this node\n\t\t\tconst embeddings = (await this.getInputConnectionData(\n\t\t\t\tNodeConnectionTypes.AiEmbedding,\n\t\t\t\t0,\n\t\t\t)) as Embeddings;\n\n\t\t\t// Handle each operation mode with dedicated modules\n\t\t\tif (mode === 'load') {\n\t\t\t\tconst items = this.getInputData(0);\n\t\t\t\tconst resultData = [];\n\n\t\t\t\tfor (let itemIndex = 0; itemIndex < items.length; itemIndex++) {\n\t\t\t\t\tconst docs = await handleLoadOperation(this, args, embeddings, itemIndex);\n\t\t\t\t\tresultData.push(...docs);\n\t\t\t\t}\n\n\t\t\t\treturn [resultData];\n\t\t\t}\n\n\t\t\tif (mode === 'insert') {\n\t\t\t\tconst resultData = await handleInsertOperation(this, args, embeddings);\n\t\t\t\treturn [resultData];\n\t\t\t}\n\n\t\t\tif (mode === 'update') {\n\t\t\t\tconst resultData = await handleUpdateOperation(this, args, embeddings);\n\t\t\t\treturn [resultData];\n\t\t\t}\n\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Only the \"load\", \"update\" and \"insert\" operation modes are supported with execute',\n\t\t\t);\n\t\t}\n\n\t\t/**\n\t\t * Method to supply data to AI nodes\n\t\t * Supports 'retrieve' and 'retrieve-as-tool' operation modes\n\t\t */\n\t\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\t\tconst mode = this.getNodeParameter('mode', 0) as NodeOperationMode;\n\n\t\t\t// Get the embeddings model connected to this node\n\t\t\tconst embeddings = (await this.getInputConnectionData(\n\t\t\t\tNodeConnectionTypes.AiEmbedding,\n\t\t\t\t0,\n\t\t\t)) as Embeddings;\n\n\t\t\t// Handle each supply data operation mode with dedicated modules\n\t\t\tif (mode === 'retrieve') {\n\t\t\t\treturn await handleRetrieveOperation(this, args, embeddings, itemIndex);\n\t\t\t}\n\n\t\t\tif (mode === 'retrieve-as-tool') {\n\t\t\t\treturn await handleRetrieveAsToolOperation(this, args, embeddings, itemIndex);\n\t\t\t}\n\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Only the \"retrieve\" and \"retrieve-as-tool\" operation mode is supported to supply data',\n\t\t\t);\n\t\t}\n\t};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,0BAAwD;AAUxD,0BAA6C;AAG7C,wBAMO;AAGP,mBAA8E;AAQvE,MAAM,wBAAwB,CACpC,SAEA,MAAM,oBAAyC;AAAA,EAA/C;AACC,uBAAoC;AAAA,MACnC,aAAa,KAAK,KAAK;AAAA,MACvB,MAAM,KAAK,KAAK;AAAA,MAChB,aAAa,KAAK,KAAK;AAAA,MACvB,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MAAM,KAAK;AAAA,MAC9B,wCAAoB;AAAA,MACpB;AAAA,IACD;AAGA,QAAI,SAAS,QAAQ;AACpB,YAAM,QAAQ,KAAK,aAAa,CAAC;AACjC,YAAM,aAAa,CAAC;AAEpB,eAAS,YAAY,GAAG,YAAY,MAAM,QAAQ,aAAa;AAC9D,cAAM,OAAO,UAAM,uCAAoB,MAAM,MAAM,YAAY,SAAS;AACxE,mBAAW,KAAK,GAAG,IAAI;AAAA,MACxB;AAEA,aAAO,CAAC,UAAU;AAAA,IACnB;AAEA,QAAI,SAAS,UAAU;AACtB,YAAM,aAAa,UAAM,yCAAsB,MAAM,MAAM,UAAU;AACrE,aAAO,CAAC,UAAU;AAAA,IACnB;AAEA,QAAI,SAAS,UAAU;AACtB,YAAM,aAAa,UAAM,yCAAsB,MAAM,MAAM,UAAU;AACrE,aAAO,CAAC,UAAU;AAAA,IACnB;AAEA,UAAM,IAAI;AAAA,MACT,KAAK,QAAQ;AAAA,MACb;AAAA,IACD;AAAA,EACD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,MAAM,WAAuC,WAAwC;AACpF,UAAM,OAAO,KAAK,iBAAiB,QAAQ,CAAC;AAG5C,UAAM,aAAc,MAAM,KAAK;AAAA,MAC9B,wCAAoB;AAAA,MACpB;AAAA,IACD;AAGA,QAAI,SAAS,YAAY;AACxB,aAAO,UAAM,2CAAwB,MAAM,MAAM,YAAY,SAAS;AAAA,IACvE;AAEA,QAAI,SAAS,oBAAoB;AAChC,aAAO,UAAM,iDAA8B,MAAM,MAAM,YAAY,SAAS;AAAA,IAC7E;AAEA,UAAM,IAAI;AAAA,MACT,KAAK,QAAQ;AAAA,MACb;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
@@ -21,6 +21,7 @@ __export(loadOperation_exports, {
21
21
  handleLoadOperation: () => handleLoadOperation
22
22
  });
23
23
  module.exports = __toCommonJS(loadOperation_exports);
24
+ var import_n8n_workflow = require("n8n-workflow");
24
25
  var import_helpers = require("../../../../../utils/helpers");
25
26
  async function handleLoadOperation(context, args, embeddings, itemIndex) {
26
27
  const filter = (0, import_helpers.getMetadataFiltersValues)(context, itemIndex);
@@ -34,13 +35,26 @@ async function handleLoadOperation(context, args, embeddings, itemIndex) {
34
35
  try {
35
36
  const prompt = context.getNodeParameter("prompt", itemIndex);
36
37
  const topK = context.getNodeParameter("topK", itemIndex, 4);
38
+ const useReranker = context.getNodeParameter("useReranker", itemIndex, false);
37
39
  const includeDocumentMetadata = context.getNodeParameter(
38
40
  "includeDocumentMetadata",
39
41
  itemIndex,
40
42
  true
41
43
  );
42
44
  const embeddedPrompt = await embeddings.embedQuery(prompt);
43
- const docs = await vectorStore.similaritySearchVectorWithScore(embeddedPrompt, topK, filter);
45
+ let docs = await vectorStore.similaritySearchVectorWithScore(embeddedPrompt, topK, filter);
46
+ if (useReranker && docs.length > 0) {
47
+ const reranker = await context.getInputConnectionData(
48
+ import_n8n_workflow.NodeConnectionTypes.AiReranker,
49
+ 0
50
+ );
51
+ const documents = docs.map(([doc]) => doc);
52
+ const rerankedDocuments = await reranker.compressDocuments(documents, prompt);
53
+ docs = rerankedDocuments.map((doc) => {
54
+ const { relevanceScore, ...metadata } = doc.metadata || {};
55
+ return [{ ...doc, metadata }, relevanceScore];
56
+ });
57
+ }
44
58
  const serializedDocs = docs.map(([doc, score]) => {
45
59
  const document = {
46
60
  pageContent: doc.pageContent,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.ts"],"sourcesContent":["import type { Embeddings } from '@langchain/core/embeddings';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport type { IExecuteFunctions, INodeExecutionData } from 'n8n-workflow';\n\nimport { getMetadataFiltersValues, logAiEvent } from '@utils/helpers';\n\nimport type { VectorStoreNodeConstructorArgs } from '../types';\n\n/**\n * Handles the 'load' operation mode\n * Searches the vector store for documents similar to a query\n */\nexport async function handleLoadOperation<T extends VectorStore = VectorStore>(\n\tcontext: IExecuteFunctions,\n\targs: VectorStoreNodeConstructorArgs<T>,\n\tembeddings: Embeddings,\n\titemIndex: number,\n): Promise<INodeExecutionData[]> {\n\tconst filter = getMetadataFiltersValues(context, itemIndex);\n\tconst vectorStore = await args.getVectorStoreClient(\n\t\tcontext,\n\t\t// We'll pass filter to similaritySearchVectorWithScore instead of getVectorStoreClient\n\t\tundefined,\n\t\tembeddings,\n\t\titemIndex,\n\t);\n\n\ttry {\n\t\t// Get the search parameters from the node\n\t\tconst prompt = context.getNodeParameter('prompt', itemIndex) as string;\n\t\tconst topK = context.getNodeParameter('topK', itemIndex, 4) as number;\n\t\tconst includeDocumentMetadata = context.getNodeParameter(\n\t\t\t'includeDocumentMetadata',\n\t\t\titemIndex,\n\t\t\ttrue,\n\t\t) as boolean;\n\n\t\t// Embed the prompt to prepare for vector similarity search\n\t\tconst embeddedPrompt = await embeddings.embedQuery(prompt);\n\n\t\t// Get the most similar documents to the embedded prompt\n\t\tconst docs = await vectorStore.similaritySearchVectorWithScore(embeddedPrompt, topK, filter);\n\n\t\t// Format the documents for the output\n\t\tconst serializedDocs = docs.map(([doc, score]) => {\n\t\t\tconst document = {\n\t\t\t\tpageContent: doc.pageContent,\n\t\t\t\t...(includeDocumentMetadata ? { metadata: doc.metadata } : {}),\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\tjson: { document, score },\n\t\t\t\tpairedItem: {\n\t\t\t\t\titem: itemIndex,\n\t\t\t\t},\n\t\t\t};\n\t\t});\n\n\t\t// Log the AI event for analytics\n\t\tlogAiEvent(context, 'ai-vector-store-searched', { query: prompt });\n\n\t\treturn serializedDocs;\n\t} finally {\n\t\t// Release the vector store client if a release method was provided\n\t\targs.releaseVectorStoreClient?.(vectorStore);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,qBAAqD;AAQrD,eAAsB,oBACrB,SACA,MACA,YACA,WACgC;AAChC,QAAM,aAAS,yCAAyB,SAAS,SAAS;AAC1D,QAAM,cAAc,MAAM,KAAK;AAAA,IAC9B;AAAA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,MAAI;AAEH,UAAM,SAAS,QAAQ,iBAAiB,UAAU,SAAS;AAC3D,UAAM,OAAO,QAAQ,iBAAiB,QAAQ,WAAW,CAAC;AAC1D,UAAM,0BAA0B,QAAQ;AAAA,MACvC;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAGA,UAAM,iBAAiB,MAAM,WAAW,WAAW,MAAM;AAGzD,UAAM,OAAO,MAAM,YAAY,gCAAgC,gBAAgB,MAAM,MAAM;AAG3F,UAAM,iBAAiB,KAAK,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACjD,YAAM,WAAW;AAAA,QAChB,aAAa,IAAI;AAAA,QACjB,GAAI,0BAA0B,EAAE,UAAU,IAAI,SAAS,IAAI,CAAC;AAAA,MAC7D;AAEA,aAAO;AAAA,QACN,MAAM,EAAE,UAAU,MAAM;AAAA,QACxB,YAAY;AAAA,UACX,MAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD,CAAC;AAGD,mCAAW,SAAS,4BAA4B,EAAE,OAAO,OAAO,CAAC;AAEjE,WAAO;AAAA,EACR,UAAE;AAED,SAAK,2BAA2B,WAAW;AAAA,EAC5C;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../../../nodes/vector_store/shared/createVectorStoreNode/operations/loadOperation.ts"],"sourcesContent":["import type { Embeddings } from '@langchain/core/embeddings';\nimport type { BaseDocumentCompressor } from '@langchain/core/retrievers/document_compressors';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport { NodeConnectionTypes, type IExecuteFunctions, type INodeExecutionData } from 'n8n-workflow';\n\nimport { getMetadataFiltersValues, logAiEvent } from '@utils/helpers';\n\nimport type { VectorStoreNodeConstructorArgs } from '../types';\n\n/**\n * Handles the 'load' operation mode\n * Searches the vector store for documents similar to a query\n */\nexport async function handleLoadOperation<T extends VectorStore = VectorStore>(\n\tcontext: IExecuteFunctions,\n\targs: VectorStoreNodeConstructorArgs<T>,\n\tembeddings: Embeddings,\n\titemIndex: number,\n): Promise<INodeExecutionData[]> {\n\tconst filter = getMetadataFiltersValues(context, itemIndex);\n\tconst vectorStore = await args.getVectorStoreClient(\n\t\tcontext,\n\t\t// We'll pass filter to similaritySearchVectorWithScore instead of getVectorStoreClient\n\t\tundefined,\n\t\tembeddings,\n\t\titemIndex,\n\t);\n\n\ttry {\n\t\t// Get the search parameters from the node\n\t\tconst prompt = context.getNodeParameter('prompt', itemIndex) as string;\n\t\tconst topK = context.getNodeParameter('topK', itemIndex, 4) as number;\n\t\tconst useReranker = context.getNodeParameter('useReranker', itemIndex, false) as boolean;\n\n\t\tconst includeDocumentMetadata = context.getNodeParameter(\n\t\t\t'includeDocumentMetadata',\n\t\t\titemIndex,\n\t\t\ttrue,\n\t\t) as boolean;\n\n\t\t// Embed the prompt to prepare for vector similarity search\n\t\tconst embeddedPrompt = await embeddings.embedQuery(prompt);\n\n\t\t// Get the most similar documents to the embedded prompt\n\t\tlet docs = await vectorStore.similaritySearchVectorWithScore(embeddedPrompt, topK, filter);\n\n\t\t// If reranker is used, rerank the documents\n\t\tif (useReranker && docs.length > 0) {\n\t\t\tconst reranker = (await context.getInputConnectionData(\n\t\t\t\tNodeConnectionTypes.AiReranker,\n\t\t\t\t0,\n\t\t\t)) as BaseDocumentCompressor;\n\t\t\tconst documents = docs.map(([doc]) => doc);\n\n\t\t\tconst rerankedDocuments = await reranker.compressDocuments(documents, prompt);\n\t\t\tdocs = rerankedDocuments.map((doc) => {\n\t\t\t\tconst { relevanceScore, ...metadata } = doc.metadata || {};\n\t\t\t\treturn [{ ...doc, metadata }, relevanceScore];\n\t\t\t});\n\t\t}\n\n\t\t// Format the documents for the output\n\t\tconst serializedDocs = docs.map(([doc, score]) => {\n\t\t\tconst document = {\n\t\t\t\tpageContent: doc.pageContent,\n\t\t\t\t...(includeDocumentMetadata ? { metadata: doc.metadata } : {}),\n\t\t\t};\n\n\t\t\treturn {\n\t\t\t\tjson: { document, score },\n\t\t\t\tpairedItem: {\n\t\t\t\t\titem: itemIndex,\n\t\t\t\t},\n\t\t\t};\n\t\t});\n\n\t\t// Log the AI event for analytics\n\t\tlogAiEvent(context, 'ai-vector-store-searched', { query: prompt });\n\n\t\treturn serializedDocs;\n\t} finally {\n\t\t// Release the vector store client if a release method was provided\n\t\targs.releaseVectorStoreClient?.(vectorStore);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAqF;AAErF,qBAAqD;AAQrD,eAAsB,oBACrB,SACA,MACA,YACA,WACgC;AAChC,QAAM,aAAS,yCAAyB,SAAS,SAAS;AAC1D,QAAM,cAAc,MAAM,KAAK;AAAA,IAC9B;AAAA;AAAA,IAEA;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,MAAI;AAEH,UAAM,SAAS,QAAQ,iBAAiB,UAAU,SAAS;AAC3D,UAAM,OAAO,QAAQ,iBAAiB,QAAQ,WAAW,CAAC;AAC1D,UAAM,cAAc,QAAQ,iBAAiB,eAAe,WAAW,KAAK;AAE5E,UAAM,0BAA0B,QAAQ;AAAA,MACvC;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAGA,UAAM,iBAAiB,MAAM,WAAW,WAAW,MAAM;AAGzD,QAAI,OAAO,MAAM,YAAY,gCAAgC,gBAAgB,MAAM,MAAM;AAGzF,QAAI,eAAe,KAAK,SAAS,GAAG;AACnC,YAAM,WAAY,MAAM,QAAQ;AAAA,QAC/B,wCAAoB;AAAA,QACpB;AAAA,MACD;AACA,YAAM,YAAY,KAAK,IAAI,CAAC,CAAC,GAAG,MAAM,GAAG;AAEzC,YAAM,oBAAoB,MAAM,SAAS,kBAAkB,WAAW,MAAM;AAC5E,aAAO,kBAAkB,IAAI,CAAC,QAAQ;AACrC,cAAM,EAAE,gBAAgB,GAAG,SAAS,IAAI,IAAI,YAAY,CAAC;AACzD,eAAO,CAAC,EAAE,GAAG,KAAK,SAAS,GAAG,cAAc;AAAA,MAC7C,CAAC;AAAA,IACF;AAGA,UAAM,iBAAiB,KAAK,IAAI,CAAC,CAAC,KAAK,KAAK,MAAM;AACjD,YAAM,WAAW;AAAA,QAChB,aAAa,IAAI;AAAA,QACjB,GAAI,0BAA0B,EAAE,UAAU,IAAI,SAAS,IAAI,CAAC;AAAA,MAC7D;AAEA,aAAO;AAAA,QACN,MAAM,EAAE,UAAU,MAAM;AAAA,QACxB,YAAY;AAAA,UACX,MAAM;AAAA,QACP;AAAA,MACD;AAAA,IACD,CAAC;AAGD,mCAAW,SAAS,4BAA4B,EAAE,OAAO,OAAO,CAAC;AAEjE,WAAO;AAAA,EACR,UAAE;AAED,SAAK,2BAA2B,WAAW;AAAA,EAC5C;AACD;","names":[]}
@@ -22,12 +22,16 @@ __export(retrieveAsToolOperation_exports, {
22
22
  });
23
23
  module.exports = __toCommonJS(retrieveAsToolOperation_exports);
24
24
  var import_tools = require("langchain/tools");
25
+ var import_n8n_workflow = require("n8n-workflow");
25
26
  var import_helpers = require("../../../../../utils/helpers");
26
27
  var import_logWrapper = require("../../../../../utils/logWrapper");
27
28
  async function handleRetrieveAsToolOperation(context, args, embeddings, itemIndex) {
28
29
  const toolDescription = context.getNodeParameter("toolDescription", itemIndex);
29
- const toolName = context.getNodeParameter("toolName", itemIndex);
30
+ const node = context.getNode();
31
+ const { typeVersion } = node;
32
+ const toolName = typeVersion < 1.3 ? context.getNodeParameter("toolName", itemIndex) : (0, import_helpers.nodeNameToToolName)(node);
30
33
  const topK = context.getNodeParameter("topK", itemIndex, 4);
34
+ const useReranker = context.getNodeParameter("useReranker", itemIndex, false);
31
35
  const includeDocumentMetadata = context.getNodeParameter(
32
36
  "includeDocumentMetadata",
33
37
  itemIndex,
@@ -46,11 +50,23 @@ async function handleRetrieveAsToolOperation(context, args, embeddings, itemInde
46
50
  );
47
51
  try {
48
52
  const embeddedPrompt = await embeddings.embedQuery(input);
49
- const documents = await vectorStore.similaritySearchVectorWithScore(
53
+ let documents = await vectorStore.similaritySearchVectorWithScore(
50
54
  embeddedPrompt,
51
55
  topK,
52
56
  filter
53
57
  );
58
+ if (useReranker && documents.length > 0) {
59
+ const reranker = await context.getInputConnectionData(
60
+ import_n8n_workflow.NodeConnectionTypes.AiReranker,
61
+ 0
62
+ );
63
+ const docs = documents.map(([doc]) => doc);
64
+ const rerankedDocuments = await reranker.compressDocuments(docs, input);
65
+ documents = rerankedDocuments.map((doc) => {
66
+ const { relevanceScore, ...metadata } = doc.metadata;
67
+ return [{ ...doc, metadata }, relevanceScore];
68
+ });
69
+ }
54
70
  return documents.map((document) => {
55
71
  if (includeDocumentMetadata) {
56
72
  return { type: "text", text: JSON.stringify(document[0]) };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.ts"],"sourcesContent":["import type { Embeddings } from '@langchain/core/embeddings';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport { DynamicTool } from 'langchain/tools';\nimport type { ISupplyDataFunctions, SupplyData } from 'n8n-workflow';\n\nimport { getMetadataFiltersValues } from '@utils/helpers';\nimport { logWrapper } from '@utils/logWrapper';\n\nimport type { VectorStoreNodeConstructorArgs } from '../types';\n\n/**\n * Handles the 'retrieve-as-tool' operation mode\n * Returns a tool that can be used with AI Agent nodes\n */\nexport async function handleRetrieveAsToolOperation<T extends VectorStore = VectorStore>(\n\tcontext: ISupplyDataFunctions,\n\targs: VectorStoreNodeConstructorArgs<T>,\n\tembeddings: Embeddings,\n\titemIndex: number,\n): Promise<SupplyData> {\n\t// Get the tool configuration parameters\n\tconst toolDescription = context.getNodeParameter('toolDescription', itemIndex) as string;\n\tconst toolName = context.getNodeParameter('toolName', itemIndex) as string;\n\tconst topK = context.getNodeParameter('topK', itemIndex, 4) as number;\n\tconst includeDocumentMetadata = context.getNodeParameter(\n\t\t'includeDocumentMetadata',\n\t\titemIndex,\n\t\ttrue,\n\t) as boolean;\n\n\t// Get metadata filters\n\tconst filter = getMetadataFiltersValues(context, itemIndex);\n\n\t// Create a Dynamic Tool that wraps vector store search functionality\n\tconst vectorStoreTool = new DynamicTool({\n\t\tname: toolName,\n\t\tdescription: toolDescription,\n\t\tfunc: async (input) => {\n\t\t\t// For each tool use, get a fresh vector store client.\n\t\t\t// We don't pass in a filter here only later in the similaritySearchVectorWithScore\n\t\t\t// method to avoid an exception with some vector stores like Supabase or Pinecone(#AI-740)\n\t\t\tconst vectorStore = await args.getVectorStoreClient(\n\t\t\t\tcontext,\n\t\t\t\tundefined,\n\t\t\t\tembeddings,\n\t\t\t\titemIndex,\n\t\t\t);\n\n\t\t\ttry {\n\t\t\t\t// Embed the input query\n\t\t\t\tconst embeddedPrompt = await embeddings.embedQuery(input);\n\n\t\t\t\t// Search for similar documents\n\t\t\t\tconst documents = await vectorStore.similaritySearchVectorWithScore(\n\t\t\t\t\tembeddedPrompt,\n\t\t\t\t\ttopK,\n\t\t\t\t\tfilter,\n\t\t\t\t);\n\n\t\t\t\t// Format the documents for the tool output\n\t\t\t\treturn documents\n\t\t\t\t\t.map((document) => {\n\t\t\t\t\t\tif (includeDocumentMetadata) {\n\t\t\t\t\t\t\treturn { type: 'text', text: JSON.stringify(document[0]) };\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext: JSON.stringify({ pageContent: document[0].pageContent }),\n\t\t\t\t\t\t};\n\t\t\t\t\t})\n\t\t\t\t\t.filter((document) => !!document);\n\t\t\t} finally {\n\t\t\t\t// Release the vector store client if a release method was provided\n\t\t\t\targs.releaseVectorStoreClient?.(vectorStore);\n\t\t\t}\n\t\t},\n\t});\n\n\t// Return the vector store tool with logging wrapper\n\treturn {\n\t\tresponse: logWrapper(vectorStoreTool, context),\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA4B;AAG5B,qBAAyC;AACzC,wBAA2B;AAQ3B,eAAsB,8BACrB,SACA,MACA,YACA,WACsB;AAEtB,QAAM,kBAAkB,QAAQ,iBAAiB,mBAAmB,SAAS;AAC7E,QAAM,WAAW,QAAQ,iBAAiB,YAAY,SAAS;AAC/D,QAAM,OAAO,QAAQ,iBAAiB,QAAQ,WAAW,CAAC;AAC1D,QAAM,0BAA0B,QAAQ;AAAA,IACvC;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAGA,QAAM,aAAS,yCAAyB,SAAS,SAAS;AAG1D,QAAM,kBAAkB,IAAI,yBAAY;AAAA,IACvC,MAAM;AAAA,IACN,aAAa;AAAA,IACb,MAAM,OAAO,UAAU;AAItB,YAAM,cAAc,MAAM,KAAK;AAAA,QAC9B;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACD;AAEA,UAAI;AAEH,cAAM,iBAAiB,MAAM,WAAW,WAAW,KAAK;AAGxD,cAAM,YAAY,MAAM,YAAY;AAAA,UACnC;AAAA,UACA;AAAA,UACA;AAAA,QACD;AAGA,eAAO,UACL,IAAI,CAAC,aAAa;AAClB,cAAI,yBAAyB;AAC5B,mBAAO,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,SAAS,CAAC,CAAC,EAAE;AAAA,UAC1D;AACA,iBAAO;AAAA,YACN,MAAM;AAAA,YACN,MAAM,KAAK,UAAU,EAAE,aAAa,SAAS,CAAC,EAAE,YAAY,CAAC;AAAA,UAC9D;AAAA,QACD,CAAC,EACA,OAAO,CAAC,aAAa,CAAC,CAAC,QAAQ;AAAA,MAClC,UAAE;AAED,aAAK,2BAA2B,WAAW;AAAA,MAC5C;AAAA,IACD;AAAA,EACD,CAAC;AAGD,SAAO;AAAA,IACN,cAAU,8BAAW,iBAAiB,OAAO;AAAA,EAC9C;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../../../nodes/vector_store/shared/createVectorStoreNode/operations/retrieveAsToolOperation.ts"],"sourcesContent":["import type { Embeddings } from '@langchain/core/embeddings';\nimport type { BaseDocumentCompressor } from '@langchain/core/retrievers/document_compressors';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport { DynamicTool } from 'langchain/tools';\nimport { NodeConnectionTypes, type ISupplyDataFunctions, type SupplyData } from 'n8n-workflow';\n\nimport { getMetadataFiltersValues, nodeNameToToolName } from '@utils/helpers';\nimport { logWrapper } from '@utils/logWrapper';\n\nimport type { VectorStoreNodeConstructorArgs } from '../types';\n\n/**\n * Handles the 'retrieve-as-tool' operation mode\n * Returns a tool that can be used with AI Agent nodes\n */\nexport async function handleRetrieveAsToolOperation<T extends VectorStore = VectorStore>(\n\tcontext: ISupplyDataFunctions,\n\targs: VectorStoreNodeConstructorArgs<T>,\n\tembeddings: Embeddings,\n\titemIndex: number,\n): Promise<SupplyData> {\n\t// Get the tool configuration parameters\n\tconst toolDescription = context.getNodeParameter('toolDescription', itemIndex) as string;\n\n\tconst node = context.getNode();\n\tconst { typeVersion } = node;\n\tconst toolName =\n\t\ttypeVersion < 1.3\n\t\t\t? (context.getNodeParameter('toolName', itemIndex) as string)\n\t\t\t: nodeNameToToolName(node);\n\n\tconst topK = context.getNodeParameter('topK', itemIndex, 4) as number;\n\tconst useReranker = context.getNodeParameter('useReranker', itemIndex, false) as boolean;\n\tconst includeDocumentMetadata = context.getNodeParameter(\n\t\t'includeDocumentMetadata',\n\t\titemIndex,\n\t\ttrue,\n\t) as boolean;\n\n\t// Get metadata filters\n\tconst filter = getMetadataFiltersValues(context, itemIndex);\n\n\t// Create a Dynamic Tool that wraps vector store search functionality\n\tconst vectorStoreTool = new DynamicTool({\n\t\tname: toolName,\n\t\tdescription: toolDescription,\n\t\tfunc: async (input) => {\n\t\t\t// For each tool use, get a fresh vector store client.\n\t\t\t// We don't pass in a filter here only later in the similaritySearchVectorWithScore\n\t\t\t// method to avoid an exception with some vector stores like Supabase or Pinecone(#AI-740)\n\t\t\tconst vectorStore = await args.getVectorStoreClient(\n\t\t\t\tcontext,\n\t\t\t\tundefined,\n\t\t\t\tembeddings,\n\t\t\t\titemIndex,\n\t\t\t);\n\n\t\t\ttry {\n\t\t\t\t// Embed the input query\n\t\t\t\tconst embeddedPrompt = await embeddings.embedQuery(input);\n\n\t\t\t\t// Search for similar documents\n\t\t\t\tlet documents = await vectorStore.similaritySearchVectorWithScore(\n\t\t\t\t\tembeddedPrompt,\n\t\t\t\t\ttopK,\n\t\t\t\t\tfilter,\n\t\t\t\t);\n\n\t\t\t\t// If reranker is used, rerank the documents\n\t\t\t\tif (useReranker && documents.length > 0) {\n\t\t\t\t\tconst reranker = (await context.getInputConnectionData(\n\t\t\t\t\t\tNodeConnectionTypes.AiReranker,\n\t\t\t\t\t\t0,\n\t\t\t\t\t)) as BaseDocumentCompressor;\n\n\t\t\t\t\tconst docs = documents.map(([doc]) => doc);\n\t\t\t\t\tconst rerankedDocuments = await reranker.compressDocuments(docs, input);\n\t\t\t\t\tdocuments = rerankedDocuments.map((doc) => {\n\t\t\t\t\t\tconst { relevanceScore, ...metadata } = doc.metadata;\n\t\t\t\t\t\treturn [{ ...doc, metadata }, relevanceScore];\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Format the documents for the tool output\n\t\t\t\treturn documents\n\t\t\t\t\t.map((document) => {\n\t\t\t\t\t\tif (includeDocumentMetadata) {\n\t\t\t\t\t\t\treturn { type: 'text', text: JSON.stringify(document[0]) };\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttype: 'text',\n\t\t\t\t\t\t\ttext: JSON.stringify({ pageContent: document[0].pageContent }),\n\t\t\t\t\t\t};\n\t\t\t\t\t})\n\t\t\t\t\t.filter((document) => !!document);\n\t\t\t} finally {\n\t\t\t\t// Release the vector store client if a release method was provided\n\t\t\t\targs.releaseVectorStoreClient?.(vectorStore);\n\t\t\t}\n\t\t},\n\t});\n\n\t// Return the vector store tool with logging wrapper\n\treturn {\n\t\tresponse: logWrapper(vectorStoreTool, context),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C5C,mBAAO,CAAC,EAAE,GAAG,KAAK,SAAS,GAAG,cAAc;AAAA,UAC7C,CAAC;AAAA,QACF;AAGA,eAAO,UACL,IAAI,CAAC,aAAa;AAClB,cAAI,yBAAyB;AAC5B,mBAAO,EAAE,MAAM,QAAQ,MAAM,KAAK,UAAU,SAAS,CAAC,CAAC,EAAE;AAAA,UAC1D;AACA,iBAAO;AAAA,YACN,MAAM;AAAA,YACN,MAAM,KAAK,UAAU,EAAE,aAAa,SAAS,CAAC,EAAE,YAAY,CAAC;AAAA,UAC9D;AAAA,QACD,CAAC,EACA,OAAO,CAAC,aAAa,CAAC,CAAC,QAAQ;AAAA,MAClC,UAAE;AAED,aAAK,2BAA2B,WAAW;AAAA,MAC5C;AAAA,IACD;AAAA,EACD,CAAC;AAGD,SAAO;AAAA,IACN,cAAU,8BAAW,iBAAiB,OAAO;AAAA,EAC9C;AACD;","names":[]}
@@ -21,13 +21,28 @@ __export(retrieveOperation_exports, {
21
21
  handleRetrieveOperation: () => handleRetrieveOperation
22
22
  });
23
23
  module.exports = __toCommonJS(retrieveOperation_exports);
24
+ var import_n8n_workflow = require("n8n-workflow");
24
25
  var import_helpers = require("../../../../../utils/helpers");
25
26
  var import_logWrapper = require("../../../../../utils/logWrapper");
26
27
  async function handleRetrieveOperation(context, args, embeddings, itemIndex) {
27
28
  const filter = (0, import_helpers.getMetadataFiltersValues)(context, itemIndex);
29
+ const useReranker = context.getNodeParameter("useReranker", itemIndex, false);
28
30
  const vectorStore = await args.getVectorStoreClient(context, filter, embeddings, itemIndex);
31
+ let response = vectorStore;
32
+ if (useReranker) {
33
+ const reranker = await context.getInputConnectionData(
34
+ import_n8n_workflow.NodeConnectionTypes.AiReranker,
35
+ 0
36
+ );
37
+ response = {
38
+ reranker,
39
+ vectorStore: (0, import_logWrapper.logWrapper)(vectorStore, context)
40
+ };
41
+ } else {
42
+ response = (0, import_logWrapper.logWrapper)(vectorStore, context);
43
+ }
29
44
  return {
30
- response: (0, import_logWrapper.logWrapper)(vectorStore, context),
45
+ response,
31
46
  closeFunction: async () => {
32
47
  args.releaseVectorStoreClient?.(vectorStore);
33
48
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.ts"],"sourcesContent":["import type { Embeddings } from '@langchain/core/embeddings';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport type { ISupplyDataFunctions, SupplyData } from 'n8n-workflow';\n\nimport { getMetadataFiltersValues } from '@utils/helpers';\nimport { logWrapper } from '@utils/logWrapper';\n\nimport type { VectorStoreNodeConstructorArgs } from '../types';\n\n/**\n * Handles the 'retrieve' operation mode\n * Returns the vector store to be used with AI nodes\n */\nexport async function handleRetrieveOperation<T extends VectorStore = VectorStore>(\n\tcontext: ISupplyDataFunctions,\n\targs: VectorStoreNodeConstructorArgs<T>,\n\tembeddings: Embeddings,\n\titemIndex: number,\n): Promise<SupplyData> {\n\t// Get metadata filters\n\tconst filter = getMetadataFiltersValues(context, itemIndex);\n\n\t// Get the vector store client\n\tconst vectorStore = await args.getVectorStoreClient(context, filter, embeddings, itemIndex);\n\n\t// Return the vector store with logging wrapper and cleanup function\n\treturn {\n\t\tresponse: logWrapper(vectorStore, context),\n\t\tcloseFunction: async () => {\n\t\t\t// Release the vector store client if a release method was provided\n\t\t\targs.releaseVectorStoreClient?.(vectorStore);\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,qBAAyC;AACzC,wBAA2B;AAQ3B,eAAsB,wBACrB,SACA,MACA,YACA,WACsB;AAEtB,QAAM,aAAS,yCAAyB,SAAS,SAAS;AAG1D,QAAM,cAAc,MAAM,KAAK,qBAAqB,SAAS,QAAQ,YAAY,SAAS;AAG1F,SAAO;AAAA,IACN,cAAU,8BAAW,aAAa,OAAO;AAAA,IACzC,eAAe,YAAY;AAE1B,WAAK,2BAA2B,WAAW;AAAA,IAC5C;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../../../nodes/vector_store/shared/createVectorStoreNode/operations/retrieveOperation.ts"],"sourcesContent":["import type { Embeddings } from '@langchain/core/embeddings';\nimport type { BaseDocumentCompressor } from '@langchain/core/retrievers/document_compressors';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport { NodeConnectionTypes, type ISupplyDataFunctions, type SupplyData } from 'n8n-workflow';\n\nimport { getMetadataFiltersValues } from '@utils/helpers';\nimport { logWrapper } from '@utils/logWrapper';\n\nimport type { VectorStoreNodeConstructorArgs } from '../types';\n\n/**\n * Handles the 'retrieve' operation mode\n * Returns the vector store to be used with AI nodes\n */\nexport async function handleRetrieveOperation<T extends VectorStore = VectorStore>(\n\tcontext: ISupplyDataFunctions,\n\targs: VectorStoreNodeConstructorArgs<T>,\n\tembeddings: Embeddings,\n\titemIndex: number,\n): Promise<SupplyData> {\n\t// Get metadata filters\n\tconst filter = getMetadataFiltersValues(context, itemIndex);\n\tconst useReranker = context.getNodeParameter('useReranker', itemIndex, false) as boolean;\n\n\t// Get the vector store client\n\tconst vectorStore = await args.getVectorStoreClient(context, filter, embeddings, itemIndex);\n\tlet response: VectorStore | { reranker: BaseDocumentCompressor; vectorStore: VectorStore } =\n\t\tvectorStore;\n\n\tif (useReranker) {\n\t\tconst reranker = (await context.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiReranker,\n\t\t\t0,\n\t\t)) as BaseDocumentCompressor;\n\n\t\t// Return reranker and vector store with log wrapper\n\t\tresponse = {\n\t\t\treranker,\n\t\t\tvectorStore: logWrapper(vectorStore, context),\n\t\t};\n\t} else {\n\t\t// Return the vector store with logging wrapper\n\t\tresponse = logWrapper(vectorStore, context);\n\t}\n\n\treturn {\n\t\tresponse,\n\t\tcloseFunction: async () => {\n\t\t\t// Release the vector store client if a release method was provided\n\t\t\targs.releaseVectorStoreClient?.(vectorStore);\n\t\t},\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAgF;AAEhF,qBAAyC;AACzC,wBAA2B;AAQ3B,eAAsB,wBACrB,SACA,MACA,YACA,WACsB;AAEtB,QAAM,aAAS,yCAAyB,SAAS,SAAS;AAC1D,QAAM,cAAc,QAAQ,iBAAiB,eAAe,WAAW,KAAK;AAG5E,QAAM,cAAc,MAAM,KAAK,qBAAqB,SAAS,QAAQ,YAAY,SAAS;AAC1F,MAAI,WACH;AAED,MAAI,aAAa;AAChB,UAAM,WAAY,MAAM,QAAQ;AAAA,MAC/B,wCAAoB;AAAA,MACpB;AAAA,IACD;AAGA,eAAW;AAAA,MACV;AAAA,MACA,iBAAa,8BAAW,aAAa,OAAO;AAAA,IAC7C;AAAA,EACD,OAAO;AAEN,mBAAW,8BAAW,aAAa,OAAO;AAAA,EAC3C;AAEA,SAAO;AAAA,IACN;AAAA,IACA,eAAe,YAAY;AAE1B,WAAK,2BAA2B,WAAW;AAAA,IAC5C;AAAA,EACD;AACD;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../nodes/vector_store/shared/createVectorStoreNode/types.ts"],"sourcesContent":["import type { Document } from '@langchain/core/documents';\nimport type { Embeddings } from '@langchain/core/embeddings';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport type {\n\tIExecuteFunctions,\n\tINodeCredentialDescription,\n\tINodeProperties,\n\tILoadOptionsFunctions,\n\tINodeListSearchResult,\n\tIcon,\n\tISupplyDataFunctions,\n\tThemeIconColor,\n\tIDataObject,\n\tNodeParameterValueType,\n} from 'n8n-workflow';\n\nexport type NodeOperationMode = 'insert' | 'load' | 'retrieve' | 'update' | 'retrieve-as-tool';\n\nexport interface NodeMeta {\n\tdisplayName: string;\n\tname: string;\n\tdescription: string;\n\tdocsUrl: string;\n\ticon: Icon;\n\ticonColor?: ThemeIconColor;\n\tcredentials?: INodeCredentialDescription[];\n\toperationModes?: NodeOperationMode[];\n}\n\nexport interface VectorStoreNodeConstructorArgs<T extends VectorStore = VectorStore> {\n\tmeta: NodeMeta;\n\tmethods?: {\n\t\tlistSearch?: {\n\t\t\t[key: string]: (\n\t\t\t\tthis: ILoadOptionsFunctions,\n\t\t\t\tfilter?: string,\n\t\t\t\tpaginationToken?: string,\n\t\t\t) => Promise<INodeListSearchResult>;\n\t\t};\n\t\tactionHandler?: {\n\t\t\t[functionName: string]: (\n\t\t\t\tthis: ILoadOptionsFunctions,\n\t\t\t\tpayload: IDataObject | string | undefined,\n\t\t\t) => Promise<NodeParameterValueType>;\n\t\t};\n\t};\n\n\tsharedFields: INodeProperties[];\n\tinsertFields?: INodeProperties[];\n\tloadFields?: INodeProperties[];\n\tretrieveFields?: INodeProperties[];\n\tupdateFields?: INodeProperties[];\n\n\t/**\n\t * Function to populate the vector store with documents\n\t * Used during the 'insert' operation mode\n\t */\n\tpopulateVectorStore: (\n\t\tcontext: IExecuteFunctions | ISupplyDataFunctions,\n\t\tembeddings: Embeddings,\n\t\tdocuments: Array<Document<Record<string, unknown>>>,\n\t\titemIndex: number,\n\t) => Promise<void>;\n\n\t/**\n\t * Function to get the vector store client\n\t * This function is called for all operation modes\n\t */\n\tgetVectorStoreClient: (\n\t\tcontext: IExecuteFunctions | ISupplyDataFunctions,\n\t\tfilter: Record<string, never> | undefined,\n\t\tembeddings: Embeddings,\n\t\titemIndex: number,\n\t) => Promise<T>;\n\n\t/**\n\t * Optional function to release resources associated with the vector store client\n\t * Called after the vector store operations are complete\n\t */\n\treleaseVectorStoreClient?: (vectorStore: T) => void;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
1
+ {"version":3,"sources":["../../../../../nodes/vector_store/shared/createVectorStoreNode/types.ts"],"sourcesContent":["import type { Document } from '@langchain/core/documents';\nimport type { Embeddings } from '@langchain/core/embeddings';\nimport type { VectorStore } from '@langchain/core/vectorstores';\nimport type {\n\tIExecuteFunctions,\n\tINodeCredentialDescription,\n\tINodeProperties,\n\tILoadOptionsFunctions,\n\tINodeListSearchResult,\n\tIcon,\n\tISupplyDataFunctions,\n\tThemeIconColor,\n\tIDataObject,\n\tNodeParameterValueType,\n} from 'n8n-workflow';\n\nexport type NodeOperationMode = 'insert' | 'load' | 'retrieve' | 'update' | 'retrieve-as-tool';\n\nexport interface NodeMeta {\n\tdisplayName: string;\n\tname: string;\n\tdescription: string;\n\tdocsUrl: string;\n\ticon: Icon;\n\ticonColor?: ThemeIconColor;\n\tcredentials?: INodeCredentialDescription[];\n\toperationModes?: NodeOperationMode[];\n\tcategories?: string[];\n\tsubcategories?: Record<string, string[]>;\n}\n\nexport interface VectorStoreNodeConstructorArgs<T extends VectorStore = VectorStore> {\n\tmeta: NodeMeta;\n\tmethods?: {\n\t\tlistSearch?: {\n\t\t\t[key: string]: (\n\t\t\t\tthis: ILoadOptionsFunctions,\n\t\t\t\tfilter?: string,\n\t\t\t\tpaginationToken?: string,\n\t\t\t) => Promise<INodeListSearchResult>;\n\t\t};\n\t\tactionHandler?: {\n\t\t\t[functionName: string]: (\n\t\t\t\tthis: ILoadOptionsFunctions,\n\t\t\t\tpayload: IDataObject | string | undefined,\n\t\t\t) => Promise<NodeParameterValueType>;\n\t\t};\n\t};\n\n\tsharedFields: INodeProperties[];\n\tinsertFields?: INodeProperties[];\n\tloadFields?: INodeProperties[];\n\tretrieveFields?: INodeProperties[];\n\tupdateFields?: INodeProperties[];\n\n\t/**\n\t * Function to populate the vector store with documents\n\t * Used during the 'insert' operation mode\n\t */\n\tpopulateVectorStore: (\n\t\tcontext: IExecuteFunctions | ISupplyDataFunctions,\n\t\tembeddings: Embeddings,\n\t\tdocuments: Array<Document<Record<string, unknown>>>,\n\t\titemIndex: number,\n\t) => Promise<void>;\n\n\t/**\n\t * Function to get the vector store client\n\t * This function is called for all operation modes\n\t */\n\tgetVectorStoreClient: (\n\t\tcontext: IExecuteFunctions | ISupplyDataFunctions,\n\t\tfilter: Record<string, never> | undefined,\n\t\tembeddings: Embeddings,\n\t\titemIndex: number,\n\t) => Promise<T>;\n\n\t/**\n\t * Optional function to release resources associated with the vector store client\n\t * Called after the vector store operations are complete\n\t */\n\treleaseVectorStoreClient?: (vectorStore: T) => void;\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../nodes/vendors/OpenAi/helpers/utils.ts"],"sourcesContent":["import type { BaseMessage } from '@langchain/core/messages';\nimport type { StructuredTool } from '@langchain/core/tools';\nimport type { OpenAIClient } from '@langchain/openai';\nimport type { BufferWindowMemory } from 'langchain/memory';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\n\n// Copied from langchain(`langchain/src/tools/convert_to_openai.ts`)\n// since these functions are not exported\n\n/**\n * Formats a `StructuredTool` instance into a format that is compatible\n * with OpenAI's ChatCompletionFunctions. It uses the `zodToJsonSchema`\n * function to convert the schema of the `StructuredTool` into a JSON\n * schema, which is then used as the parameters for the OpenAI function.\n */\nexport function formatToOpenAIFunction(\n\ttool: StructuredTool,\n): OpenAIClient.Chat.ChatCompletionCreateParams.Function {\n\treturn {\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tparameters: zodToJsonSchema(tool.schema),\n\t};\n}\n\nexport function formatToOpenAITool(tool: StructuredTool): OpenAIClient.Chat.ChatCompletionTool {\n\tconst schema = zodToJsonSchema(tool.schema);\n\treturn {\n\t\ttype: 'function',\n\t\tfunction: {\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: schema,\n\t\t},\n\t};\n}\n\nexport function formatToOpenAIAssistantTool(tool: StructuredTool): OpenAIClient.Beta.AssistantTool {\n\treturn {\n\t\ttype: 'function',\n\t\tfunction: {\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: zodToJsonSchema(tool.schema),\n\t\t},\n\t};\n}\n\nexport async function getChatMessages(memory: BufferWindowMemory): Promise<BaseMessage[]> {\n\treturn (await memory.loadMemoryVariables({}))[memory.memoryKey] as BaseMessage[];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,gCAAgC;AAWzB,SAAS,uBACf,MACwD;AACxD,SAAO;AAAA,IACN,MAAM,KAAK;AAAA,IACX,aAAa,KAAK;AAAA,IAClB,gBAAY,2CAAgB,KAAK,MAAM;AAAA,EACxC;AACD;AAEO,SAAS,mBAAmB,MAA4D;AAC9F,QAAM,aAAS,2CAAgB,KAAK,MAAM;AAC1C,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU;AAAA,MACT,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB,YAAY;AAAA,IACb;AAAA,EACD;AACD;AAEO,SAAS,4BAA4B,MAAuD;AAClG,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU;AAAA,MACT,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB,gBAAY,2CAAgB,KAAK,MAAM;AAAA,IACxC;AAAA,EACD;AACD;AAEA,eAAsB,gBAAgB,QAAoD;AACzF,UAAQ,MAAM,OAAO,oBAAoB,CAAC,CAAC,GAAG,OAAO,SAAS;AAC/D;","names":[]}
1
+ {"version":3,"sources":["../../../../../nodes/vendors/OpenAi/helpers/utils.ts"],"sourcesContent":["import type { BaseMessage } from '@langchain/core/messages';\nimport type { Tool } from '@langchain/core/tools';\nimport type { OpenAIClient } from '@langchain/openai';\nimport type { BufferWindowMemory } from 'langchain/memory';\nimport { zodToJsonSchema } from 'zod-to-json-schema';\n\n// Copied from langchain(`langchain/src/tools/convert_to_openai.ts`)\n// since these functions are not exported\n\n/**\n * Formats a `Tool` instance into a format that is compatible\n * with OpenAI's ChatCompletionFunctions. It uses the `zodToJsonSchema`\n * function to convert the schema of the tool into a JSON\n * schema, which is then used as the parameters for the OpenAI function.\n */\nexport function formatToOpenAIFunction(\n\ttool: Tool,\n): OpenAIClient.Chat.ChatCompletionCreateParams.Function {\n\treturn {\n\t\tname: tool.name,\n\t\tdescription: tool.description,\n\t\tparameters: zodToJsonSchema(tool.schema),\n\t};\n}\n\nexport function formatToOpenAITool(tool: Tool): OpenAIClient.Chat.ChatCompletionTool {\n\tconst schema = zodToJsonSchema(tool.schema);\n\treturn {\n\t\ttype: 'function',\n\t\tfunction: {\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: schema,\n\t\t},\n\t};\n}\n\nexport function formatToOpenAIAssistantTool(tool: Tool): OpenAIClient.Beta.AssistantTool {\n\treturn {\n\t\ttype: 'function',\n\t\tfunction: {\n\t\t\tname: tool.name,\n\t\t\tdescription: tool.description,\n\t\t\tparameters: zodToJsonSchema(tool.schema),\n\t\t},\n\t};\n}\n\nexport async function getChatMessages(memory: BufferWindowMemory): Promise<BaseMessage[]> {\n\treturn (await memory.loadMemoryVariables({}))[memory.memoryKey] as BaseMessage[];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,gCAAgC;AAWzB,SAAS,uBACf,MACwD;AACxD,SAAO;AAAA,IACN,MAAM,KAAK;AAAA,IACX,aAAa,KAAK;AAAA,IAClB,gBAAY,2CAAgB,KAAK,MAAM;AAAA,EACxC;AACD;AAEO,SAAS,mBAAmB,MAAkD;AACpF,QAAM,aAAS,2CAAgB,KAAK,MAAM;AAC1C,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU;AAAA,MACT,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB,YAAY;AAAA,IACb;AAAA,EACD;AACD;AAEO,SAAS,4BAA4B,MAA6C;AACxF,SAAO;AAAA,IACN,MAAM;AAAA,IACN,UAAU;AAAA,MACT,MAAM,KAAK;AAAA,MACX,aAAa,KAAK;AAAA,MAClB,gBAAY,2CAAgB,KAAK,MAAM;AAAA,IACxC;AAAA,EACD;AACD;AAEA,eAAsB,gBAAgB,QAAoD;AACzF,UAAQ,MAAM,OAAO,oBAAoB,CAAC,CAAC,GAAG,OAAO,SAAS;AAC/D;","names":[]}
@@ -76,7 +76,7 @@ const getModelSearch = (filterCondition) => async (ctx, filter) => {
76
76
  async function modelSearch(filter) {
77
77
  const credentials = await this.getCredentials("openAiApi");
78
78
  const url = credentials.url && new URL(credentials.url);
79
- const isCustomAPI = url && url.hostname !== "api.openai.com";
79
+ const isCustomAPI = url && !["api.openai.com", "ai-assistant.n8n.io"].includes(url.hostname);
80
80
  return await getModelSearch(
81
81
  (model) => !isCustomAPI && !(model.id.startsWith("babbage") || model.id.startsWith("davinci") || model.id.startsWith("computer-use") || model.id.startsWith("dall-e") || model.id.startsWith("text-embedding") || model.id.startsWith("tts") || model.id.startsWith("whisper") || model.id.startsWith("omni-moderation") || model.id.startsWith("gpt-") && model.id.includes("instruct"))
82
82
  )(this, filter);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../nodes/vendors/OpenAi/methods/listSearch.ts"],"sourcesContent":["import type {\n\tIDataObject,\n\tILoadOptionsFunctions,\n\tINodeListSearchItems,\n\tINodeListSearchResult,\n} from 'n8n-workflow';\nimport type { Assistant } from 'openai/resources/beta/assistants';\nimport type { Model } from 'openai/resources/models';\n\nimport { apiRequest } from '../transport';\n\nexport async function fileSearch(\n\tthis: ILoadOptionsFunctions,\n\tfilter?: string,\n): Promise<INodeListSearchResult> {\n\tconst { data } = await apiRequest.call(this, 'GET', '/files');\n\n\tif (filter) {\n\t\tconst results: INodeListSearchItems[] = [];\n\n\t\tfor (const file of data || []) {\n\t\t\tif ((file.filename as string)?.toLowerCase().includes(filter.toLowerCase())) {\n\t\t\t\tresults.push({\n\t\t\t\t\tname: file.filename as string,\n\t\t\t\t\tvalue: file.id as string,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tresults,\n\t\t};\n\t} else {\n\t\treturn {\n\t\t\tresults: (data || []).map((file: IDataObject) => ({\n\t\t\t\tname: file.filename as string,\n\t\t\t\tvalue: file.id as string,\n\t\t\t})),\n\t\t};\n\t}\n}\n\nconst getModelSearch =\n\t(filterCondition: (model: Model) => boolean) =>\n\tasync (ctx: ILoadOptionsFunctions, filter?: string): Promise<INodeListSearchResult> => {\n\t\tlet { data } = (await apiRequest.call(ctx, 'GET', '/models')) as { data: Model[] };\n\n\t\tdata = data?.filter((model) => filterCondition(model));\n\n\t\tlet results: INodeListSearchItems[] = [];\n\n\t\tif (filter) {\n\t\t\tfor (const model of data || []) {\n\t\t\t\tif (model.id?.toLowerCase().includes(filter.toLowerCase())) {\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\tname: model.id.toUpperCase(),\n\t\t\t\t\t\tvalue: model.id,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tresults = (data || []).map((model) => ({\n\t\t\t\tname: model.id.toUpperCase(),\n\t\t\t\tvalue: model.id,\n\t\t\t}));\n\t\t}\n\n\t\tresults = results.sort((a, b) => a.name.localeCompare(b.name));\n\t\treturn {\n\t\t\tresults,\n\t\t};\n\t};\n\nexport async function modelSearch(\n\tthis: ILoadOptionsFunctions,\n\tfilter?: string,\n): Promise<INodeListSearchResult> {\n\tconst credentials = await this.getCredentials<{ url: string }>('openAiApi');\n\tconst url = credentials.url && new URL(credentials.url);\n\tconst isCustomAPI = url && url.hostname !== 'api.openai.com';\n\treturn await getModelSearch(\n\t\t(model) =>\n\t\t\t!isCustomAPI &&\n\t\t\t!(\n\t\t\t\tmodel.id.startsWith('babbage') ||\n\t\t\t\tmodel.id.startsWith('davinci') ||\n\t\t\t\tmodel.id.startsWith('computer-use') ||\n\t\t\t\tmodel.id.startsWith('dall-e') ||\n\t\t\t\tmodel.id.startsWith('text-embedding') ||\n\t\t\t\tmodel.id.startsWith('tts') ||\n\t\t\t\tmodel.id.startsWith('whisper') ||\n\t\t\t\tmodel.id.startsWith('omni-moderation') ||\n\t\t\t\t(model.id.startsWith('gpt-') && model.id.includes('instruct'))\n\t\t\t),\n\t)(this, filter);\n}\n\nexport async function imageModelSearch(\n\tthis: ILoadOptionsFunctions,\n\tfilter?: string,\n): Promise<INodeListSearchResult> {\n\treturn await getModelSearch(\n\t\t(model) => model.id.includes('vision') || model.id.includes('gpt-4o'),\n\t)(this, filter);\n}\n\nexport async function assistantSearch(\n\tthis: ILoadOptionsFunctions,\n\tfilter?: string,\n\tpaginationToken?: string,\n): Promise<INodeListSearchResult> {\n\tconst { data, has_more, last_id } = (await apiRequest.call(this, 'GET', '/assistants', {\n\t\theaders: {\n\t\t\t'OpenAI-Beta': 'assistants=v2',\n\t\t},\n\t\tqs: {\n\t\t\tlimit: 100,\n\t\t\tafter: paginationToken,\n\t\t},\n\t})) as {\n\t\tdata: Assistant[];\n\t\thas_more: boolean;\n\t\tlast_id: string;\n\t\tfirst_id: string;\n\t};\n\n\tif (has_more) {\n\t\tpaginationToken = last_id;\n\t} else {\n\t\tpaginationToken = undefined;\n\t}\n\n\tif (filter) {\n\t\tconst results: INodeListSearchItems[] = [];\n\n\t\tfor (const assistant of data || []) {\n\t\t\tif (assistant.name?.toLowerCase().includes(filter.toLowerCase())) {\n\t\t\t\tresults.push({\n\t\t\t\t\tname: assistant.name,\n\t\t\t\t\tvalue: assistant.id,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tresults,\n\t\t};\n\t} else {\n\t\treturn {\n\t\t\tresults: (data || []).map((assistant) => ({\n\t\t\t\tname: assistant.name ?? assistant.id,\n\t\t\t\tvalue: assistant.id,\n\t\t\t})),\n\t\t\tpaginationToken,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,uBAA2B;AAE3B,eAAsB,WAErB,QACiC;AACjC,QAAM,EAAE,KAAK,IAAI,MAAM,4BAAW,KAAK,MAAM,OAAO,QAAQ;AAE5D,MAAI,QAAQ;AACX,UAAM,UAAkC,CAAC;AAEzC,eAAW,QAAQ,QAAQ,CAAC,GAAG;AAC9B,UAA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CAAC,GAAG,IAAI,CAAC,eAAe;AAAA,QACzC,MAAM,UAAU,QAAQ,UAAU;AAAA,QAClC,OAAO,UAAU;AAAA,MAClB,EAAE;AAAA,MACF;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
1
+ {"version":3,"sources":["../../../../../nodes/vendors/OpenAi/methods/listSearch.ts"],"sourcesContent":["import type {\n\tIDataObject,\n\tILoadOptionsFunctions,\n\tINodeListSearchItems,\n\tINodeListSearchResult,\n} from 'n8n-workflow';\nimport type { Assistant } from 'openai/resources/beta/assistants';\nimport type { Model } from 'openai/resources/models';\n\nimport { apiRequest } from '../transport';\n\nexport async function fileSearch(\n\tthis: ILoadOptionsFunctions,\n\tfilter?: string,\n): Promise<INodeListSearchResult> {\n\tconst { data } = await apiRequest.call(this, 'GET', '/files');\n\n\tif (filter) {\n\t\tconst results: INodeListSearchItems[] = [];\n\n\t\tfor (const file of data || []) {\n\t\t\tif ((file.filename as string)?.toLowerCase().includes(filter.toLowerCase())) {\n\t\t\t\tresults.push({\n\t\t\t\t\tname: file.filename as string,\n\t\t\t\t\tvalue: file.id as string,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tresults,\n\t\t};\n\t} else {\n\t\treturn {\n\t\t\tresults: (data || []).map((file: IDataObject) => ({\n\t\t\t\tname: file.filename as string,\n\t\t\t\tvalue: file.id as string,\n\t\t\t})),\n\t\t};\n\t}\n}\n\nconst getModelSearch =\n\t(filterCondition: (model: Model) => boolean) =>\n\tasync (ctx: ILoadOptionsFunctions, filter?: string): Promise<INodeListSearchResult> => {\n\t\tlet { data } = (await apiRequest.call(ctx, 'GET', '/models')) as { data: Model[] };\n\n\t\tdata = data?.filter((model) => filterCondition(model));\n\n\t\tlet results: INodeListSearchItems[] = [];\n\n\t\tif (filter) {\n\t\t\tfor (const model of data || []) {\n\t\t\t\tif (model.id?.toLowerCase().includes(filter.toLowerCase())) {\n\t\t\t\t\tresults.push({\n\t\t\t\t\t\tname: model.id.toUpperCase(),\n\t\t\t\t\t\tvalue: model.id,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tresults = (data || []).map((model) => ({\n\t\t\t\tname: model.id.toUpperCase(),\n\t\t\t\tvalue: model.id,\n\t\t\t}));\n\t\t}\n\n\t\tresults = results.sort((a, b) => a.name.localeCompare(b.name));\n\t\treturn {\n\t\t\tresults,\n\t\t};\n\t};\n\nexport async function modelSearch(\n\tthis: ILoadOptionsFunctions,\n\tfilter?: string,\n): Promise<INodeListSearchResult> {\n\tconst credentials = await this.getCredentials<{ url: string }>('openAiApi');\n\tconst url = credentials.url && new URL(credentials.url);\n\tconst isCustomAPI = url && !['api.openai.com', 'ai-assistant.n8n.io'].includes(url.hostname);\n\treturn await getModelSearch(\n\t\t(model) =>\n\t\t\t!isCustomAPI &&\n\t\t\t!(\n\t\t\t\tmodel.id.startsWith('babbage') ||\n\t\t\t\tmodel.id.startsWith('davinci') ||\n\t\t\t\tmodel.id.startsWith('computer-use') ||\n\t\t\t\tmodel.id.startsWith('dall-e') ||\n\t\t\t\tmodel.id.startsWith('text-embedding') ||\n\t\t\t\tmodel.id.startsWith('tts') ||\n\t\t\t\tmodel.id.startsWith('whisper') ||\n\t\t\t\tmodel.id.startsWith('omni-moderation') ||\n\t\t\t\t(model.id.startsWith('gpt-') && model.id.includes('instruct'))\n\t\t\t),\n\t)(this, filter);\n}\n\nexport async function imageModelSearch(\n\tthis: ILoadOptionsFunctions,\n\tfilter?: string,\n): Promise<INodeListSearchResult> {\n\treturn await getModelSearch(\n\t\t(model) => model.id.includes('vision') || model.id.includes('gpt-4o'),\n\t)(this, filter);\n}\n\nexport async function assistantSearch(\n\tthis: ILoadOptionsFunctions,\n\tfilter?: string,\n\tpaginationToken?: string,\n): Promise<INodeListSearchResult> {\n\tconst { data, has_more, last_id } = (await apiRequest.call(this, 'GET', '/assistants', {\n\t\theaders: {\n\t\t\t'OpenAI-Beta': 'assistants=v2',\n\t\t},\n\t\tqs: {\n\t\t\tlimit: 100,\n\t\t\tafter: paginationToken,\n\t\t},\n\t})) as {\n\t\tdata: Assistant[];\n\t\thas_more: boolean;\n\t\tlast_id: string;\n\t\tfirst_id: string;\n\t};\n\n\tif (has_more) {\n\t\tpaginationToken = last_id;\n\t} else {\n\t\tpaginationToken = undefined;\n\t}\n\n\tif (filter) {\n\t\tconst results: INodeListSearchItems[] = [];\n\n\t\tfor (const assistant of data || []) {\n\t\t\tif (assistant.name?.toLowerCase().includes(filter.toLowerCase())) {\n\t\t\t\tresults.push({\n\t\t\t\t\tname: assistant.name,\n\t\t\t\t\tvalue: assistant.id,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tresults,\n\t\t};\n\t} else {\n\t\treturn {\n\t\t\tresults: (data || []).map((assistant) => ({\n\t\t\t\tname: assistant.name ?? assistant.id,\n\t\t\t\tvalue: assistant.id,\n\t\t\t})),\n\t\t\tpaginationToken,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASA,uBAA2B;AAE3B,eAAsB,WAErB,QACiC;AACjC,QAAM,EAAE,KAAK,IAAI,MAAM,4BAAW,KAAK,MAAM,OAAO,QAAQ;AAE5D,MAAI,QAAQ;AACX,UAAM,UAAkC,CAAC;AAEzC,eAAW,QAAQ,QAAQ,CAAC,GAAG;AAC9B,UAAK,KAAK,UAAqB,YAAY,EAAE,SAAS,OAAO,YAAY,CAAC,GAAG;AAC5E,gBAAQ,KAAK;AAAA,UACZ,MAAM,KAAK;AAAA,UACX,OAAO,KAAK;AAAA,QACb,CAAC;AAAA,MACF;AAAA,IACD;AAEA,WAAO;AAAA,MACN;AAAA,IACD;AAAA,EACD,OAAO;AACN,WAAO;AAAA,MACN,UAAU,QAAQ,CAAC,GAAG,IAAI,CAAC,UAAuB;AAAA,QACjD,MAAM,KAAK;AAAA,QACX,OAAO,KAAK;AAAA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7B,MAAM,GAAG,WAAW,iBAAiB,KACpC,MAAM,GAAG,WAAW,MAAM,KAAK,MAAM,GAAG,SAAS,UAAU;AAAA,EAE/D,EAAE,MAAM,MAAM;AACf;AAEA,eAAsB,iBAErB,QACiC;AACjC,SAAO,MAAM;AAAA,IACZ,CAAC,UAAU,MAAM,GAAG,SAAS,QAAQ,KAAK,MAAM,GAAG,SAAS,QAAQ;AAAA,EACrE,EAAE,MAAM,MAAM;AACf;AAEA,eAAsB,gBAErB,QACA,iBACiC;AACjC,QAAM,EAAE,MAAM,UAAU,QAAQ,IAAK,MAAM,4BAAW,KAAK,MAAM,OAAO,eAAe;AAAA,IACtF,SAAS;AAAA,MACR,eAAe;AAAA,IAChB;AAAA,IACA,IAAI;AAAA,MACH,OAAO;AAAA,MACP,OAAO;AAAA,IACR;AAAA,EACD,CAAC;AAOD,MAAI,UAAU;AACb,sBAAkB;AAAA,EACnB,OAAO;AACN,sBAAkB;AAAA,EACnB;AAEA,MAAI,QAAQ;AACX,UAAM,UAAkC,CAAC;AAEzC,eAAW,aAAa,QAAQ,CAAC,GAAG;AACnC,UAAI,UAAU,MAAM,YAAY,EAAE,SAAS,OAAO,YAAY,CAAC,GAAG;AACjE,gBAAQ,KAAK;AAAA,UACZ,MAAM,UAAU;AAAA,UAChB,OAAO,UAAU;AAAA,QAClB,CAAC;AAAA,MACF;AAAA,IACD;AAEA,WAAO;AAAA,MACN;AAAA,IACD;AAAA,EACD,OAAO;AACN,WAAO;AAAA,MACN,UAAU,QAAQ,CAAC,GAAG,IAAI,CAAC,eAAe;AAAA,QACzC,MAAM,UAAU,QAAQ,UAAU;AAAA,QAClC,OAAO,UAAU;AAAA,MAClB,EAAE;AAAA,MACF;AAAA,IACD;AAAA,EACD;AACD;","names":[]}
@@ -2,7 +2,7 @@
2
2
  {"name":"anthropicApi","displayName":"Anthropic","documentationUrl":"anthropic","properties":[{"displayName":"API Key","name":"apiKey","type":"string","typeOptions":{"password":true},"required":true,"default":""},{"displayName":"Base URL","name":"url","type":"string","default":"https://api.anthropic.com","description":"Override the default base URL for the API"}],"authenticate":{"type":"generic","properties":{"headers":{"x-api-key":"={{$credentials.apiKey}}"}}},"test":{"request":{"baseURL":"={{$credentials?.url}}","url":"/v1/messages","method":"POST","headers":{"anthropic-version":"2023-06-01"},"body":{"model":"claude-3-haiku-20240307","messages":[{"role":"user","content":"Hey"}],"max_tokens":1}}},"supportedNodes":["lmChatAnthropic"],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/llms/LMChatAnthropic/anthropic.svg"},
3
3
  {"name":"azureOpenAiApi","displayName":"Azure Open AI","documentationUrl":"azureopenai","properties":[{"displayName":"API Key","name":"apiKey","type":"string","typeOptions":{"password":true},"required":true,"default":""},{"displayName":"Resource Name","name":"resourceName","type":"string","required":true,"default":""},{"displayName":"API Version","name":"apiVersion","type":"string","required":true,"default":"2025-03-01-preview"},{"displayName":"Endpoint","name":"endpoint","type":"string","placeholder":"https://westeurope.api.cognitive.microsoft.com"}],"authenticate":{"type":"generic","properties":{"headers":{"api-key":"={{$credentials.apiKey}}"}}},"supportedNodes":["embeddingsAzureOpenAi","lmChatAzureOpenAi"],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/embeddings/EmbeddingsAzureOpenAi/azure.svg"},
4
4
  {"name":"azureEntraCognitiveServicesOAuth2Api","displayName":"Azure Entra ID (Azure Active Directory) API","extends":["oAuth2Api"],"documentationUrl":"azureEntraCognitiveServicesOAuth2Api","properties":[{"displayName":"Grant Type","name":"grantType","type":"hidden","default":"authorizationCode"},{"displayName":"Resource Name","name":"resourceName","type":"string","required":true,"default":""},{"displayName":"API Version","name":"apiVersion","type":"string","required":true,"default":"2025-03-01-preview"},{"displayName":"Endpoint","name":"endpoint","type":"string","placeholder":"https://westeurope.api.cognitive.microsoft.com"},{"displayName":"Tenant ID","name":"tenantId","type":"string","default":"common","description":"Enter your Azure Tenant ID (Directory ID) or keep \"common\" for multi-tenant apps. Using a specific Tenant ID is generally recommended and required for certain authentication flows.","placeholder":"e.g., xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx or common"},{"displayName":"Authorization URL","name":"authUrl","type":"hidden","default":"=https://login.microsoftonline.com/{{$self[\"tenantId\"]}}/oauth2/authorize"},{"displayName":"Access Token URL","name":"accessTokenUrl","type":"hidden","default":"=https://login.microsoftonline.com/{{$self[\"tenantId\"]}}/oauth2/token"},{"displayName":"Additional Body Properties","name":"additionalBodyProperties","type":"hidden","default":"{\"grant_type\": \"client_credentials\", \"resource\": \"https://cognitiveservices.azure.com/\"}"},{"displayName":"Authentication","name":"authentication","type":"hidden","default":"body"},{"displayName":"Custom Scopes","name":"customScopes","type":"boolean","default":false,"description":"Define custom scopes. You might need this if the default scopes are not sufficient or if you want to minimize permissions. Ensure you include \"openid\" and \"offline_access\"."},{"displayName":"Auth URI Query Parameters","name":"authQueryParameters","type":"hidden","default":"","description":"For some services additional query parameters have to be set which can be defined here","placeholder":""},{"displayName":"Enabled Scopes","name":"enabledScopes","type":"string","displayOptions":{"show":{"customScopes":[true]}},"default":"openid offline_access","placeholder":"openid offline_access","description":"Space-separated list of scopes to request."},{"displayName":"Scope","name":"scope","type":"hidden","default":"={{ $self.customScopes ? $self.enabledScopes : \"openid offline_access\"}}"}],"supportedNodes":["lmChatAzureOpenAi"],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/llms/LmChatAzureOpenAi/azure.svg"},
5
- {"name":"cohereApi","displayName":"CohereApi","documentationUrl":"cohere","properties":[{"displayName":"API Key","name":"apiKey","type":"string","typeOptions":{"password":true},"required":true,"default":""}],"authenticate":{"type":"generic","properties":{"headers":{"Authorization":"=Bearer {{$credentials.apiKey}}"}}},"test":{"request":{"baseURL":"https://api.cohere.ai","url":"/v1/models?page_size=1"}},"supportedNodes":["embeddingsCohere","lmCohere"],"iconUrl":{"light":"icons/@n8n/n8n-nodes-langchain/dist/nodes/embeddings/EmbeddingsCohere/cohere.svg","dark":"icons/@n8n/n8n-nodes-langchain/dist/nodes/embeddings/EmbeddingsCohere/cohere.dark.svg"}},
5
+ {"name":"cohereApi","displayName":"CohereApi","documentationUrl":"cohere","properties":[{"displayName":"API Key","name":"apiKey","type":"string","typeOptions":{"password":true},"required":true,"default":""}],"authenticate":{"type":"generic","properties":{"headers":{"Authorization":"=Bearer {{$credentials.apiKey}}"}}},"test":{"request":{"baseURL":"https://api.cohere.ai","url":"/v1/models?page_size=1"}},"supportedNodes":["embeddingsCohere","lmCohere","rerankerCohere"],"iconUrl":{"light":"icons/@n8n/n8n-nodes-langchain/dist/nodes/embeddings/EmbeddingsCohere/cohere.svg","dark":"icons/@n8n/n8n-nodes-langchain/dist/nodes/embeddings/EmbeddingsCohere/cohere.dark.svg"}},
6
6
  {"name":"deepSeekApi","displayName":"DeepSeek","documentationUrl":"deepseek","properties":[{"displayName":"API Key","name":"apiKey","type":"string","typeOptions":{"password":true},"required":true,"default":""},{"displayName":"Base URL","name":"url","type":"hidden","default":"https://api.deepseek.com"}],"authenticate":{"type":"generic","properties":{"headers":{"Authorization":"=Bearer {{$credentials.apiKey}}"}}},"test":{"request":{"baseURL":"={{ $credentials.url }}","url":"/models"}},"supportedNodes":["lmChatDeepSeek"],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/llms/LmChatDeepSeek/deepseek.svg"},
7
7
  {"name":"googlePalmApi","displayName":"Google Gemini(PaLM) Api","documentationUrl":"google","properties":[{"displayName":"Host","name":"host","required":true,"type":"string","default":"https://generativelanguage.googleapis.com"},{"displayName":"API Key","name":"apiKey","type":"string","typeOptions":{"password":true},"required":true,"default":""}],"authenticate":{"type":"generic","properties":{"qs":{"key":"={{$credentials.apiKey}}"}}},"test":{"request":{"baseURL":"={{$credentials.host}}/v1beta/models"}},"supportedNodes":["embeddingsGoogleGemini","lmChatGoogleGemini"],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/embeddings/EmbeddingsGoogleGemini/google.svg"},
8
8
  {"name":"groqApi","displayName":"Groq","documentationUrl":"groq","properties":[{"displayName":"API Key","name":"apiKey","type":"string","typeOptions":{"password":true},"required":true,"default":""}],"authenticate":{"type":"generic","properties":{"headers":{"Authorization":"=Bearer {{$credentials.apiKey}}"}}},"test":{"request":{"baseURL":"https://api.groq.com/openai/v1","url":"/models"}},"supportedNodes":["lmChatGroq"],"iconUrl":"icons/@n8n/n8n-nodes-langchain/dist/nodes/llms/LmChatGroq/groq.svg"},