Skip to content

Commit cfaf5f0

Browse files
bjzhjingSpycsh
andauthored
Redis-dataprep: Make Redis connection consistent (#359)
There are both 'from langchain_community.vectorstores import Redis' and 'import redis' in prepare_doc_redis.py. Redis.from_texts_return_keys() is with REDIS_URL as connection, while redis.Redis() takes the combination of REDIS_HOST and REDIS_PORT as connection. When the former and the latter are not the same, it will fail to get data from vector database. Change to use REDIS_URL as the unified way. Signed-off-by: Cathy Zhang <cathy.zhang@intel.com> Co-authored-by: Sihan Chen <39623753+Spycsh@users.noreply.github.com>
1 parent 9b0edf2 commit cfaf5f0

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

comps/dataprep/redis/langchain/prepare_doc_redis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
# from pyspark import SparkConf, SparkContext
1212
import redis
13-
from config import EMBED_MODEL, INDEX_NAME, KEY_INDEX_NAME, REDIS_HOST, REDIS_PORT, REDIS_URL
13+
from config import EMBED_MODEL, INDEX_NAME, KEY_INDEX_NAME, REDIS_URL
1414
from fastapi import Body, File, Form, HTTPException, UploadFile
1515
from langchain.text_splitter import RecursiveCharacterTextSplitter
1616
from langchain_community.embeddings import HuggingFaceBgeEmbeddings, HuggingFaceHubEmbeddings
@@ -35,7 +35,7 @@
3535

3636
tei_embedding_endpoint = os.getenv("TEI_ENDPOINT")
3737
upload_folder = "./uploaded_files/"
38-
redis_pool = redis.ConnectionPool(host=REDIS_HOST, port=REDIS_PORT)
38+
redis_pool = redis.ConnectionPool.from_url(REDIS_URL)
3939

4040

4141
def check_index_existance(client):
@@ -318,7 +318,7 @@ async def delete_single_file(file_path: str = Body(..., embed=True)):
318318

319319
# partially delete files/folders
320320
if delete_path.exists():
321-
r = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)
321+
r = redis.Redis(connection_pool=redis_pool)
322322
client = r.ft(KEY_INDEX_NAME)
323323
client2 = r.ft(INDEX_NAME)
324324
doc_id = "file:" + encode_filename(file_path)

0 commit comments

Comments
 (0)