Spaces:
Sleeping
Sleeping
integrate reranker
#16
by RCaz - opened
- app.py +8 -1
- requirements.txt +1 -0
app.py
CHANGED
|
@@ -153,6 +153,14 @@ def predict(message, history, request: gr.Request):
|
|
| 153 |
# Retrieve relevant documents for the current message
|
| 154 |
relevant_docs = vectorstore.similarity_search(message,k=20) # retriever
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
# Build context from retrieved documents
|
| 157 |
context = "\nExtracted documents:\n" + "\n".join([
|
| 158 |
f"Content document {i+1}: {doc.page_content}\n\n---"
|
|
@@ -160,7 +168,6 @@ def predict(message, history, request: gr.Request):
|
|
| 160 |
])
|
| 161 |
|
| 162 |
|
| 163 |
-
|
| 164 |
# RAG tool
|
| 165 |
RAG_PROMPT_TEMPLATE="""You will be asked information related to Rémi Cazelles's specific projects, work and education.
|
| 166 |
Using the information contained in the context, provide a structured answer to the question.
|
|
|
|
| 153 |
# Retrieve relevant documents for the current message
|
| 154 |
relevant_docs = vectorstore.similarity_search(message,k=20) # retriever
|
| 155 |
|
| 156 |
+
# reranker
|
| 157 |
+
from ragatouille import RAGPretrainedModel
|
| 158 |
+
|
| 159 |
+
RERANKER = RAGPretrainedModel.from_pretrained("colbert-ir/colbertv2.0")
|
| 160 |
+
|
| 161 |
+
relevant_docs = RERANKER.rerank(message, relevant_docs, k=10)
|
| 162 |
+
relevant_docs = [doc["content"] for doc in relevant_docs]
|
| 163 |
+
|
| 164 |
# Build context from retrieved documents
|
| 165 |
context = "\nExtracted documents:\n" + "\n".join([
|
| 166 |
f"Content document {i+1}: {doc.page_content}\n\n---"
|
|
|
|
| 168 |
])
|
| 169 |
|
| 170 |
|
|
|
|
| 171 |
# RAG tool
|
| 172 |
RAG_PROMPT_TEMPLATE="""You will be asked information related to Rémi Cazelles's specific projects, work and education.
|
| 173 |
Using the information contained in the context, provide a structured answer to the question.
|
requirements.txt
CHANGED
|
@@ -11,6 +11,7 @@ langchain==0.3.8
|
|
| 11 |
langchain-community==0.3.8
|
| 12 |
langchain-openai==0.2.9
|
| 13 |
langchain-huggingface==0.1.0
|
|
|
|
| 14 |
|
| 15 |
gradio
|
| 16 |
|
|
|
|
| 11 |
langchain-community==0.3.8
|
| 12 |
langchain-openai==0.2.9
|
| 13 |
langchain-huggingface==0.1.0
|
| 14 |
+
RAGatouille
|
| 15 |
|
| 16 |
gradio
|
| 17 |
|