singhankur01 commited on
Commit
6036aa5
·
verified ·
1 Parent(s): 32588a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -14
app.py CHANGED
@@ -99,21 +99,31 @@ async def lifespan(app: FastAPI):
99
  # model="gemini-1.5-pro",
100
  model="gemini-2.0-flash",
101
  api_key=GOOGLE_API_KEY,
102
- temperature=0.1,
103
- max_output_tokens=350
104
  )
105
  ml_models["prompt_template"] = ChatPromptTemplate.from_template("""
106
- **Role**: You are an expert assistant in insurance, legal compliance, human resources, contract management and Question Answering.
 
107
  **Instructions**:
108
- - If the query contains multiple questions, split them into perfect sub-questions.
109
- - Use ONLY the provided context to answer.
110
- - Provide one concise, complete sentence per sub-question.
111
- - List answers in the same order as the sub-questions, without repeating the query text.
112
- - Do not add numbering or bullet points; separate answers with a single space.
113
- - Avoid phrases like the provided document states” or “according to the context.
114
- - Summarize relevant parts of the context without losing meaning.
115
- - If the answer is not in the context for some subqueries, respond exactly with: " I do not know the answer of "subquery",Please ask query related to the Document only." for that subquery.
116
- - Keep answers professional, clear, and direct.
 
 
 
 
 
 
 
 
 
117
  ---
118
  **Context**:
119
  {context}
@@ -225,7 +235,7 @@ async def run_hackrx(req: RunRequest):
225
  # end_time2 = time.time() - start_time2
226
  # print(f"vector done: {end_time2}")
227
  # dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 8})
228
- dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 12 ,"lambda_mult": 0.7} )
229
  # dense_retriever = vectorstore.as_retriever(search_type="similarity" ,search_kwargs={"k": 11} )
230
 
231
 
@@ -233,7 +243,7 @@ async def run_hackrx(req: RunRequest):
233
  keyword_retriever = BM25Retriever.from_documents(chunks)
234
  keyword_retriever.k = 9
235
  # dense_retriever = Chroma.from_documents(documents=chunks, embedding=ml_models["embedder"]).as_retriever()
236
- ensemble_retriever = EnsembleRetriever(retrievers=[keyword_retriever, dense_retriever], weights=[0.35, 0.65],search_kwargs={"k": 10})
237
  ### to make it faster we are now using our built reranker thats why commenting the code below
238
  # compression_retriever = ContextualCompressionRetriever(
239
  # base_retriever=ensemble_retriever, base_compressor=ml_models["reranker_compressor"]
 
99
  # model="gemini-1.5-pro",
100
  model="gemini-2.0-flash",
101
  api_key=GOOGLE_API_KEY,
102
+ temperature=0.15,
103
+ max_output_tokens=300
104
  )
105
  ml_models["prompt_template"] = ChatPromptTemplate.from_template("""
106
+ **Role**: You are an expert assistant in insurance, legal compliance, human resources, contract management, and Question Answering.
107
+
108
  **Instructions**:
109
+ Step 1 - **Initial Draft**:
110
+ - If the user query contains multiple questions, split them into clear, well-formed sub-questions.
111
+ - Use ONLY the context provided below to generate answers.
112
+ - For each sub-question, provide a concise, complete, single-sentence response.
113
+ - Maintain the original order of the sub-questions in your responses.
114
+ - Do NOT repeat the query text, do NOT number the answers, and separate them with a single space.
115
+ - Do NOT use line breakers ("/n" or "\") in between the answers.
116
+ - Avoid boilerplate phrases like the document states” or “as per the context.
117
+ - If the answer to a sub-question is not in the context, say exactly: *I do not know the answer of "subquery",Please ask query related to the Document only.*
118
+
119
+ Step 2 - **Critique & Revise**:
120
+ - Review the initial answers to identify any sub-questions where relevant information from the context might have been missed.
121
+ - Revise those answers to better incorporate relevant text and improve completeness and accuracy.
122
+ - Ensure language is professional, clear, and aligned with domain tone.
123
+
124
+ Step 3 - **Final Output**:
125
+ - Output the revised, cohesive set of answers (one sentence per sub-question).
126
+
127
  ---
128
  **Context**:
129
  {context}
 
235
  # end_time2 = time.time() - start_time2
236
  # print(f"vector done: {end_time2}")
237
  # dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 8})
238
+ dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 13 ,"lambda_mult": 0.7} )
239
  # dense_retriever = vectorstore.as_retriever(search_type="similarity" ,search_kwargs={"k": 11} )
240
 
241
 
 
243
  keyword_retriever = BM25Retriever.from_documents(chunks)
244
  keyword_retriever.k = 9
245
  # dense_retriever = Chroma.from_documents(documents=chunks, embedding=ml_models["embedder"]).as_retriever()
246
+ ensemble_retriever = EnsembleRetriever(retrievers=[keyword_retriever, dense_retriever], weights=[0.35, 0.65],search_kwargs={"k": 12})
247
  ### to make it faster we are now using our built reranker thats why commenting the code below
248
  # compression_retriever = ContextualCompressionRetriever(
249
  # base_retriever=ensemble_retriever, base_compressor=ml_models["reranker_compressor"]