feat: Add toggle for metadata

This commit is contained in:
Mutasem Aldmour 2024-12-11 13:24:51 +01:00
parent cdbfcc246d
commit 0462290cdc
No known key found for this signature in database
GPG key ID: 3DFA8122BB7FD6B8
2 changed files with 22 additions and 5 deletions

View file

@ -405,6 +405,11 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
const toolDescription = this.getNodeParameter('toolDescription', itemIndex) as string;
const toolName = this.getNodeParameter('toolName', itemIndex) as string;
const topK = this.getNodeParameter('topK', itemIndex, 4) as number;
const includeDocumentMetadata = this.getNodeParameter(
'includeDocumentMetadata',
itemIndex,
false,
) as boolean;
const vectorStoreTool = new DynamicTool({
name: toolName,
@ -426,11 +431,11 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
return documents
.map((document) => {
// Tools can only return a string or array of objects with type text
// todo return concatenated strings instead? Or just without metadata?
// return { type: 'text', text: document[0].pageContent };
// todo with metadata?
return { type: 'text', text: JSON.stringify(document[0]) };
if (includeDocumentMetadata) {
return { type: 'text', text: JSON.stringify(document[0]) };
}
return { type: 'text', text: document[0].pageContent };
})
.filter((document) => !!document);
},

View file

@ -400,6 +400,18 @@ export function convertNodeToAiTool<
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 = {
displayName: 'Description',
name: 'toolDescription',