langchain icon indicating copy to clipboard operation
langchain copied to clipboard

Unable save embeddings in Redis vectorstore

Open arunasujith opened this issue 2 years ago • 12 comments

I'm trying to save embeddings in Redis vectorstore and when I try to execute getting the following error. Any idea if this is a bug or if anything is wrong with my code? Any help is appreciated.

langchain version - both 0.0.123 and 0.0.124 Python 3.8.2

File "/Users/aruna/PycharmProjects/redis-test/database.py", line 16, in init_redis_database rds = Redis.from_documents(docs, embeddings, redis_url="redis://localhost:6379", index_name='link') File "/Users/aruna/PycharmProjects/redis-test/venv/lib/python3.8/site-packages/langchain/vectorstores/base.py", line 116, in from_documents return cls.from_texts(texts, embedding, metadatas=metadatas, **kwargs) File "/Users/aruna/PycharmProjects/redis-test/venv/lib/python3.8/site-packages/langchain/vectorstores/redis.py", line 224, in from_texts if not _check_redis_module_exist(client, "search"): File "/Users/aruna/PycharmProjects/redis-test/venv/lib/python3.8/site-packages/langchain/vectorstores/redis.py", line 23, in _check_redis_module_exist return module in [m["name"] for m in client.info().get("modules", {"name": ""})] File "/Users/aruna/PycharmProjects/redis-test/venv/lib/python3.8/site-packages/langchain/vectorstores/redis.py", line 23, in return module in [m["name"] for m in client.info().get("modules", {"name": ""})] TypeError: string indices must be integers

Sample code as follows.

REDIS_URL = 'redis://localhost:6379'

def init_redis_database(docs): embeddings = OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY) rds = Redis.from_documents(docs, embeddings, redis_url=REDIS_URL, index_name='link')

arunasujith avatar Mar 28 '23 20:03 arunasujith

Update on this, I debugged the client.info().get("modules", {"name": ""}) in line langchain.vectorstores.redis.py file line 23 and I found there are no modules returned though I have 5 redis modules installed. So I edit the library source code as follows and was able to store the embeddings in redis db. Not sure exact reason why modules are not returned for the client instance.

def _check_redis_module_exist(client: RedisType, module: str) -> bool: return True

arunasujith avatar Mar 29 '23 01:03 arunasujith

Please confirm that you are using the Redis Stack,Below is the official documentation https://redis.io/docs/stack/about/

hx23840 avatar Mar 29 '23 01:03 hx23840

Will take a look at improving this error handling.

tylerhutcherson avatar Mar 29 '23 12:03 tylerhutcherson

Got same error

    loader = PyPDFLoader(fpath)
    pages = loader.load_and_split()
    text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000,chunk_overlap=20)
    docs = text_splitter.split_documents(pages)
    embeddings = OpenAIEmbeddings()
    rds = Redis.from_documents(docs, embeddings, redis_url="redis://localhost:6379", index_name='link')

chrischjh avatar Mar 29 '23 14:03 chrischjh

Got same error

    loader = PyPDFLoader(fpath)
    pages = loader.load_and_split()
    text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000,chunk_overlap=20)
    docs = text_splitter.split_documents(pages)
    embeddings = OpenAIEmbeddings()
    rds = Redis.from_documents(docs, embeddings, redis_url="redis://localhost:6379", index_name='link')

Have you resolved it?

smyja avatar Apr 02 '23 07:04 smyja

Got same error

    loader = PyPDFLoader(fpath)
    pages = loader.load_and_split()
    text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000,chunk_overlap=20)
    docs = text_splitter.split_documents(pages)
    embeddings = OpenAIEmbeddings()
    rds = Redis.from_documents(docs, embeddings, redis_url="redis://localhost:6379", index_name='link')

Have you resolved it?

No, I had to turn to PGVector which works well

chrischjh avatar Apr 02 '23 11:04 chrischjh

@arunasujith which redis-py version are you using?

DvirDukhan avatar Apr 02 '23 21:04 DvirDukhan

@DvirDukhan its redis==4.5.3 library version.

arunasujith avatar Apr 03 '23 02:04 arunasujith

I had this error because I had done brew install redis but brew install redis-stack was needed (otherwise, redis has no modules installed)

DanielCollins avatar Apr 03 '23 06:04 DanielCollins

I still having this error and I think I know why. I'm using Redis Cloud and, after create a redis stack database, the module name for search is "searchlight", but in langchain Redis.py searches for a module called "search".

Do I have to rebuild langchain, changing it, to make it work? Is there a way to make the code more robust?

mmoraisTRT avatar Apr 10 '23 22:04 mmoraisTRT

@mmoraisTRT can you share the full output of MODULES LIST command?

tylerhutcherson avatar Apr 10 '23 22:04 tylerhutcherson

@tylerhutcherson We are encountering a similar issue. Please find below the list of packages involved:

1) 1) "name"
   2) "searchlight"
   3) "ver"
   4) (integer) 20606
2) 1) "name"
   2) "ReJSON"
   3) "ver"
   4) (integer) 20406
3) 1) "name"
   2) "bf"
   3) "ver"
   4) (integer) 20405
4) 1) "name"
   2) "timeseries"
   3) "ver"
   4) (integer) 10809
5) 1) "name"
   2) "graph"
   3) "ver"
   4) (integer) 21009

Ps: We are utilizing the free subscription tier of Redis Cloud for our current operations:

image

bern4rdelli avatar Apr 27 '23 10:04 bern4rdelli

Hi, @arunasujith! I'm Dosu, and I'm helping the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

Based on my understanding, you encountered a "TypeError: string indices must be integers" error when trying to save embeddings in Redis vectorstore. You have debugged the code and made changes to the library source code to store the embeddings successfully. Other users have also reported similar errors and suggested checking the Redis Stack documentation and the Redis module list. The maintainers have acknowledged the issue and plan to improve error handling.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on the issue. Otherwise, feel free to close the issue yourself or it will be automatically closed in 7 days.

Thank you for your contribution and understanding!

dosubot[bot] avatar Sep 21 '23 16:09 dosubot[bot]

Hi, yes still have the same error :(

Soleitconsultant avatar Oct 19 '23 17:10 Soleitconsultant

@Spartee @baskaryan ~I believe we need to extend the module check for searchlight.~

Strike that. It's been added.

tylerhutcherson avatar Oct 19 '23 18:10 tylerhutcherson

I still having this error and I think I know why. I'm using Redis Cloud and, after create a redis stack database, the module name for search is "searchlight", but in langchain Redis.py searches for a module called "search".

Do I have to rebuild langchain, changing it, to make it work? Is there a way to make the code more robust?

Could you solve it? I'm getting same error

mindxblend avatar Mar 15 '24 05:03 mindxblend