sujitb commited on
Commit
ed6e9e8
1 Parent(s): 6c204a5
Files changed (1) hide show
  1. app.py +5 -4
app.py CHANGED
@@ -11,23 +11,24 @@ bi_encoder.max_seq_length = 256 # Truncate long documents to 256 tokens
11
  # Store the index as a variable
12
  INDEX_NAME = 'cl-search-idx'
13
  NAMESPACE = 'webpages'
14
-
 
15
  index = pc.Index(name=INDEX_NAME)
16
 
17
- def query_from_pinecone(index, question_embedding, top_k=3):
18
  # get embedding from THE SAME embedder as the documents
19
 
20
  return index.query(
21
  vector=question_embedding,
22
  top_k=top_k,
23
- namespace=NAMESPACE,
24
  include_metadata=True # gets the metadata (dates, text, etc)
25
  ).get('matches')
26
 
27
 
28
  QUESTION=st.text_area('Ask a question -e.g How to prepare for Verbal section for CAT?') ##' How to prepare for Verbal section ?'
29
  question_embedding = bi_encoder.encode(QUESTION, convert_to_tensor=True)
30
- resp= query_from_pinecone(question_embedding.tolist(), 3)
31
  docresult= resp[0]['metadata']['text']
32
  #+ '\n*************\n'+ resp[1]['metadata']['text'] + '\n*************\n'+ resp[2]['metadata']['text']
33
 
 
11
  # Store the index as a variable
12
  INDEX_NAME = 'cl-search-idx'
13
  NAMESPACE = 'webpages'
14
+ pc_api_key= '3f916d01-2a69-457d-85eb-966c5d1849a8' #AWS
15
+ pc = Pinecone(api_key=pc_api_key)
16
  index = pc.Index(name=INDEX_NAME)
17
 
18
+ def query_from_pinecone(index,namespace, question_embedding, top_k=3):
19
  # get embedding from THE SAME embedder as the documents
20
 
21
  return index.query(
22
  vector=question_embedding,
23
  top_k=top_k,
24
+ namespace=namespace,
25
  include_metadata=True # gets the metadata (dates, text, etc)
26
  ).get('matches')
27
 
28
 
29
  QUESTION=st.text_area('Ask a question -e.g How to prepare for Verbal section for CAT?') ##' How to prepare for Verbal section ?'
30
  question_embedding = bi_encoder.encode(QUESTION, convert_to_tensor=True)
31
+ resp= query_from_pinecone(index,NAMESPACE, question_embedding.tolist(), 3)
32
  docresult= resp[0]['metadata']['text']
33
  #+ '\n*************\n'+ resp[1]['metadata']['text'] + '\n*************\n'+ resp[2]['metadata']['text']
34