Spaces:
Running
Running
updated index
Browse files- app.py +12 -3
- new_mbzuai-policies.json +0 -0
- requirements.txt +1 -0
app.py
CHANGED
@@ -15,6 +15,8 @@ from pinecone_text.sparse import BM25Encoder
|
|
15 |
from langchain_huggingface import HuggingFaceEmbeddings
|
16 |
from langchain_community.retrievers import PineconeHybridSearchRetriever
|
17 |
from langchain_groq import ChatGroq
|
|
|
|
|
18 |
|
19 |
# Load environment variables
|
20 |
load_dotenv(".env")
|
@@ -53,8 +55,8 @@ def initialize_pinecone(index_name: str):
|
|
53 |
##################################################
|
54 |
|
55 |
# Initialize Pinecone index and BM25 encoder
|
56 |
-
pinecone_index = initialize_pinecone("mbzuai-policies")
|
57 |
-
bm25 = BM25Encoder().load("./
|
58 |
|
59 |
##################################################
|
60 |
##################################################
|
@@ -74,6 +76,13 @@ retriever = PineconeHybridSearchRetriever(
|
|
74 |
# Initialize LLM
|
75 |
llm = ChatGroq(model="llama-3.1-70b-versatile", temperature=0, max_tokens=1024, max_retries=2)
|
76 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
# Contextualization prompt and retriever
|
78 |
contextualize_q_system_prompt = """Given a chat history and the latest user question \
|
79 |
which might reference context in the chat history, formulate a standalone question \
|
@@ -87,7 +96,7 @@ contextualize_q_prompt = ChatPromptTemplate.from_messages(
|
|
87 |
("human", "{input}")
|
88 |
]
|
89 |
)
|
90 |
-
history_aware_retriever = create_history_aware_retriever(llm,
|
91 |
|
92 |
# QA system prompt and chain
|
93 |
qa_system_prompt = """You are a highly skilled information retrieval assistant. Use the following context to answer questions effectively. \
|
|
|
15 |
from langchain_huggingface import HuggingFaceEmbeddings
|
16 |
from langchain_community.retrievers import PineconeHybridSearchRetriever
|
17 |
from langchain_groq import ChatGroq
|
18 |
+
from langchain.retrievers import ContextualCompressionRetriever
|
19 |
+
from langchain.retrievers.document_compressors import FlashrankRerank
|
20 |
|
21 |
# Load environment variables
|
22 |
load_dotenv(".env")
|
|
|
55 |
##################################################
|
56 |
|
57 |
# Initialize Pinecone index and BM25 encoder
|
58 |
+
pinecone_index = initialize_pinecone("updated-mbzuai-policies")
|
59 |
+
bm25 = BM25Encoder().load("./new_mbzuai-policies.json")
|
60 |
|
61 |
##################################################
|
62 |
##################################################
|
|
|
76 |
# Initialize LLM
|
77 |
llm = ChatGroq(model="llama-3.1-70b-versatile", temperature=0, max_tokens=1024, max_retries=2)
|
78 |
|
79 |
+
|
80 |
+
# Initialize Reranker
|
81 |
+
compressor = FlashrankRerank()
|
82 |
+
compression_retriever = ContextualCompressionRetriever(
|
83 |
+
base_compressor=compressor, base_retriever=retriever
|
84 |
+
)
|
85 |
+
|
86 |
# Contextualization prompt and retriever
|
87 |
contextualize_q_system_prompt = """Given a chat history and the latest user question \
|
88 |
which might reference context in the chat history, formulate a standalone question \
|
|
|
96 |
("human", "{input}")
|
97 |
]
|
98 |
)
|
99 |
+
history_aware_retriever = create_history_aware_retriever(llm, compression_retriever, contextualize_q_prompt)
|
100 |
|
101 |
# QA system prompt and chain
|
102 |
qa_system_prompt = """You are a highly skilled information retrieval assistant. Use the following context to answer questions effectively. \
|
new_mbzuai-policies.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
requirements.txt
CHANGED
@@ -99,3 +99,4 @@ wget==3.2
|
|
99 |
wsproto==1.2.0
|
100 |
yarl==1.9.4
|
101 |
zipp==3.19.2
|
|
|
|
99 |
wsproto==1.2.0
|
100 |
yarl==1.9.4
|
101 |
zipp==3.19.2
|
102 |
+
flaskrank
|