add metadata option

This commit is contained in:
Mutasem Aldmour 2024-12-19 11:54:31 +01:00
parent f3ddd2f6db
commit d58a107ff9
No known key found for this signature in database
GPG key ID: 3DFA8122BB7FD6B8

View file

@ -215,6 +215,18 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
}, },
}, },
}, },
{
displayName: 'Include Metadata',
name: 'includeDocumentMetadata',
type: 'boolean',
default: true,
description: 'Whether or not to include document metadata',
displayOptions: {
show: {
mode: ['load', 'retrieve'],
},
},
},
// ID is always used for update operation // ID is always used for update operation
{ {
displayName: 'ID', displayName: 'ID',
@ -268,10 +280,16 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
filter, filter,
); );
const includeDocumentMetadata = this.getNodeParameter(
'includeDocumentMetadata',
itemIndex,
true,
) as boolean;
const serializedDocs = docs.map(([doc, score]) => { const serializedDocs = docs.map(([doc, score]) => {
const document = { const document = {
metadata: doc.metadata,
pageContent: doc.pageContent, pageContent: doc.pageContent,
...(includeDocumentMetadata ? { metadata: doc.metadata } : {}),
}; };
return { return {
@ -378,7 +396,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
throw new NodeOperationError( throw new NodeOperationError(
this.getNode(), this.getNode(),
'Only the "load" and "insert" operation modes are supported with execute', 'Only the "load", "update" and "insert" operation modes are supported with execute',
); );
} }