langchain
langchain copied to clipboard
Unable save embeddings in Redis vectorstore
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
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')
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
Please confirm that you are using the Redis Stack,Below is the official documentation https://redis.io/docs/stack/about/
Will take a look at improving this error handling.
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')
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?
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
@arunasujith which redis-py version are you using?
@DvirDukhan its redis==4.5.3 library version.
I had this error because I had done brew install redis but brew install redis-stack was needed (otherwise, redis has no modules installed)
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 can you share the full output of MODULES LIST command?
@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:

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!
Hi, yes still have the same error :(
@Spartee @baskaryan ~I believe we need to extend the module check for searchlight.~
Strike that. It's been added.
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