mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat: Add toggle for metadata
This commit is contained in:
parent
cdbfcc246d
commit
0462290cdc
|
@ -405,6 +405,11 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
|
||||||
const toolDescription = this.getNodeParameter('toolDescription', itemIndex) as string;
|
const toolDescription = this.getNodeParameter('toolDescription', itemIndex) as string;
|
||||||
const toolName = this.getNodeParameter('toolName', itemIndex) as string;
|
const toolName = this.getNodeParameter('toolName', itemIndex) as string;
|
||||||
const topK = this.getNodeParameter('topK', itemIndex, 4) as number;
|
const topK = this.getNodeParameter('topK', itemIndex, 4) as number;
|
||||||
|
const includeDocumentMetadata = this.getNodeParameter(
|
||||||
|
'includeDocumentMetadata',
|
||||||
|
itemIndex,
|
||||||
|
false,
|
||||||
|
) as boolean;
|
||||||
|
|
||||||
const vectorStoreTool = new DynamicTool({
|
const vectorStoreTool = new DynamicTool({
|
||||||
name: toolName,
|
name: toolName,
|
||||||
|
@ -426,11 +431,11 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
|
||||||
|
|
||||||
return documents
|
return documents
|
||||||
.map((document) => {
|
.map((document) => {
|
||||||
// Tools can only return a string or array of objects with type text
|
if (includeDocumentMetadata) {
|
||||||
// todo return concatenated strings instead? Or just without metadata?
|
return { type: 'text', text: JSON.stringify(document[0]) };
|
||||||
// return { type: 'text', text: document[0].pageContent };
|
}
|
||||||
// todo with metadata?
|
|
||||||
return { type: 'text', text: JSON.stringify(document[0]) };
|
return { type: 'text', text: document[0].pageContent };
|
||||||
})
|
})
|
||||||
.filter((document) => !!document);
|
.filter((document) => !!document);
|
||||||
},
|
},
|
||||||
|
|
|
@ -400,6 +400,18 @@ export function convertNodeToAiTool<
|
||||||
default: 'auto',
|
default: 'auto',
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (isVectorStore) {
|
||||||
|
const metadataProp: INodeProperties = {
|
||||||
|
displayName: 'Include metadata',
|
||||||
|
name: 'includeDocumentMetadata',
|
||||||
|
type: 'boolean',
|
||||||
|
default: false,
|
||||||
|
description: 'Whether or not to include document metadata',
|
||||||
|
};
|
||||||
|
|
||||||
|
item.description.properties.unshift(metadataProp);
|
||||||
|
}
|
||||||
|
|
||||||
const descProp: INodeProperties = {
|
const descProp: INodeProperties = {
|
||||||
displayName: 'Description',
|
displayName: 'Description',
|
||||||
name: 'toolDescription',
|
name: 'toolDescription',
|
||||||
|
|
Loading…
Reference in a new issue