mtyrrell commited on
Commit
8279bee
·
1 Parent(s): e815cf3

cloud qdrant restore

Browse files
Files changed (1) hide show
  1. app.py +32 -32
app.py CHANGED
@@ -46,48 +46,48 @@ scheduler = CommitScheduler(
46
  # We need to create the local vectorstore collection once using load_chunks
47
  # vectorestore colection are stored on persistent storage so this needs to be run only once
48
  # hence, comment out line below when creating for first time
49
- vectorstores = load_new_chunks()
50
  # once the vectore embeddings are created we will use qdrant client to access these
51
- vectorstores = get_local_qdrant()
52
 
53
  # Configure cloud Qdrant client #TESTING
54
- # def get_cloud_qdrant():
55
- # from langchain_community.embeddings import HuggingFaceEmbeddings
56
- # from langchain_community.vectorstores import Qdrant
57
- # from torch import cuda
58
 
59
- # # Get config and setup embeddings like in process_chunks.py
60
- # model_config = getconfig("model_params.cfg")
61
- # device = 'cuda' if cuda.is_available() else 'cpu'
62
 
63
- # embeddings = HuggingFaceEmbeddings(
64
- # model_kwargs = {'device': device},
65
- # encode_kwargs = {'normalize_embeddings': True},
66
- # model_name=model_config.get('retriever','MODEL')
67
- # )
68
 
69
- # # Get Qdrant API key from environment variable
70
- # qdrant_api_key = os.getenv("QDRANT")
71
- # if not qdrant_api_key:
72
- # raise ValueError("QDRANT API key not found in environment variables")
73
 
74
- # # Create the Qdrant client
75
- # client = QdrantClient(
76
- # url="https://ff3f0448-0a00-470e-9956-49efa3071db3.europe-west3-0.gcp.cloud.qdrant.io:6333",
77
- # api_key=qdrant_api_key,
78
- # )
79
 
80
- # # Wrap the client in Langchain's Qdrant vectorstore
81
- # vectorstore = Qdrant(
82
- # client=client,
83
- # collection_name="allreports",
84
- # embeddings=embeddings,
85
- # )
86
 
87
- # return {"allreports": vectorstore}
88
 
89
- # # Replace local Qdrant with cloud Qdrant
90
- # vectorstores = get_cloud_qdrant()
91
 
92
  #####---------------------CHAT-----------------------------------------------------
93
  def start_chat(query,history):
 
46
  # We need to create the local vectorstore collection once using load_chunks
47
  # vectorestore colection are stored on persistent storage so this needs to be run only once
48
  # hence, comment out line below when creating for first time
49
+ # vectorstores = load_new_chunks()
50
  # once the vectore embeddings are created we will use qdrant client to access these
51
+ # vectorstores = get_local_qdrant()
52
 
53
  # Configure cloud Qdrant client #TESTING
54
+ def get_cloud_qdrant():
55
+ from langchain_community.embeddings import HuggingFaceEmbeddings
56
+ from langchain_community.vectorstores import Qdrant
57
+ from torch import cuda
58
 
59
+ # Get config and setup embeddings like in process_chunks.py
60
+ model_config = getconfig("model_params.cfg")
61
+ device = 'cuda' if cuda.is_available() else 'cpu'
62
 
63
+ embeddings = HuggingFaceEmbeddings(
64
+ model_kwargs = {'device': device},
65
+ encode_kwargs = {'normalize_embeddings': True},
66
+ model_name=model_config.get('retriever','MODEL')
67
+ )
68
 
69
+ # Get Qdrant API key from environment variable
70
+ qdrant_api_key = os.getenv("QDRANT")
71
+ if not qdrant_api_key:
72
+ raise ValueError("QDRANT API key not found in environment variables")
73
 
74
+ # Create the Qdrant client
75
+ client = QdrantClient(
76
+ url="https://ff3f0448-0a00-470e-9956-49efa3071db3.europe-west3-0.gcp.cloud.qdrant.io:6333",
77
+ api_key=qdrant_api_key,
78
+ )
79
 
80
+ # Wrap the client in Langchain's Qdrant vectorstore
81
+ vectorstore = Qdrant(
82
+ client=client,
83
+ collection_name="allreports",
84
+ embeddings=embeddings,
85
+ )
86
 
87
+ return {"allreports": vectorstore}
88
 
89
+ # Replace local Qdrant with cloud Qdrant
90
+ vectorstores = get_cloud_qdrant()
91
 
92
  #####---------------------CHAT-----------------------------------------------------
93
  def start_chat(query,history):