Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -106,13 +106,13 @@ async def lifespan(app: FastAPI):
|
|
| 106 |
ml_models["prompt_template"] = ChatPromptTemplate.from_template("""
|
| 107 |
**Role**: You are an expert assistant in insurance, legal compliance, human resources, and contract management.
|
| 108 |
**Instructions**:
|
| 109 |
-
- If the query contains multiple questions, split them into sub-questions.
|
| 110 |
- Use ONLY the provided context to answer.
|
| 111 |
- Provide one concise, complete sentence per sub-question.
|
| 112 |
- List answers in the same order as the sub-questions, without repeating the query text.
|
| 113 |
- Do not add numbering or bullet points; separate answers with a single space.
|
| 114 |
- Avoid phrases like “the provided document states” or “according to the context.”
|
| 115 |
-
- Summarize relevant parts of the context without losing meaning
|
| 116 |
- 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.
|
| 117 |
- Keep answers professional, clear, and direct, avoiding unnecessary jargon.
|
| 118 |
**Tone & Style**:
|
|
@@ -229,14 +229,15 @@ async def run_hackrx(req: RunRequest):
|
|
| 229 |
# end_time2 = time.time() - start_time2
|
| 230 |
# print(f"vector done: {end_time2}")
|
| 231 |
# dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 8})
|
| 232 |
-
dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 10 ,"lambda_mult": 0.80} )
|
|
|
|
| 233 |
|
| 234 |
|
| 235 |
# Create retrievers using the pre-loaded models from our ml_models dictionary
|
| 236 |
keyword_retriever = BM25Retriever.from_documents(chunks)
|
| 237 |
-
keyword_retriever.k =
|
| 238 |
# dense_retriever = Chroma.from_documents(documents=chunks, embedding=ml_models["embedder"]).as_retriever()
|
| 239 |
-
ensemble_retriever = EnsembleRetriever(retrievers=[keyword_retriever, dense_retriever], weights=[0.
|
| 240 |
### to make it faster we are now using our built reranker thats why commenting the code below
|
| 241 |
# compression_retriever = ContextualCompressionRetriever(
|
| 242 |
# base_retriever=ensemble_retriever, base_compressor=ml_models["reranker_compressor"]
|
|
|
|
| 106 |
ml_models["prompt_template"] = ChatPromptTemplate.from_template("""
|
| 107 |
**Role**: You are an expert assistant in insurance, legal compliance, human resources, and contract management.
|
| 108 |
**Instructions**:
|
| 109 |
+
- If the query contains multiple questions, split them into perfect sub-questions.
|
| 110 |
- Use ONLY the provided context to answer.
|
| 111 |
- Provide one concise, complete sentence per sub-question.
|
| 112 |
- List answers in the same order as the sub-questions, without repeating the query text.
|
| 113 |
- Do not add numbering or bullet points; separate answers with a single space.
|
| 114 |
- Avoid phrases like “the provided document states” or “according to the context.”
|
| 115 |
+
- Summarize relevant parts of the context without losing meaning.
|
| 116 |
- 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.
|
| 117 |
- Keep answers professional, clear, and direct, avoiding unnecessary jargon.
|
| 118 |
**Tone & Style**:
|
|
|
|
| 229 |
# end_time2 = time.time() - start_time2
|
| 230 |
# print(f"vector done: {end_time2}")
|
| 231 |
# dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 8})
|
| 232 |
+
# dense_retriever = vectorstore.as_retriever(search_type="mmr",search_kwargs={"k": 10 ,"lambda_mult": 0.80} )
|
| 233 |
+
dense_retriever = vectorstore.as_retriever(search_type="similarity" ,search_kwargs={"k": 11} )
|
| 234 |
|
| 235 |
|
| 236 |
# Create retrievers using the pre-loaded models from our ml_models dictionary
|
| 237 |
keyword_retriever = BM25Retriever.from_documents(chunks)
|
| 238 |
+
keyword_retriever.k = 8
|
| 239 |
# dense_retriever = Chroma.from_documents(documents=chunks, embedding=ml_models["embedder"]).as_retriever()
|
| 240 |
+
ensemble_retriever = EnsembleRetriever(retrievers=[keyword_retriever, dense_retriever], weights=[0.3, 0.75],search_kwargs={"k": 9})
|
| 241 |
### to make it faster we are now using our built reranker thats why commenting the code below
|
| 242 |
# compression_retriever = ContextualCompressionRetriever(
|
| 243 |
# base_retriever=ensemble_retriever, base_compressor=ml_models["reranker_compressor"]
|