mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 15:00:57 +03:00
fix(components/weaviate): fix metadata special chars upsertion failure (#4436)
* Enhancement: Add recursive key normalization for metadata in Weaviate vector store - Introduced `normalizeKeysRecursively` utility to standardize metadata keys. - Updated Weaviate vector store to apply normalization on document metadata before processing. * format(compnonents/utils): format for ci * Update utils.ts --------- Co-authored-by: Henry Heng <henryheng@flowiseai.com>
This commit is contained in:
@@ -1216,6 +1216,35 @@ export const handleDocumentLoaderDocuments = async (loader: DocumentLoader, text
|
||||
return docs
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize special characters in key to be used in vector store
|
||||
* @param str - Key to normalize
|
||||
* @returns Normalized key
|
||||
*/
|
||||
export const normalizeSpecialChars = (str: string) => {
|
||||
return str.replace(/[^a-zA-Z0-9_]/g, '_')
|
||||
}
|
||||
|
||||
/**
|
||||
* recursively normalize object keys
|
||||
* @param data - Object to normalize
|
||||
* @returns Normalized object
|
||||
*/
|
||||
export const normalizeKeysRecursively = (data: any): any => {
|
||||
if (Array.isArray(data)) {
|
||||
return data.map(normalizeKeysRecursively)
|
||||
}
|
||||
|
||||
if (data !== null && typeof data === 'object') {
|
||||
return Object.entries(data).reduce((acc, [key, value]) => {
|
||||
const newKey = normalizeSpecialChars(key)
|
||||
acc[newKey] = normalizeKeysRecursively(value)
|
||||
return acc
|
||||
}, {} as Record<string, any>)
|
||||
}
|
||||
return data
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if OAuth2 token is expired and refresh if needed
|
||||
* @param {string} credentialId
|
||||
|
||||
Reference in New Issue
Block a user