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:
Ahmed Rowaihi
2025-06-07 02:19:02 +03:00
committed by GitHub
parent 0c5f7ea003
commit 7dfa269502
2 changed files with 35 additions and 2 deletions
+29
View File
@@ -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