zilliztech / GPTCache

Semantic cache for LLMs. Fully integrated with LangChain and llama_index.
https://gptcache.readthedocs.io
MIT License
7.18k stars 502 forks source link

[Bug]: redis cache storage issues with connecting to remote cluster #486

Closed a9raag closed 1 year ago

a9raag commented 1 year ago

Current Behavior

The GPTCache server works fine while using the local Redis instance but, I am getting a connection error while trying to connect to Remote Redis Instance

  File "E:\dev\gptcache\gptcache_server\server.py", line 215, in <module>
    main()
  File "E:\dev\gptcache\gptcache_server\server.py", line 178, in main
    init_conf = init_similar_cache_from_config(config_dir=args.cache_config_file)
  File "E:\dev\gptcache\gptcache\adapter\api.py", line 221, in init_similar_cache_from_config
    data_manager = manager_factory(**storage_config)
  File "E:\dev\gptcache\gptcache\manager\factory.py", line 74, in manager_factory
    s = CacheBase(name=scalar, **scalar_params)
  File "E:\dev\gptcache\gptcache\manager\scalar_data\__init__.py", line 14, in CacheBase
    return scalar_manager.CacheBase.get(name, **kwargs)
  File "E:\dev\gptcache\gptcache\manager\scalar_data\manager.py", line 99, in get
    return RedisCacheStorage(
  File "E:\dev\gptcache\gptcache\manager\scalar_data\redis_storage.py", line 199, in __init__
    Migrator().run()
  File "D:\Dev\venv\lib\site-packages\redis_om\model\migrations\migrator.py", line 163, in run
    self.detect_migrations()
  File "D:\Dev\venv\lib\site-packages\redis_om\model\migrations\migrator.py", line 118, in detect_migrations
    conn.ft(cls.Meta.index_name).info()
  File "D:\Dev\venv\lib\site-packages\redis\commands\search\commands.py", line 370, in info
    res = self.execute_command(INFO_CMD, self.index_name)
  File "D:\Dev\venv\lib\site-packages\redis\client.py", line 1266, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "D:\Dev\venv\lib\site-packages\redis\connection.py", line 1461, in get_connection
    connection.connect()
  File "D:\Dev\venv\lib\site-packages\redis\connection.py", line 713, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 10061 connecting to localhost:6379. No connection could be made because the target machine actively refused it.

Expected Behavior

GPTCache server should start without errors

Steps To Reproduce


Step 1: Update the cache_config_file and set 
storage_config:
    data_dir:
        gptcache_data
    manager:
        redis,faiss
    scalar_params:
        # Set scalar storage related params here
        url: "URL_TO_REMOTE_INSTACE:PORT"

Step 2: Start GPT Cache Server 

Environment

Mac, Windows, Linux

Anything else?

No response

SimFG commented 1 year ago

@a9raag can you get me the error message?

a9raag commented 1 year ago

@SimFG added the error trace.

a9raag commented 1 year ago

@SimFG I know where it is coming from. Migrator.run() creates Indexes necessary for Redis Search. But during the creation, it picks up localhost connection from the pool instead of the cluster collection.

I have a solution: We can modify the connection to be used in the instance of RedisModel by updating the Meta class. While calling the get_models method provide the Redis connection as a parameter and this will be used to update the Meta class for all RedisModels

SimFG commented 1 year ago

@a9raag Thank your pull request!!!