Skip to content

Commit

Permalink
Redis-dataprep: Make Redis connection consistent (opea-project#359)
Browse files Browse the repository at this point in the history
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 <[email protected]>
Co-authored-by: Sihan Chen <[email protected]>
Signed-off-by: BaoHuiling <[email protected]>
  • Loading branch information
2 people authored and BaoHuiling committed Aug 15, 2024
1 parent 2b35c01 commit 6875d48
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions comps/dataprep/redis/langchain/prepare_doc_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# from pyspark import SparkConf, SparkContext
import redis
from config import EMBED_MODEL, INDEX_NAME, KEY_INDEX_NAME, REDIS_HOST, REDIS_PORT, REDIS_URL
from config import EMBED_MODEL, INDEX_NAME, KEY_INDEX_NAME, REDIS_URL
from fastapi import Body, File, Form, HTTPException, UploadFile
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain_community.embeddings import HuggingFaceBgeEmbeddings, HuggingFaceHubEmbeddings
Expand All @@ -35,7 +35,7 @@

tei_embedding_endpoint = os.getenv("TEI_ENDPOINT")
upload_folder = "./uploaded_files/"
redis_pool = redis.ConnectionPool(host=REDIS_HOST, port=REDIS_PORT)
redis_pool = redis.ConnectionPool.from_url(REDIS_URL)


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

# partially delete files/folders
if delete_path.exists():
r = redis.Redis(host=REDIS_HOST, port=REDIS_PORT)
r = redis.Redis(connection_pool=redis_pool)
client = r.ft(KEY_INDEX_NAME)
client2 = r.ft(INDEX_NAME)
doc_id = "file:" + encode_filename(file_path)
Expand Down

0 comments on commit 6875d48

Please sign in to comment.