tykiww commited on
Commit
0cd2aee
1 Parent(s): 52eac76

Update services/qa_service/qna.py

Browse files
Files changed (1) hide show
  1. services/qa_service/qna.py +11 -4
services/qa_service/qna.py CHANGED
@@ -6,6 +6,7 @@ class QAService:
6
  def __init__(self, conf, pinecone, model_pipeline, question, goals):
7
  self.conf = conf
8
  self.pc = pinecone['connection']
 
9
  self.embedder = pinecone['embedder']
10
  self.model_pipeline = model_pipeline
11
  self.question = question
@@ -17,20 +18,26 @@ class QAService:
17
 
18
  def __exit__(self, exc_type, exc_val, exc_tb):
19
  print("Exiting Q&A Service")
 
 
 
 
 
 
 
20
 
21
  def retrieve_context(self):
22
  """Pass embedded question into pinecone"""
23
  embedded_query = self.embedder.get_text_embedding(self.question)
24
- pinecone_index = self.pc.Index(conf['embeddings']['index_name'])
25
 
26
- result = pinecone_index.query(
27
  vector=embedded_query,
28
  top_k=1,
29
  include_values=False,
30
  include_metadata=True
31
  )
32
-
33
- output = json.loads(result['matches'][0]['metadata']['_node_content'])
34
 
35
  return output
36
 
 
6
  def __init__(self, conf, pinecone, model_pipeline, question, goals):
7
  self.conf = conf
8
  self.pc = pinecone['connection']
9
+ self.pc_index = self.pc.Index(self.conf['embeddings']['index_name'])
10
  self.embedder = pinecone['embedder']
11
  self.model_pipeline = model_pipeline
12
  self.question = question
 
18
 
19
  def __exit__(self, exc_type, exc_val, exc_tb):
20
  print("Exiting Q&A Service")
21
+
22
+ def parse_results(self, result):
23
+ level_1 = result['matches'][0]
24
+ level_2 = level_1['metadata']['_node_content']
25
+ parsed = json.loads(level_2)
26
+
27
+ return parsed
28
 
29
  def retrieve_context(self):
30
  """Pass embedded question into pinecone"""
31
  embedded_query = self.embedder.get_text_embedding(self.question)
 
32
 
33
+ result = self.pc_index.query(
34
  vector=embedded_query,
35
  top_k=1,
36
  include_values=False,
37
  include_metadata=True
38
  )
39
+
40
+ output = self.parse_results(output)
41
 
42
  return output
43