Redis Vector Store - addition of similaritySearchVectorWithScore method and other updates

This commit is contained in:
vinodkiran
2023-10-22 11:52:06 +05:30
parent 931e14c082
commit 23c62bdc0b
4 changed files with 155 additions and 5 deletions
@@ -0,0 +1,25 @@
/*
* Escapes all '-' characters.
* Redis Search considers '-' as a negative operator, hence we need
* to escape it
*/
export const escapeSpecialChars = (str: string) => {
return str.replaceAll('-', '\\-')
}
export const escapeAllStrings = (obj: object) => {
Object.keys(obj).forEach((key: string) => {
// @ts-ignore
let item = obj[key]
if (typeof item === 'object') {
escapeAllStrings(item)
} else if (typeof item === 'string') {
// @ts-ignore
obj[key] = escapeSpecialChars(item)
}
})
}
export const unEscapeSpecialChars = (str: string) => {
return str.replaceAll('\\-', '-')
}