mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
Merge branch 'main' into chore/Upgrade-LC-version
# Conflicts: # packages/components/nodes/cache/RedisCache/RedisCache.ts # packages/components/nodes/cache/RedisCache/RedisEmbeddingsCache.ts # packages/components/nodes/chains/ConversationChain/ConversationChain.ts # packages/components/nodes/tools/RetrieverTool/RetrieverTool.ts # packages/components/nodes/vectorstores/Qdrant/Qdrant.ts # packages/components/nodes/vectorstores/Redis/Redis.ts # packages/components/nodes/vectorstores/Redis/RedisSearchBase.ts # packages/components/nodes/vectorstores/Redis/Redis_Existing.ts # packages/components/nodes/vectorstores/Redis/Redis_Upsert.ts # packages/components/src/agents.ts
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { flatten } from 'lodash'
|
||||
import { createClient, SearchOptions } from 'redis'
|
||||
import { flatten, isEqual } from 'lodash'
|
||||
import { createClient, SearchOptions, RedisClientOptions } from 'redis'
|
||||
import { Embeddings } from '@langchain/core/embeddings'
|
||||
import { RedisVectorStore, RedisVectorStoreConfig } from '@langchain/community/vectorstores/redis'
|
||||
import { Document } from '@langchain/core/documents'
|
||||
@@ -7,6 +7,27 @@ import { ICommonObject, INode, INodeData, INodeOutputsValue, INodeParams } from
|
||||
import { getBaseClasses, getCredentialData, getCredentialParam } from '../../../src/utils'
|
||||
import { escapeAllStrings, escapeSpecialChars, unEscapeSpecialChars } from './utils'
|
||||
|
||||
let redisClientSingleton: ReturnType<typeof createClient>
|
||||
let redisClientOption: RedisClientOptions
|
||||
|
||||
const getRedisClient = async (option: RedisClientOptions) => {
|
||||
if (!redisClientSingleton) {
|
||||
// if client doesn't exists
|
||||
redisClientSingleton = createClient(option)
|
||||
await redisClientSingleton.connect()
|
||||
redisClientOption = option
|
||||
return redisClientSingleton
|
||||
} else if (redisClientSingleton && !isEqual(option, redisClientOption)) {
|
||||
// if client exists but option changed
|
||||
redisClientSingleton.quit()
|
||||
redisClientSingleton = createClient(option)
|
||||
await redisClientSingleton.connect()
|
||||
redisClientOption = option
|
||||
return redisClientSingleton
|
||||
}
|
||||
return redisClientSingleton
|
||||
}
|
||||
|
||||
class Redis_VectorStores implements INode {
|
||||
label: string
|
||||
name: string
|
||||
@@ -149,8 +170,7 @@ class Redis_VectorStores implements INode {
|
||||
}
|
||||
|
||||
try {
|
||||
const redisClient = createClient({ url: redisUrl })
|
||||
await redisClient.connect()
|
||||
const redisClient = await getRedisClient({ url: redisUrl })
|
||||
|
||||
const storeConfig: RedisVectorStoreConfig = {
|
||||
redisClient: redisClient,
|
||||
@@ -210,8 +230,7 @@ class Redis_VectorStores implements INode {
|
||||
redisUrl = 'redis://' + username + ':' + password + '@' + host + ':' + portStr
|
||||
}
|
||||
|
||||
const redisClient = createClient({ url: redisUrl })
|
||||
await redisClient.connect()
|
||||
const redisClient = await getRedisClient({ url: redisUrl })
|
||||
|
||||
const storeConfig: RedisVectorStoreConfig = {
|
||||
redisClient: redisClient,
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
import { createClient, SearchOptions, RedisClientOptions } from 'redis'
|
||||
import { isEqual } from 'lodash'
|
||||
import { Embeddings } from '@langchain/core/embeddings'
|
||||
import { VectorStore } from '@langchain/core/vectorstores'
|
||||
import { Document } from '@langchain/core/documents'
|
||||
import { RedisVectorStore } from '@langchain/community/vectorstores/redis'
|
||||
import { escapeSpecialChars, unEscapeSpecialChars } from './utils'
|
||||
import {
|
||||
getBaseClasses,
|
||||
getCredentialData,
|
||||
@@ -7,12 +14,27 @@ import {
|
||||
INodeOutputsValue,
|
||||
INodeParams
|
||||
} from '../../../src'
|
||||
import { Embeddings } from '@langchain/core/embeddings'
|
||||
import { VectorStore } from '@langchain/core/vectorstores'
|
||||
import { Document } from '@langchain/core/documents'
|
||||
import { createClient, SearchOptions } from 'redis'
|
||||
import { RedisVectorStore } from '@langchain/community/vectorstores/redis'
|
||||
import { escapeSpecialChars, unEscapeSpecialChars } from './utils'
|
||||
|
||||
let redisClientSingleton: ReturnType<typeof createClient>
|
||||
let redisClientOption: RedisClientOptions
|
||||
|
||||
const getRedisClient = async (option: RedisClientOptions) => {
|
||||
if (!redisClientSingleton) {
|
||||
// if client doesn't exists
|
||||
redisClientSingleton = createClient(option)
|
||||
await redisClientSingleton.connect()
|
||||
redisClientOption = option
|
||||
return redisClientSingleton
|
||||
} else if (redisClientSingleton && !isEqual(option, redisClientOption)) {
|
||||
// if client exists but option changed
|
||||
redisClientSingleton.quit()
|
||||
redisClientSingleton = createClient(option)
|
||||
await redisClientSingleton.connect()
|
||||
redisClientOption = option
|
||||
return redisClientSingleton
|
||||
}
|
||||
return redisClientSingleton
|
||||
}
|
||||
|
||||
export abstract class RedisSearchBase {
|
||||
label: string
|
||||
@@ -140,8 +162,7 @@ export abstract class RedisSearchBase {
|
||||
redisUrl = 'redis://' + username + ':' + password + '@' + host + ':' + portStr
|
||||
}
|
||||
|
||||
this.redisClient = createClient({ url: redisUrl })
|
||||
await this.redisClient.connect()
|
||||
this.redisClient = await getRedisClient({ url: redisUrl })
|
||||
|
||||
const vectorStore = await this.constructVectorStore(embeddings, indexName, replaceIndex, docs)
|
||||
if (!contentKey || contentKey === '') contentKey = 'content'
|
||||
|
||||
Reference in New Issue
Block a user